Skip to content

Commit

Permalink
Merge pull request #2011 from wordpress-mobile/issue/fix-android-cras…
Browse files Browse the repository at this point in the history
…h-modals-open-orientation-change

Fix crash and side effects on double rotation with modal
  • Loading branch information
cameronvoell committed Mar 25, 2020
2 parents 8942d36 + 92e1cf0 commit d72586b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class RNReactNativeGutenbergBridgeModule extends ReactContextBaseJavaModu
private static final String EVENT_NAME_FOCUS_TITLE = "setFocusOnTitle";
private static final String EVENT_NAME_MEDIA_UPLOAD = "mediaUpload";
private static final String EVENT_NAME_MEDIA_APPEND = "mediaAppend";
private static final String EVENT_NAME_TOGGLE_HTML_MODE = "toggleHTMLMode";
private static final String EVENT_NAME_NOTIFY_MODAL_CLOSED = "notifyModalClosed";

private static final String MAP_KEY_UPDATE_HTML = "html";
private static final String MAP_KEY_UPDATE_TITLE = "title";
Expand Down Expand Up @@ -285,6 +287,10 @@ private void setMediaFileUploadDataInJS(int state, int mediaId, String mediaUrl,
}

public void toggleEditorMode() {
emitToJS("toggleHTMLMode", null);
emitToJS(EVENT_NAME_TOGGLE_HTML_MODE, null);
}

public void notifyModalClosed() {
emitToJS(EVENT_NAME_NOTIFY_MODAL_CLOSED, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ public void invokeDefaultOnBackPressed() {
}
}

public void onDetach(Activity activity) {
mReactInstanceManager.onHostDestroy(activity);
mRnReactNativeGutenbergBridgePackage.getRNReactNativeGutenbergBridgeModule().notifyModalClosed();
}

public void onDestroy(Activity activity) {
if (mReactRootView != null) {
mReactRootView.unmountReactApplication();
Expand Down
5 changes: 5 additions & 0 deletions react-native-gutenberg-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';

const { RNReactNativeGutenbergBridge } = NativeModules;
const isIOS = Platform.OS === 'ios';
const isAndroid = Platform.OS === 'android';

const gutenbergBridgeEvents = new NativeEventEmitter( RNReactNativeGutenbergBridge );

Expand Down Expand Up @@ -70,6 +71,10 @@ export function subscribeMediaAppend( callback ) {
return gutenbergBridgeEvents.addListener( 'mediaAppend', callback );
}

export function subscribeAndroidModalClosed( callback ) {
return isAndroid ? gutenbergBridgeEvents.addListener( 'notifyModalClosed', callback ) : undefined;
}

/**
* Request media picker for the given media source.
*
Expand Down

0 comments on commit d72586b

Please sign in to comment.