[英]double header stack navigation react-native
I am using a StackNavigator in react native app. 我在React Native应用程序中使用StackNavigator。 The problem is that in my app, it creates two headers ...
问题是在我的应用程序中,它创建了两个标题...
I would like to keep the upper one to go back from the screen. 我想保留上一个,使其从屏幕上退回。 Is it possible without recreate the back button manually ?
是否可以不手动重新创建后退按钮?
Screen: 屏幕:
class CommandsList extends React.Component {
constructor(props){
super(props);
}
addCommand = () => {
this.props.navigation.navigate("CreateCommand");
}
render() {
return (
<SafeAreaView style={{flex:1}}>
<MyList itemsUrl="http://localhost:9000/commands"/>
<Button title="Ajouter" onPress={this.addCommand}></Button>
</SafeAreaView>
);
}
}
export default StackNavigator({
CommandsList : {
screen : CommandsList,
},
});
EDIT : App.js 编辑:App.js
const navigationOptions = ({ navigation }) => ({headerLeft: <Icon name {'chevron-left'} onPress={ () => { navigation.goBack() }} />})
const RootStack = StackNavigator(
{
CommandsList: {
screen: CommandsList,
},
CreateCommand: {
screen: CreateCommand,
},
ListFournisseurs: {
screen: ListFournisseurs,
},
ListAffaires: {
screen: ListAffaires,
}
},
{
initialRouteName: 'CommandsList',
headerMode:'none',
navigationOptions:{navigationOptions}
}
);
According to the docs, if you want to disable the header
of the StackNavigator
, you can apply the config at your StackNavigatorConfig
as headerMode: 'none'
. 根据文档,如果您要禁用
StackNavigator
的header
,则可以在您的StackNavigatorConfig
headerMode: 'none'
配置应用为headerMode: 'none'
。 It is back propagated from Child to Parent, if Parent is none then Child will also not be rendered. 它从子级 传播回 父级,如果父级不存在,则也不会渲染子级。
Therefore for a single header, in your case you should do 因此,对于单个标题,您应该这样做
export default StackNavigator({
CommandsList : {
screen : CommandsList,
},
}, {
headerMode: 'none'
});
For the back button in the Parent Stack, you can create a component as 对于“父堆栈”中的“后退”按钮,您可以将组件创建为
const navigationOptions = ({ navigation }) => ({
headerLeft: <Icon name={'arrow-left'} //<== Vector Icon Here
onPress={ () => { navigation.goBack() }} />
const RootStack = StackNavigator(
RouteConfigs,
//... StackNavigatorConfigs,
navigationOptions
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.