Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash and side effects on double rotation with modal #2011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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