diff --git a/README.md b/README.md index 9a7be1d..0e7c688 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ The **``** object used to initialize the navigation can take the follo - `customAction`: A special callback prop for your action buttons (this can be handy for triggering a side menu for example). The action gets triggered from your custom `leftCorner` or `rightCorner` components by calling `this.props.customAction("someActionName")` from them. It is then picked up like this: ``. - `hideNavigationBar`: Hide the navigation bar, always - `handleBackAndroid` (Boolean value): Apply a listener to the native back button on Android. On click, it will go to the previous route until it reach the first scene, then it will exit the app. +- `alertAndroidExit` (Boolean value): Alert the user if the Android back button is about to exit them from the app. - `statusBarProps`: Default StatusBar props, please refer to [StatusBar Docs](https://facebook.github.io/react-native/docs/statusbar.html#content). (Android) If `backgroundColor` isn't provided, it will take the same color as defined in `headerStyle`. - `sceneConfig`: Default animation to be used in case no `sceneConfig` is provided by the `toRoute` function. More details and possible parameters are in the `toRoute` documentation below. Defaults to `Navigator.SceneConfigs.FloatFromRight`. @@ -170,7 +171,7 @@ The **`this.props.toRoute()`** callback prop takes one parameter (a JavaScript o const { text, user, - } = this.props.data; + } = this.props.data; ``` The **`this.props.replaceRoute`** function takes in an object that can contain the same keys as `toRoute()`. The difference is that instead of adding a route to your stack, it replaces the route diff --git a/components/NavBarContainer.js b/components/NavBarContainer.js index 781ac3d..899f3a4 100644 --- a/components/NavBarContainer.js +++ b/components/NavBarContainer.js @@ -1,5 +1,6 @@ import React, { PropTypes } from 'react'; import { + Alert, BackAndroid, Platform, StyleSheet, @@ -17,6 +18,7 @@ const propTypes = { currentRoute: PropTypes.object.isRequired, customAction: PropTypes.func, handleBackAndroid: PropTypes.bool, + alertAndroidExit: PropTypes.bool, goToFirstRoute: PropTypes.func.isRequired, leftProps: PropTypes.object, navigator: PropTypes.object.isRequired, @@ -70,10 +72,19 @@ class NavBarContainer extends React.Component { BackAndroid.addEventListener('hardwareBackPress', () => { if (this.props.currentRoute.index > 0) { this.goBack(); - return true; + } else { + console.log('dsa') + console.log(this.props.alertAndroidExit) + console.log('dsa') + if (this.props.alertAndroidExit) { + Alert.alert('Leaving Current App', 'Are you sure you want to exit?', [ + { text: 'Cancel', style: 'cancel' }, + { text: 'Yes', onPress: () => BackAndroid.exitApp() } + ]) + } } - return false; + return true; }); } } diff --git a/index.js b/index.js index 42e73bc..282ff10 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,7 @@ const propTypes = { customAction: PropTypes.func, firstRoute: PropTypes.object.isRequired, handleBackAndroid: PropTypes.bool, + alertAndroidExit: PropTypes.bool, headerStyle: View.propTypes.style, hideNavigationBar: PropTypes.bool, noStatusBar: PropTypes.bool, @@ -380,6 +381,7 @@ class Router extends React.Component { titleProps={this.state.titleProps} customAction={this.customAction} handleBackAndroid={this.props.handleBackAndroid} + alertAndroidExit={this.props.alertAndroidExit} /> ); }