Skip to content

Commit

Permalink
use BackHandler instead of BackAndroid, fix expo#461
Browse files Browse the repository at this point in the history
Closes expo#462

fbshipit-source-id: 4243d1f
  • Loading branch information
sibelius authored and expbot committed May 11, 2017
1 parent 7ac641a commit cf30d3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ on the left or right of the title.

// ...
}

@connect()
class SignOutButton extends React.Component {
render() {
Expand Down Expand Up @@ -421,7 +421,7 @@ will be rendered in the left position of the `navigationBar`.
will be rendered in the title position of the `navigationBar`.
- `renderRight` - a function that should return a React component that
will be rendered in the right position of the `navigationBar`.
- `renderBackground` - a function that should return a React component that
- `renderBackground` - a function that should return a React component that
will be rendered in the background of the `navigationBar`.

## TabNavigation
Expand Down Expand Up @@ -734,12 +734,12 @@ export default screenTracking;

### Android back button handling

React Native includes a global `BackAndroid` module. Rather than using this module
directly, include the `AndroidBackButtonBehavior` component in routes where you'd
React Native includes a global `BackHandler` module. Rather than using this module
directly, include the `AndroidBackButtonBehavior` component in routes where you'd
like to control the back button. `AndroidBackButtonBehavior` accepts
`isFocused` and `onBackButtonPress`. If `isFocused` is true, the `onBackButtonPress`
will fire when the user presses the back button. You need to make sure that `onBackButtonPress`
returns a promise that wraps the function you want to be called. Eg.
`isFocused` and `onBackButtonPress`. If `isFocused` is true, the `onBackButtonPress`
will fire when the user presses the back button. You need to make sure that `onBackButtonPress`
returns a promise that wraps the function you want to be called. Eg.

```
<AndroidBackButtonBehavior isFocused={someboolean}
Expand Down
14 changes: 8 additions & 6 deletions src/ExNavigationBackButtonManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* @flow
*/

import { BackAndroid } from 'react-native';
import { BackAndroid, BackHandler } from 'react-native';

import ExNavigationActions from './ExNavigationActions';

import type { ExNavigationStore } from './ExNavigationStore';

const Handler = BackHandler ? BackHandler : BackAndroid;

/**
* Manages a global listener, as well as any custom listeners, on the
* Android hardware back button.
Expand Down Expand Up @@ -53,9 +55,9 @@ class ExNavigationBackButtonManager {

disable() {
this._listeners.forEach(listener =>
BackAndroid.removeEventListener('hardwareBackPress', listener)
Handler.removeEventListener('hardwareBackPress', listener)
);
BackAndroid.addEventListener(
Handler.addEventListener(
'hardwareBackPress',
this._disabledBackButtonPress
); // Don't let app be exited.
Expand All @@ -68,11 +70,11 @@ class ExNavigationBackButtonManager {
_setListeners(newListeners: Array<() => Promise<void>>) {
this.disable();
this._listeners = newListeners;
BackAndroid.removeEventListener(
Handler.removeEventListener(
'hardwareBackPress',
this._disabledBackButtonPress
);
BackAndroid.addEventListener(
Handler.addEventListener(
'hardwareBackPress',
this._listeners[this._listeners.length - 1]
);
Expand All @@ -84,7 +86,7 @@ class ExNavigationBackButtonManager {
}
const moreRoutes = await this._store.dispatch(ExNavigationActions.goBack());
if (moreRoutes === false) {
BackAndroid.exitApp();
Handler.exitApp();
}
};

Expand Down

0 comments on commit cf30d3b

Please sign in to comment.