我正在尝试在视图底部添加阴影,但是我不打算在Android上这样做。有了elevation它,阴影也在顶部。有没有办法像在iOS上那样呢?
这是我的代码:
export function makeElevation(elevation) {
const iosShadowElevation = {
shadowOpacity: 0.0015 * elevation + 0.18,
shadowRadius: 0.5 * elevation,
shadowOffset: {
height: 0.6 * elevation,
},
};
const androidShadowElevation = {
elevation,
};
return Platform.OS === 'ios' ? iosShadowElevation : androidShadowElevation;
Run Code Online (Sandbox Code Playgroud)
}
左:iOS(预期)
右:Android
android shadow android-styles react-native react-native-android
我试图将我的所有样式都放在一个外部文件中以使其更清晰,但我找不到解决方案。
例如,我有这样的事情:
const styles = theme => ({
appBar: {
zIndex: theme.zIndex.drawer + 1,
position: 'absolute',
marginLeft: drawerWidth,
width: '100%',
},
});
Run Code Online (Sandbox Code Playgroud)
在我的 App 组件末尾加上这个:
App.propTypes = {
classes: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired,
};
export default withStyles(styles, { withTheme: true })(App);
Run Code Online (Sandbox Code Playgroud)
但是如果我试图将我的样式放在我的组件之外并导入它,我将无法访问 theme.zIndex.drawer
我的外部样式文件如下所示:
const drawerWidth = 240;
export default {
appBar: {
zIndex: theme.zIndex.drawer + 1,
position: 'absolute',
marginLeft: drawerWidth,
width: '100%',
},
}
Run Code Online (Sandbox Code Playgroud)
我不太明白它是如何工作的,有人可以帮助我吗?