From 35e517562c829f439601f78f2ccfee04779def22 Mon Sep 17 00:00:00 2001 From: Linmic Date: Fri, 11 Nov 2016 09:40:09 -0800 Subject: [PATCH] =?UTF-8?q?Fixed=20the=20issue=20that=20=5FonTransitionEnd?= =?UTF-8?q?=20might=20try=20to=20setState=20at=20unmoun=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This is to fix the issue that if `Animated.parallel`'s callback - `_onTransitionEnd` being triggered twice in a really short period(say quickly double-click the Android's hardware back button), it might try to `setState` at unmounted stage, hence cause app crash. This will make sure `_onTransitionEnd` only fired after mounted. Closes https://github.com/facebook/react-native/pull/10878 Differential Revision: D4167266 Pulled By: ericvicenti fbshipit-source-id: 7361e0ea4e8481b2da3fa39f78cdc0461693631f --- .../NavigationTransitioner.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Libraries/NavigationExperimental/NavigationTransitioner.js b/Libraries/NavigationExperimental/NavigationTransitioner.js index f13eeb7286..2a6aa90ebb 100644 --- a/Libraries/NavigationExperimental/NavigationTransitioner.js +++ b/Libraries/NavigationExperimental/NavigationTransitioner.js @@ -60,6 +60,7 @@ class NavigationTransitioner extends React.Component { _onTransitionEnd: () => void; _prevTransitionProps: ?NavigationTransitionProps; _transitionProps: NavigationTransitionProps; + _isMounted: boolean; props: Props; state: State; @@ -94,6 +95,7 @@ class NavigationTransitioner extends React.Component { this._prevTransitionProps = null; this._transitionProps = buildTransitionProps(props, this.state); + this._isMounted = false; } componentWillMount(): void { @@ -101,6 +103,14 @@ class NavigationTransitioner extends React.Component { this._onTransitionEnd = this._onTransitionEnd.bind(this); } + componentDidMount(): void { + this._isMounted = true; + } + + componentWillUnmount(): void { + this._isMounted = false; + } + componentWillReceiveProps(nextProps: Props): void { const nextScenes = NavigationScenesReducer( this.state.scenes, @@ -211,6 +221,10 @@ class NavigationTransitioner extends React.Component { } _onTransitionEnd(): void { + if (!this._isMounted) { + return; + } + const prevTransitionProps = this._prevTransitionProps; this._prevTransitionProps = null;