From e382894ef3b896d09db186f00884302fcbff5476 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Thu, 16 Apr 2015 10:26:25 -0700 Subject: [PATCH] [ReactNative] Navigator fix BackAndroid warning on iOS --- Libraries/CustomComponents/Navigator/Navigator.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Libraries/CustomComponents/Navigator/Navigator.js b/Libraries/CustomComponents/Navigator/Navigator.js index 371553d6a..f783c34ea 100644 --- a/Libraries/CustomComponents/Navigator/Navigator.js +++ b/Libraries/CustomComponents/Navigator/Navigator.js @@ -35,6 +35,7 @@ var NavigatorNavigationBar = require('NavigatorNavigationBar'); var NavigatorSceneConfigs = require('NavigatorSceneConfigs'); var NavigatorStaticContextContainer = require('NavigatorStaticContextContainer'); var PanResponder = require('PanResponder'); +var Platform = require('Platform'); var React = require('React'); var StaticContainer = require('StaticContainer.react'); var StyleSheet = require('StyleSheet'); @@ -398,22 +399,22 @@ var Navigator = React.createClass({ this._emitDidFocus(this.state.routeStack[this.state.presentedIndex]); if (this.parentNavigator) { this.parentNavigator.setHandler(this._handleRequest); - } else { + } else if (Platform.OS === 'android') { // There is no navigator in our props or context, so this is the // top-level navigator. We will handle back button presses here - BackAndroid.addEventListener('hardwareBackPress', this._handleBackPress); + BackAndroid.addEventListener('hardwareBackPress', this._handleAndroidBackPress); } }, componentWillUnmount: function() { if (this.parentNavigator) { this.parentNavigator.setHandler(null); - } else { - BackAndroid.removeEventListener('hardwareBackPress', this._handleBackPress); + } else if (Platform.OS === 'android') { + BackAndroid.removeEventListener('hardwareBackPress', this._handleAndroidBackPress); } }, - _handleBackPress: function() { + _handleAndroidBackPress: function() { var didPop = this.pop(); if (!didPop) { BackAndroid.exitApp();