Skip to content

Commit

Permalink
Bug fix for facebook#6228.
Browse files Browse the repository at this point in the history
Test Plan:
Check work with the dialogs. The original issue occurs in case of calling the showDialog after activity state has been saved. The mIsInForeground flag accessed from two different threads as result module doesnt' work as expected.

Release Notes:
Fixed race-condition in DialogModule on android platform. We had an access to the mIsInForeground flag on two different threads.
  • Loading branch information
dryganets committed Dec 29, 2017
1 parent fa574c6 commit adaf040
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;

Expand Down Expand Up @@ -95,6 +96,7 @@ public FragmentManagerHelper(android.app.FragmentManager fragmentManager) {
}

public void showPendingAlert() {
UiThreadUtil.assertOnUiThread();
if (mFragmentToShow == null) {
return;
}
Expand Down Expand Up @@ -123,6 +125,8 @@ private void dismissExisting() {
}

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

dismissExisting();

AlertFragmentListener actionListener =
Expand Down Expand Up @@ -218,8 +222,8 @@ public void onHostResume() {
public void showAlert(
ReadableMap options,
Callback errorCallback,
Callback actionCallback) {
FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
final Callback actionCallback) {
final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
if (fragmentManagerHelper == null) {
errorCallback.invoke("Tried to show an alert while not attached to an Activity");
return;
Expand Down Expand Up @@ -253,7 +257,13 @@ public void showAlert(
args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE));
}

fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback);
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
fragmentManagerHelper.showNewAlert(mIsInForeground, args, actionCallback);
}
});

}

/**
Expand Down

0 comments on commit adaf040

Please sign in to comment.