Avoid throwing exceptions from native modules when the host activity … (#201)
* Avoid throwing exceptions from native modules when the host activity is not a FragmentActivity * Delete ReactFeatureFlags.js~d9a25c2d04f32259d711e38195689d376d4a06a7
This commit is contained in:
Родитель
a65c7af600
Коммит
45554f8ec9
|
@ -7,7 +7,7 @@
|
|||
|
||||
package com.facebook.react.modules.datepicker;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.DatePickerDialog.OnDateSetListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
|
@ -112,14 +112,16 @@ public class DatePickerDialogModule extends ReactContextBaseJavaModule {
|
|||
*/
|
||||
@ReactMethod
|
||||
public void open(@Nullable final ReadableMap options, Promise promise) {
|
||||
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
|
||||
if (activity == null) {
|
||||
Activity raw_activity = getCurrentActivity();
|
||||
if (raw_activity == null || !(raw_activity instanceof FragmentActivity)) {
|
||||
promise.reject(
|
||||
ERROR_NO_ACTIVITY,
|
||||
"Tried to open a DatePicker dialog while not attached to an Activity");
|
||||
"Tried to open a DatePicker dialog while not attached to a FragmentActivity");
|
||||
return;
|
||||
}
|
||||
|
||||
FragmentActivity activity = (FragmentActivity) raw_activity;
|
||||
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
|
||||
if (oldFragment != null) {
|
||||
|
|
|
@ -239,7 +239,7 @@ public class DialogModule extends ReactContextBaseJavaModule implements Lifecycl
|
|||
*/
|
||||
private @Nullable FragmentManagerHelper getFragmentManagerHelper() {
|
||||
Activity activity = getCurrentActivity();
|
||||
if (activity == null) {
|
||||
if (activity == null || !(activity instanceof FragmentActivity)) {
|
||||
return null;
|
||||
}
|
||||
return new FragmentManagerHelper(((FragmentActivity) activity).getSupportFragmentManager());
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
package com.facebook.react.modules.timepicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.TimePickerDialog.OnTimeSetListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
|
@ -92,13 +93,16 @@ public class TimePickerDialogModule extends ReactContextBaseJavaModule {
|
|||
@ReactMethod
|
||||
public void open(@Nullable final ReadableMap options, Promise promise) {
|
||||
|
||||
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
|
||||
if (activity == null) {
|
||||
Activity raw_activity = getCurrentActivity();
|
||||
if (raw_activity == null || !(raw_activity instanceof FragmentActivity)) {
|
||||
promise.reject(
|
||||
ERROR_NO_ACTIVITY,
|
||||
"Tried to open a TimePicker dialog while not attached to an Activity");
|
||||
ERROR_NO_ACTIVITY,
|
||||
"Tried to open a DatePicker dialog while not attached to a FragmentActivity");
|
||||
return;
|
||||
}
|
||||
|
||||
FragmentActivity activity = (FragmentActivity) raw_activity;
|
||||
|
||||
// We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
|
||||
// (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
|
|
Загрузка…
Ссылка в новой задаче