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: pass absolute styles to outer shadow layer for ios #3239

Merged
merged 1 commit into from
Jul 5, 2022
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
2 changes: 1 addition & 1 deletion src/components/Appbar/AppbarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const AppbarHeader = ({
height = isV3 ? modeAppbarHeight[mode] : DEFAULT_APPBAR_HEIGHT,
elevation = isV3 ? (elevated ? 2 : 0) : 4,
backgroundColor: customBackground,
zIndex = 0,
zIndex = isV3 && elevated ? 1 : 0,
...restStyle
}: ViewStyle = StyleSheet.flatten(style) || {};

Expand Down
17 changes: 12 additions & 5 deletions src/components/Surface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ const Surface = ({
return colors.elevation?.[`level${elevation}`];
})();

const sharedStyle = [{ backgroundColor }, style];

if (Platform.OS === 'web') {
return (
<Animated.View
Expand Down Expand Up @@ -169,6 +167,7 @@ const Surface = ({
) as ViewStyle;

const outerLayerStyles = { margin, padding, transform, borderRadius };
const sharedStyle = [{ backgroundColor }, style];

return (
<Animated.View
Expand Down Expand Up @@ -204,6 +203,12 @@ const Surface = ({

const shadowColor = '#000';

const { position, top, left, right, bottom, ...restStyle } =
(StyleSheet.flatten(style) || {}) as ViewStyle;

const absoluteStyles = { position, top, right, bottom, left };
const sharedStyle = [{ backgroundColor }, restStyle];

if (isAnimatedValue(elevation)) {
const inputRange = [0, 1, 2, 3, 4, 5];

Expand All @@ -230,7 +235,9 @@ const Surface = ({
};

return (
<Animated.View style={getStyleForAnimatedShadowLayer(0)}>
<Animated.View
style={[getStyleForAnimatedShadowLayer(0), absoluteStyles]}
>
<Animated.View style={getStyleForAnimatedShadowLayer(1)}>
<Animated.View {...props} style={sharedStyle}>
{children}
Expand All @@ -253,8 +260,8 @@ const Surface = ({
};

return (
<Animated.View style={getStyleForShadowLayer(0)}>
<Animated.View style={getStyleForShadowLayer(1)}>
<Animated.View style={[getStyleForShadowLayer(0), absoluteStyles]}>
<Animated.View style={[getStyleForShadowLayer(1)]}>
<Animated.View {...props} style={sharedStyle}>
{children}
</Animated.View>
Expand Down
35 changes: 35 additions & 0 deletions src/components/__tests__/Appbar/__snapshots__/Appbar.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down Expand Up @@ -45,13 +50,18 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 1,
"width": 0,
},
"shadowOpacity": 0.15,
"shadowRadius": 3,
"top": undefined,
}
}
>
Expand Down Expand Up @@ -84,13 +94,18 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down Expand Up @@ -214,13 +229,18 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down Expand Up @@ -328,13 +348,18 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down Expand Up @@ -368,13 +393,18 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down Expand Up @@ -597,13 +627,18 @@ exports[`Appbar passes additional props to AppbarBackAction, AppbarContent and A
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down
5 changes: 5 additions & 0 deletions src/components/__tests__/Card/__snapshots__/Card.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ exports[`Card renders an outlined card 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": undefined,
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 0,
"width": 0,
},
"shadowOpacity": 0,
"shadowRadius": 0,
"top": undefined,
}
}
>
Expand Down
18 changes: 15 additions & 3 deletions src/components/__tests__/__snapshots__/AnimatedFAB.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ exports[`renders animated fab 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": "absolute",
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 4,
"width": 0,
},
"shadowOpacity": 0.15,
"shadowRadius": 8,
"top": undefined,
}
}
>
Expand All @@ -36,7 +41,6 @@ exports[`renders animated fab 1`] = `
"backgroundColor": "transparent",
"borderRadius": 16,
"opacity": 1,
"position": "absolute",
"transform": Array [
Object {
"scale": 1,
Expand Down Expand Up @@ -265,13 +269,18 @@ exports[`renders animated fab with label on the left 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": "absolute",
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 4,
"width": 0,
},
"shadowOpacity": 0.15,
"shadowRadius": 8,
"top": undefined,
}
}
>
Expand All @@ -296,7 +305,6 @@ exports[`renders animated fab with label on the left 1`] = `
"backgroundColor": "transparent",
"borderRadius": 16,
"opacity": 1,
"position": "absolute",
"transform": Array [
Object {
"scale": 1,
Expand Down Expand Up @@ -528,13 +536,18 @@ exports[`renders animated fab with label on the right by default 1`] = `
collapsable={false}
style={
Object {
"bottom": undefined,
"left": undefined,
"position": "absolute",
"right": undefined,
"shadowColor": "#000",
"shadowOffset": Object {
"height": 4,
"width": 0,
},
"shadowOpacity": 0.15,
"shadowRadius": 8,
"top": undefined,
}
}
>
Expand All @@ -559,7 +572,6 @@ exports[`renders animated fab with label on the right by default 1`] = `
"backgroundColor": "transparent",
"borderRadius": 16,
"opacity": 1,
"position": "absolute",
"transform": Array [
Object {
"scale": 1,
Expand Down
Loading