React-native-navigation: Overrride default back functionality in v2

Created on 8 Oct 2018  路  8Comments  路  Source: wix/react-native-navigation

Issue Description

Please provide an option to override default back functionality for a component. In my case I want to handle the back button to take current tab to home.


Environment

  • React Native Navigation version: v2
  • React Native version: 0.56
  • Platform(s) (iOS, Android, or both?): Android
馃彋 stale

Most helpful comment

Found a workaround. If you user React Native's BackHandler and return anything in the method bound to the "hardwareBackPress", React Native Navigation's behavior is overwritten.

All 8 comments

use the BackHandler of RN to handle backPress, and a navigation leftButton for the back button

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

@ogostus' solution is not enough, since we can not override the behavior of Android's hardware back button. A good example of this use case would be adding a confirmation before closing the app when user is pressing Android's back button in root view.

Any updates on this?

Found a workaround. If you user React Native's BackHandler and return anything in the method bound to the "hardwareBackPress", React Native Navigation's behavior is overwritten.

To clarify @Jazqa's answer. Just be sure you register an event that returns "true". Below would work fine in a root level screen.

    componentDidMount() {
        BackHandler.addEventListener('hardwareBackPress', this.handleHardwareBackPress);
    }

    componentWillUnmount() {
        BackHandler.removeEventListener('hardwareBackPress', this.handleHardwareBackPress);
    }

    handleHardwareBackPress = () => {
        return true;
    };

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

The issue has been closed for inactivity.

Was this page helpful?
0 / 5 - 0 ratings