Skip to content

Commit

Permalink
TimePickerDialogModule supports only FragmentActivity (#23372)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dulmandakh authored and facebook-github-bot committed Feb 11, 2019
1 parent 9ff43ab commit be361d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 86 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
package com.facebook.react.modules.timepicker;

import android.app.Dialog;
import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.format.DateFormat;

import java.util.Calendar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

package com.facebook.react.modules.timepicker;

import android.app.Activity;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.widget.TimePicker;

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

Activity activity = getCurrentActivity();
FragmentActivity activity = (FragmentActivity) getCurrentActivity();
if (activity == null) {
promise.reject(
ERROR_NO_ACTIVITY,
Expand All @@ -101,39 +101,20 @@ public void open(@Nullable final ReadableMap options, Promise promise) {
}
// 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.
if (activity instanceof android.support.v4.app.FragmentActivity) {
android.support.v4.app.FragmentManager fragmentManager =
((android.support.v4.app.FragmentActivity) activity).getSupportFragmentManager();
android.support.v4.app.DialogFragment oldFragment =
(android.support.v4.app.DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
if (oldFragment != null) {
oldFragment.dismiss();
}
SupportTimePickerDialogFragment fragment = new SupportTimePickerDialogFragment();
if (options != null) {
Bundle args = createFragmentArguments(options);
fragment.setArguments(args);
}
TimePickerDialogListener listener = new TimePickerDialogListener(promise);
fragment.setOnDismissListener(listener);
fragment.setOnTimeSetListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
} else {
FragmentManager fragmentManager = activity.getFragmentManager();
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
if (oldFragment != null) {
oldFragment.dismiss();
}
TimePickerDialogFragment fragment = new TimePickerDialogFragment();
if (options != null) {
final Bundle args = createFragmentArguments(options);
fragment.setArguments(args);
}
TimePickerDialogListener listener = new TimePickerDialogListener(promise);
fragment.setOnDismissListener(listener);
fragment.setOnTimeSetListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
FragmentManager fragmentManager = activity.getSupportFragmentManager();
DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
if (oldFragment != null) {
oldFragment.dismiss();
}
TimePickerDialogFragment fragment = new TimePickerDialogFragment();
if (options != null) {
Bundle args = createFragmentArguments(options);
fragment.setArguments(args);
}
TimePickerDialogListener listener = new TimePickerDialogListener(promise);
fragment.setOnDismissListener(listener);
fragment.setOnTimeSetListener(listener);
fragment.show(fragmentManager, FRAGMENT_TAG);
}

private Bundle createFragmentArguments(ReadableMap options) {
Expand Down

0 comments on commit be361d0

Please sign in to comment.