diff --git a/src/Reducer.js b/src/Reducer.js index 510d72897..0c63e4f29 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -22,6 +22,7 @@ import { import { assert } from './Util'; import { getInitialState } from './State'; +import { Platform } from 'react-native'; // WARN: it is not working correct. rewrite it. function checkPropertiesEqual(action, lastAction) { @@ -72,6 +73,11 @@ function inject(state, action, props, scenes) { case POP_ACTION2: case POP_ACTION: { assert(!state.tabs, 'pop() operation cannot be run on tab bar (tabs=true)'); + + if (Platform.OS === 'android') { + assert(state.index > 0, 'You are already in the root scene.'); + } + if (state.index === 0) { return state; } diff --git a/src/Router.js b/src/Router.js index 43ff28384..751d352c0 100644 --- a/src/Router.js +++ b/src/Router.js @@ -10,6 +10,7 @@ import React, { Component, PropTypes, } from 'react'; +import { BackAndroid } from 'react-native'; import NavigationExperimental from 'react-native-experimental-navigation'; import Actions from './Actions'; @@ -98,6 +99,15 @@ class Router extends Component { render() { if (!this.state.reducer) return null; + BackAndroid.addEventListener('hardwareBackPress', () => { + try { + Actions.pop(); + return true; + } catch (err) { + return false; + } + }); + return (