Search code examples
androidreact-nativebackreact-native-router-flux

React native router flux - How to access back pressed from navigation bar (not hardware back button) in android?


First of all, I'm very new to react native. I have used react native router flux for navigation in my project.

Problem: I want to check if the user has pressed back from top bar(navigation bar). I know how to listen to hardware back button press.

But I cannot figure out how to listen if the user has pressed back from top bar.

I searched for almost everyday possible. But I'm not able to get the solution.

Any suggestions .


Solution

  • Register your scene as:

    <Scene 
             key="latest"
             title="LATEST"
             titleStyle={{flex:0}}
             component={Latest}
             onRight={()=>{}} 
             rightButtonImage={NOTIFICATION_ICON}
             onLeft={()=>{}}
             leftButtonImage={NAV_SEARCH_ICON}
    />
    

    and then in your componentDidMount() use setParams() as:

    componentDidMount() {
              this.props.navigation.setParams({
                   'onRight': this.showNotifications,
                   'onLeft': this.showSearch,
             })
      }
    

    and implement showSearch or showNotifications method.

    That's it .