mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move TimePickerAndroid to FB internal
Summary: Moving TimePickerAndroid to FB internal. Changelog: [Android][Changed] - Moved TimePickerAndroid to FB internal. Reviewed By: cpojer Differential Revision: D21504128 fbshipit-source-id: 400c6ee7cff96a0d6b4205f7806ef8951b611b8c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1a77943e8b
commit
c8fed9e385
-30
@@ -1,30 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*
|
||||
* <p>Generated by an internal genrule from Flow types.
|
||||
*
|
||||
* @generated
|
||||
* @nolint
|
||||
*/
|
||||
|
||||
package com.facebook.fbreact.specs;
|
||||
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReactModuleWithSpec;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
||||
|
||||
public abstract class NativeTimePickerAndroidSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
|
||||
public NativeTimePickerAndroidSpec(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public abstract void open(ReadableMap options, Promise promise);
|
||||
}
|
||||
-20
@@ -2093,26 +2093,6 @@ namespace facebook {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
||||
static facebook::jsi::Value __hostFunction_NativeTimePickerAndroidSpecJSI_open(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
||||
return static_cast<JavaTurboModule&>(turboModule).invokeJavaMethod(rt, PromiseKind, "open", "(Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V", args, count);
|
||||
}
|
||||
|
||||
|
||||
NativeTimePickerAndroidSpecJSI::NativeTimePickerAndroidSpecJSI(const JavaTurboModule::InitParams ¶ms)
|
||||
: JavaTurboModule(params) {
|
||||
|
||||
methodMap_["open"] = MethodMetadata {1, __hostFunction_NativeTimePickerAndroidSpecJSI_open};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
|
||||
@@ -745,20 +745,6 @@ namespace facebook {
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
/**
|
||||
* C++ class for module 'TimePickerAndroid'
|
||||
*/
|
||||
|
||||
class JSI_EXPORT NativeTimePickerAndroidSpecJSI : public JavaTurboModule {
|
||||
public:
|
||||
NativeTimePickerAndroidSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
||||
|
||||
};
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
/**
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
|
||||
|
||||
rn_android_library(
|
||||
name = "timepicker",
|
||||
srcs = glob(["**/*.java"]),
|
||||
is_androidx = True,
|
||||
labels = ["supermodule:xplat/default/public.react_native.infra"],
|
||||
provided_deps = [
|
||||
react_native_dep("third-party/android/androidx:annotation"),
|
||||
react_native_dep("third-party/android/androidx:core"),
|
||||
react_native_dep("third-party/android/androidx:fragment"),
|
||||
react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
|
||||
react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
|
||||
],
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
deps = [
|
||||
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
||||
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
||||
react_native_target("java/com/facebook/react/bridge:bridge"),
|
||||
react_native_target("java/com/facebook/react/common:common"),
|
||||
react_native_target("java/com/facebook/react/module/annotations:annotations"),
|
||||
],
|
||||
exported_deps = [react_native_target("java/com/facebook/fbreact/specs:FBReactNativeSpec")],
|
||||
)
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.timepicker;
|
||||
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Certain versions of Android (Jellybean-KitKat) have a bug where when dismissed, the {@link
|
||||
* TimePickerDialog} still calls the OnTimeSetListener. This class works around that issue by *not*
|
||||
* calling super.onStop on KitKat on lower, as that would erroneously call the OnTimeSetListener
|
||||
* when the dialog is dismissed, or call it twice when "OK" is pressed.
|
||||
*
|
||||
* <p>See: <a href="https://code.google.com/p/android/issues/detail?id=34833">Issue 34833</a>
|
||||
*/
|
||||
public class DismissableTimePickerDialog extends TimePickerDialog {
|
||||
|
||||
public DismissableTimePickerDialog(
|
||||
Context context,
|
||||
@Nullable TimePickerDialog.OnTimeSetListener callback,
|
||||
int hourOfDay,
|
||||
int minute,
|
||||
boolean is24HourView) {
|
||||
super(context, callback, hourOfDay, minute, is24HourView);
|
||||
}
|
||||
|
||||
public DismissableTimePickerDialog(
|
||||
Context context,
|
||||
int theme,
|
||||
@Nullable TimePickerDialog.OnTimeSetListener callback,
|
||||
int hourOfDay,
|
||||
int minute,
|
||||
boolean is24HourView) {
|
||||
super(context, theme, callback, hourOfDay, minute, is24HourView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
|
||||
super.onStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.timepicker;
|
||||
|
||||
import android.app.Dialog;
|
||||
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.text.format.DateFormat;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
@SuppressWarnings("ValidFragment")
|
||||
public class TimePickerDialogFragment extends DialogFragment {
|
||||
|
||||
@Nullable private OnTimeSetListener mOnTimeSetListener;
|
||||
@Nullable private OnDismissListener mOnDismissListener;
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Bundle args = getArguments();
|
||||
return createDialog(args, getActivity(), mOnTimeSetListener);
|
||||
}
|
||||
|
||||
/*package*/ static Dialog createDialog(
|
||||
Bundle args, Context activityContext, @Nullable OnTimeSetListener onTimeSetListener) {
|
||||
final Calendar now = Calendar.getInstance();
|
||||
int hour = now.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = now.get(Calendar.MINUTE);
|
||||
boolean is24hour = DateFormat.is24HourFormat(activityContext);
|
||||
|
||||
TimePickerMode mode = TimePickerMode.DEFAULT;
|
||||
if (args != null && args.getString(TimePickerDialogModule.ARG_MODE, null) != null) {
|
||||
mode =
|
||||
TimePickerMode.valueOf(
|
||||
args.getString(TimePickerDialogModule.ARG_MODE).toUpperCase(Locale.US));
|
||||
}
|
||||
|
||||
if (args != null) {
|
||||
hour = args.getInt(TimePickerDialogModule.ARG_HOUR, now.get(Calendar.HOUR_OF_DAY));
|
||||
minute = args.getInt(TimePickerDialogModule.ARG_MINUTE, now.get(Calendar.MINUTE));
|
||||
is24hour =
|
||||
args.getBoolean(
|
||||
TimePickerDialogModule.ARG_IS24HOUR, DateFormat.is24HourFormat(activityContext));
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (mode == TimePickerMode.CLOCK) {
|
||||
return new DismissableTimePickerDialog(
|
||||
activityContext,
|
||||
activityContext
|
||||
.getResources()
|
||||
.getIdentifier("ClockTimePickerDialog", "style", activityContext.getPackageName()),
|
||||
onTimeSetListener,
|
||||
hour,
|
||||
minute,
|
||||
is24hour);
|
||||
} else if (mode == TimePickerMode.SPINNER) {
|
||||
return new DismissableTimePickerDialog(
|
||||
activityContext,
|
||||
activityContext
|
||||
.getResources()
|
||||
.getIdentifier(
|
||||
"SpinnerTimePickerDialog", "style", activityContext.getPackageName()),
|
||||
onTimeSetListener,
|
||||
hour,
|
||||
minute,
|
||||
is24hour);
|
||||
}
|
||||
}
|
||||
return new DismissableTimePickerDialog(
|
||||
activityContext, onTimeSetListener, hour, minute, is24hour);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (mOnDismissListener != null) {
|
||||
mOnDismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnDismissListener(@Nullable OnDismissListener onDismissListener) {
|
||||
mOnDismissListener = onDismissListener;
|
||||
}
|
||||
|
||||
public void setOnTimeSetListener(@Nullable OnTimeSetListener onTimeSetListener) {
|
||||
mOnTimeSetListener = onTimeSetListener;
|
||||
}
|
||||
}
|
||||
-136
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.timepicker;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.TimePickerDialog.OnTimeSetListener;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TimePicker;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import com.facebook.fbreact.specs.NativeTimePickerAndroidSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.Promise;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
import com.facebook.react.bridge.WritableNativeMap;
|
||||
import com.facebook.react.common.annotations.VisibleForTesting;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
|
||||
/**
|
||||
* {@link NativeModule} that allows JS to show a native time picker dialog and get called back when
|
||||
* the user selects a time.
|
||||
*/
|
||||
@ReactModule(name = TimePickerDialogModule.FRAGMENT_TAG)
|
||||
public class TimePickerDialogModule extends NativeTimePickerAndroidSpec {
|
||||
|
||||
@VisibleForTesting public static final String FRAGMENT_TAG = "TimePickerAndroid";
|
||||
|
||||
private static final String ERROR_NO_ACTIVITY = "E_NO_ACTIVITY";
|
||||
|
||||
/* package */ static final String ARG_HOUR = "hour";
|
||||
/* package */ static final String ARG_MINUTE = "minute";
|
||||
/* package */ static final String ARG_IS24HOUR = "is24Hour";
|
||||
/* package */ static final String ARG_MODE = "mode";
|
||||
/* package */ static final String ACTION_TIME_SET = "timeSetAction";
|
||||
/* package */ static final String ACTION_DISMISSED = "dismissedAction";
|
||||
|
||||
public TimePickerDialogModule(ReactApplicationContext reactContext) {
|
||||
super(reactContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return FRAGMENT_TAG;
|
||||
}
|
||||
|
||||
private class TimePickerDialogListener implements OnTimeSetListener, OnDismissListener {
|
||||
|
||||
private final Promise mPromise;
|
||||
private boolean mPromiseResolved = false;
|
||||
|
||||
public TimePickerDialogListener(Promise promise) {
|
||||
mPromise = promise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hour, int minute) {
|
||||
if (!mPromiseResolved && getReactApplicationContext().hasActiveCatalystInstance()) {
|
||||
WritableMap result = new WritableNativeMap();
|
||||
result.putString("action", ACTION_TIME_SET);
|
||||
result.putInt("hour", hour);
|
||||
result.putInt("minute", minute);
|
||||
mPromise.resolve(result);
|
||||
mPromiseResolved = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (!mPromiseResolved && getReactApplicationContext().hasActiveCatalystInstance()) {
|
||||
WritableMap result = new WritableNativeMap();
|
||||
result.putString("action", ACTION_DISMISSED);
|
||||
mPromise.resolve(result);
|
||||
mPromiseResolved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(@Nullable final ReadableMap options, Promise promise) {
|
||||
|
||||
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 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();
|
||||
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) {
|
||||
final Bundle args = new Bundle();
|
||||
if (options.hasKey(ARG_HOUR) && !options.isNull(ARG_HOUR)) {
|
||||
args.putInt(ARG_HOUR, options.getInt(ARG_HOUR));
|
||||
}
|
||||
if (options.hasKey(ARG_MINUTE) && !options.isNull(ARG_MINUTE)) {
|
||||
args.putInt(ARG_MINUTE, options.getInt(ARG_MINUTE));
|
||||
}
|
||||
if (options.hasKey(ARG_IS24HOUR) && !options.isNull(ARG_IS24HOUR)) {
|
||||
args.putBoolean(ARG_IS24HOUR, options.getBoolean(ARG_IS24HOUR));
|
||||
}
|
||||
if (options.hasKey(ARG_MODE) && !options.isNull(ARG_MODE)) {
|
||||
args.putString(ARG_MODE, options.getString(ARG_MODE));
|
||||
}
|
||||
return args;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.react.modules.timepicker;
|
||||
|
||||
public enum TimePickerMode {
|
||||
CLOCK,
|
||||
SPINNER,
|
||||
DEFAULT
|
||||
}
|
||||
@@ -46,7 +46,6 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/modules/statusbar:statusbar"),
|
||||
react_native_target("java/com/facebook/react/modules/storage:storage"),
|
||||
react_native_target("java/com/facebook/react/modules/sound:sound"),
|
||||
react_native_target("java/com/facebook/react/modules/timepicker:timepicker"),
|
||||
react_native_target("java/com/facebook/react/modules/toast:toast"),
|
||||
react_native_target("java/com/facebook/react/modules/vibration:vibration"),
|
||||
react_native_target("java/com/facebook/react/modules/websocket:websocket"),
|
||||
|
||||
@@ -37,7 +37,6 @@ import com.facebook.react.modules.share.ShareModule;
|
||||
import com.facebook.react.modules.sound.SoundManagerModule;
|
||||
import com.facebook.react.modules.statusbar.StatusBarModule;
|
||||
import com.facebook.react.modules.storage.AsyncStorageModule;
|
||||
import com.facebook.react.modules.timepicker.TimePickerDialogModule;
|
||||
import com.facebook.react.modules.toast.ToastModule;
|
||||
import com.facebook.react.modules.vibration.VibrationModule;
|
||||
import com.facebook.react.modules.websocket.WebSocketModule;
|
||||
@@ -92,7 +91,6 @@ import java.util.Map;
|
||||
ShareModule.class,
|
||||
SoundManagerModule.class,
|
||||
StatusBarModule.class,
|
||||
TimePickerDialogModule.class,
|
||||
ToastModule.class,
|
||||
VibrationModule.class,
|
||||
WebSocketModule.class,
|
||||
@@ -155,8 +153,6 @@ public class MainReactPackage extends TurboReactPackage {
|
||||
return new StatusBarModule(context);
|
||||
case SoundManagerModule.NAME:
|
||||
return new SoundManagerModule(context);
|
||||
case TimePickerDialogModule.FRAGMENT_TAG:
|
||||
return new TimePickerDialogModule(context);
|
||||
case ToastModule.NAME:
|
||||
return new ToastModule(context);
|
||||
case VibrationModule.NAME:
|
||||
@@ -229,7 +225,6 @@ public class MainReactPackage extends TurboReactPackage {
|
||||
ShareModule.class,
|
||||
StatusBarModule.class,
|
||||
SoundManagerModule.class,
|
||||
TimePickerDialogModule.class,
|
||||
ToastModule.class,
|
||||
VibrationModule.class,
|
||||
WebSocketModule.class
|
||||
|
||||
Reference in New Issue
Block a user