Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: iOS Surface flex styles moved to outer layer #3887

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions example/src/Examples/ButtonExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,25 @@ const ButtonExample = () => {
Custom Font
</Button>
</View>

<View style={styles.row}>
<Button
mode="contained"
onPress={() => {}}
style={styles.flexGrow1Button}
>
flex-grow: 1
</Button>
</View>
<View style={styles.row}>
<Button
mode="contained"
onPress={() => {}}
style={styles.width100PercentButton}
>
width: 100%
</Button>
</View>
</List.Section>
<List.Section title="Compact">
<View style={styles.row}>
Expand Down Expand Up @@ -337,6 +356,14 @@ const styles = StyleSheet.create({
fontWeight: '800',
fontSize: 24,
},
flexGrow1Button: {
flexGrow: 1,
marginTop: 10,
},
width100PercentButton: {
width: '100%',
marginTop: 10,
},
});

export default ButtonExample;
70 changes: 31 additions & 39 deletions src/components/Surface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ const MD2Surface = forwardRef<View, Props>(
}
);

const outerLayerStyleProperties: (keyof ViewStyle)[] = [
'position',
'alignSelf',
'top',
'right',
'bottom',
'left',
'start',
'end',
'flex',
'flexShrink',
'flexGrow',
'width',
'height',
'transform',
'opacity',
];

const shadowColor = '#000';
const iOSShadowOutputRanges = [
{
Expand Down Expand Up @@ -148,29 +166,16 @@ const SurfaceIOS = forwardRef<
ref
) => {
const [outerLayerViewStyles, innerLayerViewStyles] = React.useMemo(() => {
const {
position,
alignSelf,
top,
left,
right,
bottom,
start,
end,
flex,
backgroundColor: backgroundColorStyle,
width,
height,
transform,
opacity,
...restStyle
} = (StyleSheet.flatten(style) || {}) as ViewStyle;

const [filteredStyles, marginStyles, borderRadiusStyles] = splitStyles(
restStyle,
(style) => style.startsWith('margin'),
(style) => style.startsWith('border') && style.endsWith('Radius')
);
const flattenedStyles = (StyleSheet.flatten(style) || {}) as ViewStyle;

const [filteredStyles, outerLayerStyles, borderRadiusStyles] =
splitStyles(
flattenedStyles,
(style) =>
outerLayerStyleProperties.includes(style) ||
style.startsWith('margin'),
(style) => style.startsWith('border') && style.endsWith('Radius')
);

if (
process.env.NODE_ENV !== 'production' &&
Expand All @@ -182,35 +187,22 @@ const SurfaceIOS = forwardRef<
);
}

const bgColor = backgroundColorStyle || backgroundColor;
const bgColor = flattenedStyles.backgroundColor || backgroundColor;

const isElevated = mode === 'elevated';

const outerLayerViewStyles = {
...(isElevated && getStyleForShadowLayer(elevation, 0)),
...marginStyles,
...outerLayerStyles,
...borderRadiusStyles,
position,
alignSelf,
top,
right,
bottom,
left,
start,
end,
flex,
width,
height,
transform,
opacity,
backgroundColor: bgColor,
};

const innerLayerViewStyles = {
...(isElevated && getStyleForShadowLayer(elevation, 1)),
...filteredStyles,
...borderRadiusStyles,
flex: height ? 1 : undefined,
flex: flattenedStyles.height ? 1 : undefined,
backgroundColor: bgColor,
};

Expand Down
81 changes: 0 additions & 81 deletions src/components/__tests__/Appbar/__snapshots__/Appbar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,15 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "rgba(255, 251, 254, 1)",
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": 64,
"left": undefined,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": undefined,
}
}
testID="surface-outer-layer"
Expand Down Expand Up @@ -58,28 +46,15 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "rgb(238, 232, 244)",
"borderRadius": 28,
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": undefined,
"left": undefined,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": undefined,
}
}
testID="search-bar-container-outer-layer"
Expand Down Expand Up @@ -108,28 +83,17 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "transparent",
"borderRadius": 20,
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": 40,
"left": undefined,
"margin": 6,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": 40,
}
}
Expand Down Expand Up @@ -301,28 +265,17 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "transparent",
"borderRadius": 20,
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": 40,
"left": undefined,
"margin": 6,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": 40,
}
}
Expand Down Expand Up @@ -452,27 +405,15 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "rgba(255, 251, 254, 1)",
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": 64,
"left": undefined,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": undefined,
}
}
testID="surface-outer-layer"
Expand Down Expand Up @@ -505,28 +446,17 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "transparent",
"borderRadius": 20,
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": 40,
"left": undefined,
"margin": 6,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": 40,
}
}
Expand Down Expand Up @@ -746,28 +676,17 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "transparent",
"borderRadius": 20,
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": 40,
"left": undefined,
"margin": 6,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": 40,
}
}
Expand Down
13 changes: 0 additions & 13 deletions src/components/__tests__/Card/__snapshots__/Card.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@ exports[`Card renders an outlined card 1`] = `
collapsable={false}
style={
Object {
"alignSelf": undefined,
"backgroundColor": "rgba(255, 251, 254, 1)",
"borderRadius": 12,
"bottom": undefined,
"end": undefined,
"flex": undefined,
"height": undefined,
"left": undefined,
"opacity": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"start": undefined,
"top": undefined,
"transform": undefined,
"width": undefined,
}
}
testID="card-container-outer-layer"
Expand Down
Loading