【发布时间】:2020-01-03 15:25:46
【问题描述】:
我正在使用反应导航,并在右侧添加了一个按钮,用于使用默认导航选项从我的应用中退出,如下所示:
const otherApp = createStackNavigator({
Welcome : {
screen : WelcomeScreen
}
},
{
defaultNavigationOptions : ({navigation}) => ({
title : 'Welcome',
headerStyle: {
backgroundColor: '#29434e',
shadowColor: 'transparent',
elevation: 0
},
headerRight: (
<TouchableOpacity
style={{ backgroundColor: '#DDDDDD', padding: 5 }}
onPress={() => navigation.getParam('logout')}>
<Text
style={{
fontSize: 10,
}}>
Logout
</Text>
</TouchableOpacity>
),
})
});
我正在绑定要调用的方法,如下所示:
_Logout() {
this.props.signOut();
}
componentDidMount(){
this.props.navigation.setParams({ logout : this._Logout.bind(this) })
}
函数使用 redux 映射到 props
const mapDispatchToProps = (dispatch) => {
return {
Signout : ()=> dispatch(Signout())
}
}
但问题是当我按下按钮时,它没有调用该方法!
【问题讨论】:
标签: react-native react-redux react-navigation redux-thunk react-navigation-stack