react native在static中使用this方法

首先需要在componentDidMount(){}中动态的添加点击事件

属性给params

componentDidMount(){
    this.props.navigation.setParams({
        title:'Save,
        navigatePress:this.clickSave
    })
}
clickSave = () => {
    alert('点击headerRight中的保存');
    console.log(this.props.navigation);
}
接下来就可以通过params方法来获取点击事件了
static navigationOptions = ({ navigation}) => ({
        title: navigation.state.params.title,
        headerRight:(
            <Text onPress={() => navigation.state.params.navigatePress()}>
                保存
            </Text>
        )
});

猜你喜欢

转载自www.cnblogs.com/wowchky/p/9133802.html