Ale*_*oJS 5 react-native react-navigation
我需要从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}
/>
),
},
}
}
Run Code Online (Sandbox Code Playgroud)
我通过以下方式使其工作:
// 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)
});
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5586 次 |
| 最近记录: |