mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Create and show DatePickerDialogFragment in UI thread
Summary: Fix 'An Unexpected error occurred' in Messenger Kids caused by DatePickerDialog. Changelog: [Android][Fixed] - Create and show DatePickerDialogFragment in UI thread Differential Revision: D27882121 fbshipit-source-id: 2490a8178e5986222105bfbc16e7c0de471baa02
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e9016f8b73
commit
49af5e7385
+17
-11
@@ -101,7 +101,7 @@ public class DatePickerDialogModule extends NativeDatePickerAndroidSpec {
|
||||
* If the action is dismiss, year, month and date are undefined.
|
||||
*/
|
||||
@Override
|
||||
public void open(@Nullable final ReadableMap options, Promise promise) {
|
||||
public void open(@Nullable final ReadableMap options, final Promise promise) {
|
||||
Activity raw_activity = getCurrentActivity();
|
||||
if (raw_activity == null || !(raw_activity instanceof FragmentActivity)) {
|
||||
promise.reject(
|
||||
@@ -112,20 +112,26 @@ public class DatePickerDialogModule extends NativeDatePickerAndroidSpec {
|
||||
|
||||
FragmentActivity activity = (FragmentActivity) raw_activity;
|
||||
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
final FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
|
||||
if (oldFragment != null) {
|
||||
oldFragment.dismiss();
|
||||
}
|
||||
DatePickerDialogFragment fragment = new DatePickerDialogFragment();
|
||||
if (options != null) {
|
||||
final Bundle args = createFragmentArguments(options);
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
|
||||
fragment.setOnDismissListener(listener);
|
||||
fragment.setOnDateSetListener(listener);
|
||||
fragment.show(fragmentManager, FRAGMENT_TAG);
|
||||
activity.runOnUiThread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DatePickerDialogFragment fragment = new DatePickerDialogFragment();
|
||||
if (options != null) {
|
||||
final Bundle args = createFragmentArguments(options);
|
||||
fragment.setArguments(args);
|
||||
}
|
||||
final DatePickerDialogListener listener = new DatePickerDialogListener(promise);
|
||||
fragment.setOnDismissListener(listener);
|
||||
fragment.setOnDateSetListener(listener);
|
||||
fragment.show(fragmentManager, FRAGMENT_TAG);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Bundle createFragmentArguments(ReadableMap options) {
|
||||
|
||||
Reference in New Issue
Block a user