Skip to content

Commit be361d0

Browse files
dulmandakhfacebook-github-bot
authored andcommitted
TimePickerDialogModule supports only FragmentActivity (#23372)
Summary: Now RN has only ReactActivity which extends AppCompatActivity, subclass of FragmentActivity, therefore no need to check if activity is FragmentActivity or not. This PR changes TimePickerDialogModule to work only with FragmentActivity. Also DialogFragment from Android is deprecated in API 28, and recommends to use DialogFragment from Support Library. Excerpt from DialogFragment documentation. > **This class was deprecated in API level 28.** > Use the Support Library DialogFragment for consistent behavior across all devices and access to Lifecycle. [Android] [Changed] - TimePickerDialogModule supports only FragmentActivity Pull Request resolved: #23372 Differential Revision: D14030748 Pulled By: cpojer fbshipit-source-id: 9b3778c90eb1c014260327513bc8709264b94431
1 parent 9ff43ab commit be361d0

File tree

3 files changed

+18
-86
lines changed

3 files changed

+18
-86
lines changed

ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/SupportTimePickerDialogFragment.java

-48
This file was deleted.

ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogFragment.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
package com.facebook.react.modules.timepicker;
99

1010
import android.app.Dialog;
11-
import android.app.DialogFragment;
12-
import android.app.TimePickerDialog;
1311
import android.app.TimePickerDialog.OnTimeSetListener;
1412
import android.content.Context;
1513
import android.content.DialogInterface;
1614
import android.content.DialogInterface.OnDismissListener;
1715
import android.os.Build;
1816
import android.os.Bundle;
17+
import android.support.v4.app.DialogFragment;
1918
import android.text.format.DateFormat;
2019

2120
import java.util.Calendar;

ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java

+17-36
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
package com.facebook.react.modules.timepicker;
99

10-
import android.app.Activity;
11-
import android.app.DialogFragment;
12-
import android.app.FragmentManager;
1310
import android.app.TimePickerDialog.OnTimeSetListener;
1411
import android.content.DialogInterface;
1512
import android.content.DialogInterface.OnDismissListener;
1613
import android.os.Bundle;
14+
import android.support.v4.app.DialogFragment;
15+
import android.support.v4.app.FragmentActivity;
16+
import android.support.v4.app.FragmentManager;
1717
import android.widget.TimePicker;
1818

1919
import com.facebook.react.bridge.NativeModule;
@@ -92,7 +92,7 @@ public void onDismiss(DialogInterface dialog) {
9292
@ReactMethod
9393
public void open(@Nullable final ReadableMap options, Promise promise) {
9494

95-
Activity activity = getCurrentActivity();
95+
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
9696
if (activity == null) {
9797
promise.reject(
9898
ERROR_NO_ACTIVITY,
@@ -101,39 +101,20 @@ public void open(@Nullable final ReadableMap options, Promise promise) {
101101
}
102102
// We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity
103103
// (for apps that use it for legacy reasons). This unfortunately leads to some code duplication.
104-
if (activity instanceof android.support.v4.app.FragmentActivity) {
105-
android.support.v4.app.FragmentManager fragmentManager =
106-
((android.support.v4.app.FragmentActivity) activity).getSupportFragmentManager();
107-
android.support.v4.app.DialogFragment oldFragment =
108-
(android.support.v4.app.DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
109-
if (oldFragment != null) {
110-
oldFragment.dismiss();
111-
}
112-
SupportTimePickerDialogFragment fragment = new SupportTimePickerDialogFragment();
113-
if (options != null) {
114-
Bundle args = createFragmentArguments(options);
115-
fragment.setArguments(args);
116-
}
117-
TimePickerDialogListener listener = new TimePickerDialogListener(promise);
118-
fragment.setOnDismissListener(listener);
119-
fragment.setOnTimeSetListener(listener);
120-
fragment.show(fragmentManager, FRAGMENT_TAG);
121-
} else {
122-
FragmentManager fragmentManager = activity.getFragmentManager();
123-
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
124-
if (oldFragment != null) {
125-
oldFragment.dismiss();
126-
}
127-
TimePickerDialogFragment fragment = new TimePickerDialogFragment();
128-
if (options != null) {
129-
final Bundle args = createFragmentArguments(options);
130-
fragment.setArguments(args);
131-
}
132-
TimePickerDialogListener listener = new TimePickerDialogListener(promise);
133-
fragment.setOnDismissListener(listener);
134-
fragment.setOnTimeSetListener(listener);
135-
fragment.show(fragmentManager, FRAGMENT_TAG);
104+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
105+
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
106+
if (oldFragment != null) {
107+
oldFragment.dismiss();
108+
}
109+
TimePickerDialogFragment fragment = new TimePickerDialogFragment();
110+
if (options != null) {
111+
Bundle args = createFragmentArguments(options);
112+
fragment.setArguments(args);
136113
}
114+
TimePickerDialogListener listener = new TimePickerDialogListener(promise);
115+
fragment.setOnDismissListener(listener);
116+
fragment.setOnTimeSetListener(listener);
117+
fragment.show(fragmentManager, FRAGMENT_TAG);
137118
}
138119

139120
private Bundle createFragmentArguments(ReadableMap options) {

0 commit comments

Comments
 (0)