Skip to content

Instantly share code, notes, and snippets.

@ruvaleev
Created November 25, 2021 14:38
Show Gist options
  • Save ruvaleev/2fffd08fe3ea2834d56dd68c91b96523 to your computer and use it in GitHub Desktop.
Save ruvaleev/2fffd08fe3ea2834d56dd68c91b96523 to your computer and use it in GitHub Desktop.
const generateBoxShadowStyle = (
xOffset,
yOffset,
shadowColorIos,
shadowOpacity,
shadowRadius,
elevation,
shadowColorAndroid,
) => {
if (Platform.OS === 'ios') {
// styles.boxShadow = {
return {
shadowColor: shadowColorIos,
shadowOffset: {width: xOffset, height: yOffset},
shadowOpacity,
shadowRadius,
};
} else if (Platform.OS === 'android') {
// styles.boxShadow = {
return {
elevation,
shadowColor: shadowColorAndroid,
};
} else {
return {
boxShadow: '0px 0px 4px 4px rgba(0, 0, 0, 0.2)',
}
}
};
// В компоненте теперь можно такое применять:
<View style={[generateBoxShadowStyle(-2, 4, 'black', 0.2, 3, 2, 'black'), styles.someStyle]}></View>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment