From 3d676ed6f3c948a5e9d62b6ec6f71e10f6c30289 Mon Sep 17 00:00:00 2001 From: Cameron Voell Date: Tue, 24 Mar 2020 21:31:39 -0700 Subject: [PATCH] BottomSheet listens to native bridge for closed modals on Android (#20860) * Bridge notifies BottomSheet of closed modals * Limit subscibeModalClosed to Android * Added unique variable name androidModalClosedSubscription * Added subscribeAndroidModalClosed to jest setup * Only remove subscription if it exists --- .../src/mobile/bottom-sheet/index.native.js | 12 ++++++++++++ test/native/setup.js | 1 + 2 files changed, 13 insertions(+) diff --git a/packages/components/src/mobile/bottom-sheet/index.native.js b/packages/components/src/mobile/bottom-sheet/index.native.js index 4df6fc064a088..826356958c9b7 100644 --- a/packages/components/src/mobile/bottom-sheet/index.native.js +++ b/packages/components/src/mobile/bottom-sheet/index.native.js @@ -13,6 +13,7 @@ import { } from 'react-native'; import Modal from 'react-native-modal'; import SafeArea from 'react-native-safe-area'; +import { subscribeAndroidModalClosed } from 'react-native-gutenberg-bridge'; /** * WordPress dependencies @@ -67,6 +68,14 @@ class BottomSheet extends Component { } componentDidMount() { + if ( Platform.OS === 'android' ) { + this.androidModalClosedSubscription = subscribeAndroidModalClosed( + () => { + this.props.onClose(); + } + ); + } + this.keyboardWillShowListener = Keyboard.addListener( 'keyboardWillShow', this.keyboardWillShow @@ -85,6 +94,9 @@ class BottomSheet extends Component { } componentWillUnmount() { + if ( this.androidModalClosedSubscription ) { + this.androidModalClosedSubscription.remove(); + } if ( this.safeAreaEventSubscription === null ) { return; } diff --git a/test/native/setup.js b/test/native/setup.js index 1a29cb054f924..fe55851be4827 100644 --- a/test/native/setup.js +++ b/test/native/setup.js @@ -13,6 +13,7 @@ jest.mock( 'react-native-gutenberg-bridge', () => { subscribeSetFocusOnTitle: jest.fn(), subscribeUpdateHtml: jest.fn(), subscribeMediaAppend: jest.fn(), + subscribeAndroidModalClosed: jest.fn(), editorDidMount: jest.fn(), editorDidAutosave: jest.fn(), subscribeMediaUpload: jest.fn(),