美文网首页
static navaigationOptions中调用this

static navaigationOptions中调用this

作者: 快感的感知 | 来源:发表于2020-06-16 15:31 被阅读0次

static navigationOptions = ({navigation}) => {
const {params} = navigation.state;
return {
headerRight: (
<TouchableOpacity onPress={() => {
if (navigation.state.params !== undefined) {
navigation.state.params.choseType();
}
}}>
<Image
source={require('../../static/img/more.png')}
style={{
resizeMode: 'contain',
width: 20,
height: 20,
marginRight: 12
}}/>
</TouchableOpacity>
),
};
};

componentWillMount() {
this.props.navigation.setParams({choseType:this.choseType})
}

choseType = () => {
cosole.log("被调用了")
}
第一次传过去的params是undefined,这里有个坑就是一定要判断navigation.state.params !== undefined。

相关文章

网友评论

      本文标题:static navaigationOptions中调用this

      本文链接:https://www.haomeiwen.com/subject/jmmgectx.html