[英]React native - Hide status bar only on specific screens
我正在使用標簽導航來上傳下面的圖片
const Photos = TabNavigator({
CAMERA: {
screen: TakeCamera,
navigationOptions: {
tabBarIcon: ({focused}) => (
<View style={{flexDirection: 'row'}}>
<Text style={{textAlign: 'center', color: focused? '#C7A985' : '#020202'}}>CAMERA</Text>
<Icon name="chevron-down" size={15} color= {focused? '#C7A985' : '#ffffff'}/>
</View>
)
},
},
ALBUMS: {
screen: Albums,
navigationOptions: {
tabBarIcon: ({focused}) => (
<View style={{flexDirection: 'row'}}>
<Text style={{textAlign: 'center', color: focused? '#C7A985' : '#020202'}}>ALBUMS</Text>
<Icon name="chevron-down" size={15} color= {focused? '#C7A985' : '#ffffff'}/>
</View>
)
},
},
{
tabBarOptions: {
upperCaseLabel: false,
showIcon: true,
showLabel: false,
style: {
backgroundColor: '#F7F1ED',
borderTopWidth: 1
}
},
//initialRouteName: 'Feed',
tabBarComponent: TabBarBottom,
tabBarPosition: 'bottom',
animationEnabled: false,
swipeEnabled: false,
});
export default class UploadPost extends Component {
static navigationOptions = ({ navigation }) => ({
header: null,
tabBarVisible: false
});
render() {
return (
<View style={{flex: 1}}>
<StatusBar hidden={true}/>
<Photos screenProps={{navigation: this.props.navigation}}/>
</View>
);
}
}
此處<Statusbar hidden={true}>
按預期隱藏“CAMERA”,“ALBUMS”屏幕中的狀態欄。 但它也隱藏了其他屏幕中的狀態欄。
我的問題是,如何僅在CAMERA,ALBUMS屏幕上隱藏狀態欄?
您可以使用文檔中提到的屏幕跟蹤中間件來獲取currentScreen
的活動routeName
function getActiveRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
// dive into nested navigators
if (route.routes) {
return getActiveRouteName(route);
}
return route.routeName;
}
如果routeName
與您不希望顯示StatusBar的所需屏幕匹配,則將其設置為true
否則為false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.