How to call Screen / Component class method from react-navigation Header

后端 未结 5 2058
死守一世寂寞
死守一世寂寞 2021-02-09 00:27

I need to call SearchScreen class method from a React Navigation Header.

The Navigator look like this:

  Search: {
    screen: SearchScreen,
    path: \'         


        
5条回答
  •  无人及你
    2021-02-09 01:02

    I've made it work by doing:

    // declare static navigationOptions in the Component
    static navigationOptions = {
      title: 'Title',
      header: ({ state }) => ({
        right: (
          
        ),
      }),
    }
    
    _handleFilterPress() {
      // do something
    }
    
    
    componentDidMount() {
      // set handler method with setParams
      this.props.navigation.setParams({ 
        handleFilterPress: this._handleFilterPress.bind(this) 
      });
    }

提交回复
热议问题