gpt4 book ai didi

react-native - 如何从react-navigation标题中调用Screen/Component类的方法

转载 作者:行者123 更新时间:2023-12-04 18:27:10 24 4
gpt4 key购买 nike

我需要从React Navigation Header调用SearchScreen类方法。

导航器如下所示:

  Search: {
screen: SearchScreen,
path: 'search/:query',
navigationOptions: {
title: 'Search',
header: {
right: (
<MaterialCommunityIcons
name="filter"
onPress={() => {
console.log(this);
}}
style={{marginRight: 15, color: 'white'}}
size={24}
/>
),
},
}
}

最佳答案

我通过以下方式使其工作:

// declare static navigationOptions in the Component
static navigationOptions = {
title: 'Title',
header: ({ state }) => ({
right: (
<MaterialCommunityIcons
name="filter"
onPress={state.params.handleFilterPress}
style={{marginRight: 15, color: 'white'}}
size={24}
/>
),
}),
}

_handleFilterPress() {
// do something
}


componentDidMount() {
// set handler method with setParams
this.props.navigation.setParams({
handleFilterPress: this._handleFilterPress.bind(this)
});
}

关于react-native - 如何从react-navigation标题中调用Screen/Component类的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42377301/

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