Skip to content

Commit

Permalink
BottomSheet listens to native bridge for closed modals on Android (#2…
Browse files Browse the repository at this point in the history
…0860)

* 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
  • Loading branch information
cameronvoell committed Mar 25, 2020
1 parent f4a37d5 commit 3d676ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/components/src/mobile/bottom-sheet/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -85,6 +94,9 @@ class BottomSheet extends Component {
}

componentWillUnmount() {
if ( this.androidModalClosedSubscription ) {
this.androidModalClosedSubscription.remove();
}
if ( this.safeAreaEventSubscription === null ) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions test/native/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3d676ed

Please sign in to comment.