【发布时间】:2018-10-19 05:12:43
【问题描述】:
我的 React-Native 应用中有这个 ImageBackground 标签。
const{height,width} = Dimensions.get('window);
const navHeight = ExtraDimensions.get('SOFT_MENU_BAR_HEIGHT');
render(){
return(
<ImageBackground source={Images.bg} style={{width=width+48,height=height}}>
//content
</ImageBackground>
);
}
数字 48 是默认 Android 导航栏的高度(包含 BACK 按钮)。 navHeight是检测设备上导航栏的高度(参考这里:https://github.com/Sunhat/react-native-extra-dimensions-android)。
由于现在有没有导航栏的设备,我想在 ImageBackground 样式中设置条件样式,当有 navHeight 的值时采用 style={styles.bg1} 并在没有 navHeight 时采用 style={styles.bg2}价值。
我可以知道我应该在哪里以及如何实现样式吗?谢谢
我目前的错误做法是
<ImageBackground source={Images.bg} style={navHeight=0 ? styles.bg1 : styles.bg2}>
【问题讨论】:
标签: javascript android react-native