From 73c5360470bee493e440d10b33a173aa42acf23b Mon Sep 17 00:00:00 2001 From: Geordie Date: Mon, 17 Oct 2016 10:26:20 -0700 Subject: [PATCH] NavigatorIOS: stopPropagation on navigationComplete event. Fixes #1241 Summary: With nested NavigatorIOS components: ``` ``` Navigating (via push etc.) in ComponentWithAnotherNavigatorIOSInSubtree's `navigator` caused an invariant error, making apps with this structure unusable. The reason was that the `navigationComplete` nativeEvent was being propagated to the outer Navigator due to React's automatic event bubbling, making the outer NavigatorIOS incorrectly think it was holding navigation stack state inconsistent with its native UINavigationController. Concretely, if the outer navigation stack is empty except for its initial state and something is pushed onto the inner stack, the outer NavigatorIOS suddenly complains that it has 2 items on its stack rather than 1. In reality, the outer Navigator still only has 1 item on its stack but the inner Navigator's event (containing information about the inner Navigator) incorrectly bubbles up and reaches the outer Navigator too. Closes https://github.com/facebook/react-native/pull/9828 Differential Revision: D4030167 Pulled By: ericvicenti fbshipit-source-id: d04de3d5b70b4862a78610c92701ebdab2b047dd --- Libraries/Components/Navigation/NavigatorIOS.ios.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Libraries/Components/Navigation/NavigatorIOS.ios.js b/Libraries/Components/Navigation/NavigatorIOS.ios.js index 0743dae67..5b8cad684 100644 --- a/Libraries/Components/Navigation/NavigatorIOS.ios.js +++ b/Libraries/Components/Navigation/NavigatorIOS.ios.js @@ -836,6 +836,9 @@ var NavigatorIOS = React.createClass({ }, _handleNavigationComplete: function(e: Event) { + // Don't propagate to other NavigatorIOS instances this is nested in: + e.stopPropagation(); + if (this._toFocusOnNavigationComplete) { this._getFocusEmitter().emit('focus', this._toFocusOnNavigationComplete); this._toFocusOnNavigationComplete = null;