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: Fix shadow consistency ios/android #140

Merged
merged 1 commit into from
Jul 22, 2019
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
fix: Fix shadow consistency ios/android
  • Loading branch information
amaury1093 committed Jul 22, 2019
commit 7afcea8c7ee70b1b7c66e401118467f007891035
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