react-native Detect Hardware back button presses in Android


Example

BackAndroid.addEventListener('hardwareBackPress', function() {
    if (!this.onMainScreen()) {
        this.goBack();
        return true;
    }
    return false;
});

Note: this.onMainScreen() and this.goBack() are not built in functions, you also need to implement those. (https://github.com/immidi/react-native/commit/ed7e0fb31d842c63e8b8dc77ce795fac86e0f712)