From 787df7306ae32acd8b072fd09f475af55f1fea5f Mon Sep 17 00:00:00 2001 From: Marko Savic Date: Mon, 18 Feb 2019 10:52:21 -0500 Subject: [PATCH] Fixed set state after component is unmounted --- .../components/mobile/bottom-sheet/index.native.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/editor/src/components/mobile/bottom-sheet/index.native.js b/packages/editor/src/components/mobile/bottom-sheet/index.native.js index 4f63b2e4500842..097dd3de9218aa 100644 --- a/packages/editor/src/components/mobile/bottom-sheet/index.native.js +++ b/packages/editor/src/components/mobile/bottom-sheet/index.native.js @@ -21,6 +21,7 @@ import PickerCell from './picker-cell'; class BottomSheet extends Component { constructor() { super( ...arguments ); + this._isMounted = false; this.onSafeAreaInsetsUpdate = this.onSafeAreaInsetsUpdate.bind( this ); this.state = { safeAreaBottomInset: 0, @@ -30,17 +31,21 @@ class BottomSheet extends Component { } componentDidMount() { + this._isMounted = true; SafeArea.addEventListener( 'safeAreaInsetsForRootViewDidChange', this.onSafeAreaInsetsUpdate ); } componentWillUnmount() { + this._isMounted = false; SafeArea.removeEventListener( 'safeAreaInsetsForRootViewDidChange', this.onSafeAreaInsetsUpdate ); } onSafeAreaInsetsUpdate( result ) { - const { safeAreaInsets } = result; - if ( this.state.safeAreaBottomInset !== safeAreaInsets.bottom ) { - this.setState( { safeAreaBottomInset: safeAreaInsets.bottom } ); + if ( this._isMounted ) { + const { safeAreaInsets } = result; + if ( this.state.safeAreaBottomInset !== safeAreaInsets.bottom ) { + this.setState( { safeAreaBottomInset: safeAreaInsets.bottom } ); + } } }