【发布时间】:2020-01-02 22:59:00
【问题描述】:
我有一个带有 react-navigation v3 的 expo react 本机应用程序。
我正在将一个 signOut 函数从我的主应用程序传递到我的堆栈导航器之一的标题组件。我想传递这个标题一次,所以我不想将它添加到每个屏幕的 navigationOptions 中。
我无法访问 MainStackNavigator 中的道具并将函数向下传递给我的组件。
主应用
render () {
return (
<View style={styles.container}>
<AppNavigator screenProps={{ signOut: this.signOut }}/>
</View>
);
}
AppNavigator
export default createAppContainer(
createSwitchNavigator({
// You could add another route here for authentication.
// Read more at https://reactnavigation.org/docs/en/auth-flow.html
Main: MainStackNavigator,
},
{
initialRouteName: 'Main'
})
);
MainStackNavigator
export default createStackNavigator({
Home: {
screen: HomeScreen,
}
},{
initialRouteName: 'Home',
defaultNavigationOptions : {
headerTitle: <LogoTitle signOut={this.screenProps.signOut}/>,
headerMode: 'screen',
}
});
那么当我传入组件LogoTitle的时候,此时如何访问screenProps呢?
【问题讨论】:
-
你能看看这个吗:
headerTitle: (props) => <LogoTitle signOut={props.screenProps.signOut}/>
标签: react-native react-navigation expo