Skip to content

Commit

Permalink
fix: Fix shadow consistency ios/android (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Jul 22, 2019
1 parent 8050d31 commit 22604e4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion App/Screens/Details/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const styles = StyleSheet.create({
marginRight: theme.spacing.normal
},
container: {
...theme.elevatedLevel1('bottom'),
...theme.elevationShadowStyle(2, 'bottom'),
...theme.withPadding,
backgroundColor: 'white',
paddingBottom: theme.spacing.small,
Expand Down
8 changes: 6 additions & 2 deletions App/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ export function Banner ({
onPress={asTouchable ? onClick : undefined}
style={[
styles.container,
elevated === true ? theme.elevatedLevel1(shadowPosition) : null,
elevated === 'very' ? theme.elevatedLevel2(shadowPosition) : null
elevated === true
? theme.elevationShadowStyle(2, shadowPosition)
: null,
elevated === 'very'
? theme.elevationShadowStyle(10, shadowPosition)
: null
]}
underlayColor={asTouchable ? theme.primaryColor : undefined} // https://github.com/facebook/react-native/issues/11834
>
Expand Down
6 changes: 1 addition & 5 deletions App/components/BoxButton/BoxButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ const styles = StyleSheet.create({
borderColor: 'rgba(0, 0, 0, 0.1)',
borderRadius: scale(12),
borderWidth: 1,
elevation: 1,
marginBottom: theme.spacing.tiny,
paddingHorizontal: theme.spacing.small,
paddingVertical: scale(4),
shadowColor: 'black',
shadowOffset: { width: 0, height: 6 },
shadowOpacity: 0.1,
shadowRadius: 4
...theme.elevationShadowStyle(5)
},
boxButtonText: {
...theme.shitText,
Expand Down
35 changes: 19 additions & 16 deletions App/util/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,25 @@ const fixTextMargin = {
})
};

export const elevatedLevel1 = (position: ShadowPosition) => ({
elevation: 2,
shadowColor: 'black',
shadowOffset: { width: 0, height: position === 'top' ? -2 : 2 },
shadowOpacity: 0.2,
shadowRadius: 2
});

export const elevatedLevel2 = (position: ShadowPosition) => ({
elevation: 10,
shadowColor: 'black',
shadowOffset: { width: 0, height: position === 'top' ? -9 : 9 },
shadowOpacity: 0.4,
shadowRadius: 9,
zIndex: 100
});
/**
* Get consistent shadows between iOS and Android
* @see https://stenbeck.io/styling-shadows-in-react-native-ios-and-android/
*/
export function elevationShadowStyle (
elevation: number,
position: ShadowPosition = 'bottom'
) {
return {
elevation,
shadowColor: 'black',
shadowOffset: {
width: 0,
height: scale((position === 'bottom' ? 1 : -1) * 0.5 * elevation)
},
shadowOpacity: 0.3,
shadowRadius: scale(0.8 * elevation)
};
}

export const fullScreen = {
backgroundColor,
Expand Down

0 comments on commit 22604e4

Please sign in to comment.