Skip to content

Commit

Permalink
DialogModule crash fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dryganets committed Jun 20, 2018
1 parent 73c4df2 commit 932d92c
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.SoftAssertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
Expand Down Expand Up @@ -95,9 +96,12 @@ public FragmentManagerHelper(android.app.FragmentManager fragmentManager) {

public void showPendingAlert() {
UiThreadUtil.assertOnUiThread();
SoftAssertions.assertCondition(mIsInForeground, "showPendingAlert() called in background");
if (mFragmentToShow == null) {
return;
}

dismissExisting();
if (isUsingSupportLibrary()) {
((SupportAlertFragment) mFragmentToShow).show(mSupportFragmentManager, FRAGMENT_TAG);
} else {
Expand All @@ -107,6 +111,9 @@ public void showPendingAlert() {
}

private void dismissExisting() {
if (!mIsInForeground) {
return;
}
if (isUsingSupportLibrary()) {
SupportAlertFragment oldFragment =
(SupportAlertFragment) mSupportFragmentManager.findFragmentByTag(FRAGMENT_TAG);
Expand All @@ -122,7 +129,7 @@ private void dismissExisting() {
}
}

public void showNewAlert(boolean isInForeground, Bundle arguments, Callback actionCallback) {
public void showNewAlert(Bundle arguments, Callback actionCallback) {
UiThreadUtil.assertOnUiThread();

dismissExisting();
Expand All @@ -132,7 +139,7 @@ public void showNewAlert(boolean isInForeground, Bundle arguments, Callback acti

if (isUsingSupportLibrary()) {
SupportAlertFragment alertFragment = new SupportAlertFragment(actionListener, arguments);
if (isInForeground) {
if (mIsInForeground) {
if (arguments.containsKey(KEY_CANCELABLE)) {
alertFragment.setCancelable(arguments.getBoolean(KEY_CANCELABLE));
}
Expand All @@ -142,7 +149,7 @@ public void showNewAlert(boolean isInForeground, Bundle arguments, Callback acti
}
} else {
AlertFragment alertFragment = new AlertFragment(actionListener, arguments);
if (isInForeground) {
if (mIsInForeground) {
if (arguments.containsKey(KEY_CANCELABLE)) {
alertFragment.setCancelable(arguments.getBoolean(KEY_CANCELABLE));
}
Expand Down Expand Up @@ -258,7 +265,7 @@ public void showAlert(
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback);
fragmentManagerHelper.showNewAlert(args, actionCallback);
}
});

Expand Down

0 comments on commit 932d92c

Please sign in to comment.