fix dialogmodule crashing with no fragment manager in onHostResume

Summary: This can happen now, we shouldn't crash. `showAlert` will crash instead if JS tries to call it.

Reviewed By: lexs

Differential Revision: D3450018

fbshipit-source-id: bbc062b357315f26ee98ed3b3a59db71dc5fc74a
This commit is contained in:
Felix Oghina 2016-06-17 07:52:57 -07:00 committed by Facebook Github Bot
parent ae6afcf3f6
commit bf79352e4f
2 changed files with 7 additions and 5 deletions

View File

@ -6,6 +6,7 @@ android_library(
deps = [
react_native_target('java/com/facebook/react/bridge:bridge'),
react_native_target('java/com/facebook/react/common:common'),
react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'),
react_native_dep('third-party/android/support/v4:lib-support-v4'),
react_native_dep('third-party/java/infer-annotations:infer-annotations'),
react_native_dep('third-party/java/jsr-305:jsr-305'),

View File

@ -20,6 +20,7 @@ import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
@ -198,11 +199,11 @@ public class DialogModule extends ReactContextBaseJavaModule implements Lifecycl
mIsInForeground = true;
// Check if a dialog has been created while the host was paused, so that we can show it now.
FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
Assertions.assertNotNull(
fragmentManagerHelper,
"Attached DialogModule to host with pending alert but no FragmentManager " +
"(not attached to an Activity).");
fragmentManagerHelper.showPendingAlert();
if (fragmentManagerHelper != null) {
fragmentManagerHelper.showPendingAlert();
} else {
FLog.w(DialogModule.class, "onHostResume called but no FragmentManager found");
}
}
@ReactMethod