【发布时间】:2018-02-23 22:25:32
【问题描述】:
我正在开发一个反应原生应用程序,我希望能够从静态导航选项更改状态。我在关注这个:https://github.com/react-navigation/react-navigation/issues/1789
并已实施如下解决方案之一:
static navigationOptions = ({navigation}) => {
const { state } = navigation;
const {params = {}} = navigation.state;
navigation.params = {title: "", description: "", points: 0, image: {}, saveImage: true};
return {
headerRight: ( <Button transparent onPress={()=> params.create()}><Icon name="ios-add" style={{color: 'white'}}/></Button>)
};
};
componentDidMount() {
this.props.navigation.setParams({
create: this.openCreateModal
});
}
openCreateModal() {
this.setState({createModalVisible:true});
}
不幸的是,当我按下按钮调用 openCreateModal 函数时,我收到错误 this.setState is not a function。
如果有任何帮助,我将不胜感激。
【问题讨论】: