Move BackAndroid -> BackHandler, add Apple TV support for back nav

Summary:
Enable back navigation on Apple TV (with the remote's menu button) in code making use of BackAndroid.  The module is renamed to BackHandler.  BackAndroid is still exported to ReactNative for now, until external projects switch to using the new name for the module.  The navigation in https://github.com/react-community/react-navigation makes use of this module.

**Test plan**: Manual testing with an example app (https://github.com/dlowder-salesforce/react-nav-example).
Closes https://github.com/facebook/react-native/pull/12571

Differential Revision: D4665152

Pulled By: ericvicenti

fbshipit-source-id: 925400ce216379267e014457be6f5eedbe4453ec
This commit is contained in:
Douglas Lowder
2017-03-06 21:41:51 -08:00
committed by Facebook Github Bot
parent 9325496d46
commit b7e9374c64
10 changed files with 197 additions and 41 deletions

View File

@@ -25,7 +25,7 @@
const AppRegistry = require('AppRegistry');
const AsyncStorage = require('AsyncStorage');
const BackAndroid = require('BackAndroid');
const BackHandler = require('BackHandler');
const Dimensions = require('Dimensions');
const DrawerLayoutAndroid = require('DrawerLayoutAndroid');
const Linking = require('Linking');
@@ -73,7 +73,7 @@ class UIExplorerApp extends React.Component {
state: UIExplorerNavigationState;
componentWillMount() {
BackAndroid.addEventListener('hardwareBackPress', this._handleBackButtonPress);
BackHandler.addEventListener('hardwareBackPress', this._handleBackButtonPress);
}
componentDidMount() {

View File

@@ -24,6 +24,7 @@
'use strict';
const AsyncStorage = require('AsyncStorage');
const BackHandler = require('BackHandler');
const Linking = require('Linking');
const React = require('react');
const ReactNative = require('react-native');
@@ -68,6 +69,10 @@ class UIExplorerApp extends React.Component {
props: Props;
state: UIExplorerNavigationState;
componentWillMount() {
BackHandler.addEventListener('hardwareBackPress', this._handleBack);
}
componentDidMount() {
Linking.getInitialURL().then((url) => {
AsyncStorage.getItem(APP_STATE_KEY, (err, storedString) => {