Fixed the issue that _onTransitionEnd might try to setState at unmoun…
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
This commit is contained in:
Родитель
07b975248b
Коммит
35e517562c
|
@ -60,6 +60,7 @@ class NavigationTransitioner extends React.Component<any, Props, State> {
|
|||
_onTransitionEnd: () => void;
|
||||
_prevTransitionProps: ?NavigationTransitionProps;
|
||||
_transitionProps: NavigationTransitionProps;
|
||||
_isMounted: boolean;
|
||||
|
||||
props: Props;
|
||||
state: State;
|
||||
|
@ -94,6 +95,7 @@ class NavigationTransitioner extends React.Component<any, Props, State> {
|
|||
|
||||
this._prevTransitionProps = null;
|
||||
this._transitionProps = buildTransitionProps(props, this.state);
|
||||
this._isMounted = false;
|
||||
}
|
||||
|
||||
componentWillMount(): void {
|
||||
|
@ -101,6 +103,14 @@ class NavigationTransitioner extends React.Component<any, Props, State> {
|
|||
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<any, Props, State> {
|
|||
}
|
||||
|
||||
_onTransitionEnd(): void {
|
||||
if (!this._isMounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
const prevTransitionProps = this._prevTransitionProps;
|
||||
this._prevTransitionProps = null;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче