我在React-Native应用中使用了ImageBackground标签。
数字48是默认Android导航栏(包含“返回”按钮的导航栏)的高度。navHeight用于检测设备上导航栏的高度(参见此处:https://github.com/Sunhat/react-native-extra-dimensions-android)。
由于现在有些设备没有导航栏,我想在ImageBackground样式中进行条件化样式设置,当存在navHeight值时,采用
我当前错误的做法是:
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导航栏(包含“返回”按钮的导航栏)的高度。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}>