Method is not being invoked when i press the button

后端 未结 2 1978
忘掉有多难
忘掉有多难 2021-01-28 16:55

I am using react navigation and have added a button on the right to signout from my app using default navigation options as shown below :

const otherApp = create         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-28 17:35

    You can also use onFocus method of react-navigation to see whether the screen is on focus or not. If the screen is on focus then call the function.

    import { withNavigation } from "react-navigation";
     componentDidMount() {
        const { navigation } = this.props;
        this.focusListener = navigation.addListener("didFocus", () => {
          // The screen is focused
          // Call any action
        });
      }
    
      componentWillUnmount() {
        // Remove the event listener
        this.focusListener.remove();
      }
    
    export default withNavigation(Your Class Name);
    

    Method : 2

    import { NavigationEvents } from "react-navigation";
    
     onFocus = () => {
     //Write the code here which you want to do when the screen comes to focus.
      };
    
      render() {
        return (
             {
                this.onFocus();
              }}
            />
    )}
    

提交回复
热议问题