aharon vishinsky
aharon vishinsky

Reputation: 229

react-native-router-flux addListener doesn't work

I am using

react-native": "0.62.2", react-native-router-flux: "4.2.0-beta.1",

addListener doesn't work, and console.log never invoke

    componentDidMount() {
        this.props.navigation.addListener(ActionConst.RESET, () => {
            console.log('RESET');
        });
        this.props.navigation.addListener(ActionConst.FOCUS, () => {
            console.log('FOCUS');
        });
        this.props.navigation.addListener(ActionConst.PUSH, () => {
            console.log('PUSH');
        });
        this.props.navigation.addListener(ActionConst.POP_TO, () => {
            console.log('POP_TO');
        });
}

is there a way or documentation that I can look into?

Upvotes: 0

Views: 1095

Answers (1)

高鵬翔
高鵬翔

Reputation: 2057

You only have

  • willFocus - the screen will focus
  • didFocus - the screen focused (if there was a transition, the transition completed)
  • willBlur - the screen will be unfocused
  • didBlur - the screen unfocused (if there was a transition, the transition completed)

To add listener

componentDidMount(){
    const didBlurSubscription = this.props.navigation.addListener(
      'didBlur',() => {
         console.log('didBlur');
       }
    );
}

componentWillUnmount(){
    // Remove the listener when you are done
    didBlurSubscription.remove();
}

DOC (v4.2.x is based on React Navigation v4.x)

Upvotes: 1

Related Questions