gpt4 book ai didi

react-native - react native navigationOptions调用函数错误

转载 作者:行者123 更新时间:2023-12-04 04:16:12 25 4
gpt4 key购买 nike

navigationOptions 内部调用函数时出错.

static navigationOptions = {
tabBarIcon: ({ tintColor })=> (
<Icon name='ios-add-circle' style={{ color: tintColor}} />
),
tabBarOnPress: () => {
this.callingFun();
},
}

callingFun = ()=> {
console.log('tabBarOnPress:');
}

错误:

error image

最佳答案

您不能调用callingFun在静态对象属性中。我想你想要这个

static navigationOptions = ({navigation}) => {
return {
tabBarIcon: ({ tintColor }) => (
<Icon name='ios-add-circle' style={{ color: tintColor }} />
),
tabBarOnPress: () => {
navigation.getParam('callingFun')();
},
}
}

callingFun = () => {
console.log('tabBarOnPress:');
}

componentDidMount() {
const { navigation } = this.props
navigation.setParams({
callingFun: this.callingFun,
})
}

关于react-native - react native navigationOptions调用函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53166401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com