From dbf070c51ecd14127a8317faa75cb661697b5a6b Mon Sep 17 00:00:00 2001 From: Christoph Nakazawa Date: Fri, 13 Sep 2019 07:44:20 -0700 Subject: [PATCH] Remove TimePickerAndroid from React Native Summary: Lean Core Reviewed By: rubennorte Differential Revision: D17344045 fbshipit-source-id: a5a7ab41075da93f8a1929059abe183838b00c82 --- .../NativeTimePickerAndroid.js | 33 ----- .../TimePickerAndroid/TimePickerAndroid.js | 80 ----------- .../FBReactNativeSpec-generated.mm | 33 ----- .../FBReactNativeSpec/FBReactNativeSpec.h | 92 ------------- .../TimePicker/TimePickerAndroidExample.js | 125 ------------------ RNTester/js/utils/RNTesterList.android.js | 4 - ReactAndroid/src/androidTest/js/TestBundle.js | 6 - .../js/TimePickerDialogTestModule.js | 45 ------- index.js | 23 ++-- 9 files changed, 13 insertions(+), 428 deletions(-) delete mode 100644 Libraries/Components/TimePickerAndroid/NativeTimePickerAndroid.js delete mode 100644 Libraries/Components/TimePickerAndroid/TimePickerAndroid.js delete mode 100644 RNTester/js/examples/TimePicker/TimePickerAndroidExample.js delete mode 100644 ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js diff --git a/Libraries/Components/TimePickerAndroid/NativeTimePickerAndroid.js b/Libraries/Components/TimePickerAndroid/NativeTimePickerAndroid.js deleted file mode 100644 index ac4aa7e6eb3e18..00000000000000 --- a/Libraries/Components/TimePickerAndroid/NativeTimePickerAndroid.js +++ /dev/null @@ -1,33 +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. - * - * @flow - * @format - */ - -'use strict'; - -import type {TurboModule} from '../../TurboModule/RCTExport'; -import * as TurboModuleRegistry from '../../TurboModule/TurboModuleRegistry'; - -export type TimePickerOptions = {| - hour?: number, - minute?: number, - is24Hour?: boolean, - mode?: string, -|}; - -export type TimePickerResult = {| - action: string, - hour: number, - minute: number, -|}; - -export interface Spec extends TurboModule { - +open: (options: TimePickerOptions) => Promise; -} - -export default (TurboModuleRegistry.get('TimePickerAndroid'): ?Spec); diff --git a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.js b/Libraries/Components/TimePickerAndroid/TimePickerAndroid.js deleted file mode 100644 index 5c2aab9cf52cc1..00000000000000 --- a/Libraries/Components/TimePickerAndroid/TimePickerAndroid.js +++ /dev/null @@ -1,80 +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. - * - * @format - * @flow strict-local - */ - -'use strict'; - -import NativeTimePickerAndroid, { - type TimePickerOptions, - type TimePickerResult, -} from './NativeTimePickerAndroid'; - -/** - * Opens the standard Android time picker dialog. - * - * ### Example - * - * ``` - * try { - * const {action, hour, minute} = await TimePickerAndroid.open({ - * hour: 14, - * minute: 0, - * is24Hour: false, // Will display '2 PM' - * }); - * if (action !== TimePickerAndroid.dismissedAction) { - * // Selected hour (0-23), minute (0-59) - * } - * } catch ({code, message}) { - * console.warn('Cannot open time picker', message); - * } - * ``` - */ -class TimePickerAndroid { - /** - * Opens the standard Android time picker dialog. - * - * The available keys for the `options` object are: - * * `hour` (0-23) - the hour to show, defaults to the current time - * * `minute` (0-59) - the minute to show, defaults to the current time - * * `is24Hour` (boolean) - If `true`, the picker uses the 24-hour format. If `false`, - * the picker shows an AM/PM chooser. If undefined, the default for the current locale - * is used. - * * `mode` (`enum('clock', 'spinner', 'default')`) - set the time picker mode - * - 'clock': Show a time picker in clock mode. - * - 'spinner': Show a time picker in spinner mode. - * - 'default': Show a default time picker based on Android versions. - * - * Returns a Promise which will be invoked an object containing `action`, `hour` (0-23), - * `minute` (0-59) if the user picked a time. If the user dismissed the dialog, the Promise will - * still be resolved with action being `TimePickerAndroid.dismissedAction` and all the other keys - * being undefined. **Always** check whether the `action` before reading the values. - */ - static async open( - options: TimePickerOptions, - ): Promise<$ReadOnly> { - if (NativeTimePickerAndroid) { - return NativeTimePickerAndroid.open(options); - } else { - return Promise.reject({ - message: 'TimePickerAndroid is not supported on this platform.', - }); - } - } - - /** - * A time has been selected. - */ - static +timeSetAction: 'timeSetAction' = 'timeSetAction'; - /** - * The dialog has been dismissed. - */ - static +dismissedAction: 'dismissedAction' = 'dismissedAction'; -} - -module.exports = TimePickerAndroid; diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm index e0ff2cfd602024..0c086448d40cc4 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm @@ -1995,39 +1995,6 @@ + (RCTManagedPointer *)JS_NativeStatusBarManager_SpecGetHeightCallbackResult:(id } // namespace react } // namespace facebook -@implementation RCTCxxConvert (NativeTimePickerAndroid_TimePickerOptions) -+ (RCTManagedPointer *)JS_NativeTimePickerAndroid_TimePickerOptions:(id)json -{ - return facebook::react::managedPointer(json); -} -@end -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(turboModule).invokeObjCMethod(rt, PromiseKind, "open", @selector(open:resolve:reject:), args, count); - } - - - NativeTimePickerAndroidSpecJSI::NativeTimePickerAndroidSpecJSI(id instance, std::shared_ptr jsInvoker) - : ObjCTurboModule("TimePickerAndroid", instance, jsInvoker) { - - methodMap_["open"] = MethodMetadata {1, __hostFunction_NativeTimePickerAndroidSpecJSI_open}; - - setMethodArgConversionSelector(@"open", 0, @"JS_NativeTimePickerAndroid_TimePickerOptions:"); - - - } - - } // namespace react -} // namespace facebook -@implementation RCTCxxConvert (NativeTimePickerAndroid_TimePickerResult) -+ (RCTManagedPointer *)JS_NativeTimePickerAndroid_TimePickerResult:(id)json -{ - return facebook::react::managedPointer(json); -} -@end namespace facebook { namespace react { diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index 9cc6942263245f..16fe9ab45456da 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -2038,63 +2038,6 @@ namespace facebook { }; } // namespace react } // namespace facebook - -namespace JS { - namespace NativeTimePickerAndroid { - struct TimePickerOptions { - folly::Optional hour() const; - folly::Optional minute() const; - folly::Optional is24Hour() const; - NSString *mode() const; - - TimePickerOptions(NSDictionary *const v) : _v(v) {} - private: - NSDictionary *_v; - }; - } -} - -@interface RCTCxxConvert (NativeTimePickerAndroid_TimePickerOptions) -+ (RCTManagedPointer *)JS_NativeTimePickerAndroid_TimePickerOptions:(id)json; -@end -@protocol NativeTimePickerAndroidSpec - -- (void)open:(JS::NativeTimePickerAndroid::TimePickerOptions &)options - resolve:(RCTPromiseResolveBlock)resolve - reject:(RCTPromiseRejectBlock)reject; - -@end -namespace facebook { - namespace react { - /** - * ObjC++ class for module 'TimePickerAndroid' - */ - - class JSI_EXPORT NativeTimePickerAndroidSpecJSI : public ObjCTurboModule { - public: - NativeTimePickerAndroidSpecJSI(id instance, std::shared_ptr jsInvoker); - - }; - } // namespace react -} // namespace facebook - -namespace JS { - namespace NativeTimePickerAndroid { - struct TimePickerResult { - NSString *action() const; - double hour() const; - double minute() const; - - TimePickerResult(NSDictionary *const v) : _v(v) {} - private: - NSDictionary *_v; - }; - } -} - -@interface RCTCxxConvert (NativeTimePickerAndroid_TimePickerResult) -+ (RCTManagedPointer *)JS_NativeTimePickerAndroid_TimePickerResult:(id)json; -@end @protocol NativeTimingSpec - (void)createTimer:(double)callbackID @@ -3074,41 +3017,6 @@ inline JS::NativeStatusBarManager::Constants::Builder::Builder(const Input i) : inline JS::NativeStatusBarManager::Constants::Builder::Builder(Constants i) : _factory(^{ return i.unsafeRawValue(); }) {} -inline folly::Optional JS::NativeTimePickerAndroid::TimePickerOptions::hour() const -{ - id const p = _v[@"hour"]; - return RCTBridgingToOptionalDouble(p); -} -inline folly::Optional JS::NativeTimePickerAndroid::TimePickerOptions::minute() const -{ - id const p = _v[@"minute"]; - return RCTBridgingToOptionalDouble(p); -} -inline folly::Optional JS::NativeTimePickerAndroid::TimePickerOptions::is24Hour() const -{ - id const p = _v[@"is24Hour"]; - return RCTBridgingToOptionalBool(p); -} -inline NSString *JS::NativeTimePickerAndroid::TimePickerOptions::mode() const -{ - id const p = _v[@"mode"]; - return RCTBridgingToString(p); -} -inline NSString *JS::NativeTimePickerAndroid::TimePickerResult::action() const -{ - id const p = _v[@"action"]; - return RCTBridgingToString(p); -} -inline double JS::NativeTimePickerAndroid::TimePickerResult::hour() const -{ - id const p = _v[@"hour"]; - return RCTBridgingToDouble(p); -} -inline double JS::NativeTimePickerAndroid::TimePickerResult::minute() const -{ - id const p = _v[@"minute"]; - return RCTBridgingToDouble(p); -} inline JS::NativeToastAndroid::Constants::Builder::Builder(const Input i) : _factory(^{ NSMutableDictionary *d = [NSMutableDictionary new]; auto SHORT = i.SHORT.get(); diff --git a/RNTester/js/examples/TimePicker/TimePickerAndroidExample.js b/RNTester/js/examples/TimePicker/TimePickerAndroidExample.js deleted file mode 100644 index ced8a74ff73a41..00000000000000 --- a/RNTester/js/examples/TimePicker/TimePickerAndroidExample.js +++ /dev/null @@ -1,125 +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. - * - * @format - */ - -'use strict'; - -const React = require('react'); -const { - TimePickerAndroid, - StyleSheet, - Text, - TouchableWithoutFeedback, -} = require('react-native'); - -const RNTesterBlock = require('../../components/RNTesterBlock'); -const RNTesterPage = require('../../components/RNTesterPage'); - -class TimePickerAndroidExample extends React.Component { - state = { - isoFormatText: 'pick a time (24-hour format)', - presetHour: 4, - presetMinute: 4, - presetText: 'pick a time, default: 4:04AM', - simpleText: 'pick a time', - clockText: 'pick a time', - spinnerText: 'pick a time', - defaultText: 'pick a time', - }; - - showPicker = async (stateKey, options) => { - try { - const {action, minute, hour} = await TimePickerAndroid.open(options); - const newState = {}; - if (action === TimePickerAndroid.timeSetAction) { - newState[stateKey + 'Text'] = _formatTime(hour, minute); - newState[stateKey + 'Hour'] = hour; - newState[stateKey + 'Minute'] = minute; - } else if (action === TimePickerAndroid.dismissedAction) { - newState[stateKey + 'Text'] = 'dismissed'; - } - this.setState(newState); - } catch ({code, message}) { - console.warn(`Error in example '${stateKey}': `, message); - } - }; - - render() { - return ( - - - - {this.state.simpleText} - - - - - {this.state.clockText} - - - - - {this.state.spinnerText} - - - - - {this.state.defaultText} - - - - - {this.state.presetText} - - - - - {this.state.isoFormatText} - - - - ); - } -} - -/** - * Returns e.g. '3:05'. - */ -function _formatTime(hour, minute) { - return hour + ':' + (minute < 10 ? '0' + minute : minute); -} - -const styles = StyleSheet.create({ - text: { - color: 'black', - }, -}); - -exports.title = 'TimePickerAndroid'; -exports.description = 'Standard Android time picker dialog'; -exports.examples = [ - { - title: 'Simple time picker', - render: function(): React.Element { - return ; - }, - }, -]; diff --git a/RNTester/js/utils/RNTesterList.android.js b/RNTester/js/utils/RNTesterList.android.js index c8d6c28b7ebc32..fb32d01cf9415d 100644 --- a/RNTester/js/utils/RNTesterList.android.js +++ b/RNTester/js/utils/RNTesterList.android.js @@ -204,10 +204,6 @@ const APIExamples: Array = [ key: 'ShareExample', module: require('../examples/Share/ShareExample'), }, - { - key: 'TimePickerAndroidExample', - module: require('../examples/TimePicker/TimePickerAndroidExample'), - }, { key: 'TimerExample', module: require('../examples/Timer/TimerExample'), diff --git a/ReactAndroid/src/androidTest/js/TestBundle.js b/ReactAndroid/src/androidTest/js/TestBundle.js index 9aa42a745d9fde..4634d0c80491af 100644 --- a/ReactAndroid/src/androidTest/js/TestBundle.js +++ b/ReactAndroid/src/androidTest/js/TestBundle.js @@ -29,7 +29,6 @@ require('./ScrollViewTestModule'); require('./ShareTestModule'); require('./SwipeRefreshLayoutTestModule'); require('./TextInputTestModule'); -require('./TimePickerDialogTestModule'); // Define catalyst test apps used in integration tests const {AppRegistry} = require('react-native'); @@ -116,11 +115,6 @@ const apps = [ appKey: 'TestIdTestApp', component: () => require('./TestIdTestModule').TestIdTestApp, }, - { - appKey: 'TimePickerDialogTestApp', - component: () => - require('./TimePickerDialogTestModule').TimePickerDialogTestApp, - }, { appKey: 'TouchBubblingTestAppModule', component: () => require('./TouchBubblingTestAppModule'), diff --git a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js b/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js deleted file mode 100644 index 987e7cd2ca2b34..00000000000000 --- a/ReactAndroid/src/androidTest/js/TimePickerDialogTestModule.js +++ /dev/null @@ -1,45 +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. - * - * @format - */ - -'use strict'; - -const React = require('react'); -const {NativeModules, TimePickerAndroid, View} = require('react-native'); -const BatchedBridge = require('react-native/Libraries/BatchedBridge/BatchedBridge'); - -const {TimePickerDialogRecordingModule: RecordingModule} = NativeModules; - -class TimePickerDialogTestApp extends React.Component { - render() { - return ; - } -} - -const TimePickerDialogTestModule = { - TimePickerDialogTestApp: TimePickerDialogTestApp, - showTimePickerDialog: function(options) { - TimePickerAndroid.open(options).then( - ({action, hour, minute}) => { - if (action === TimePickerAndroid.timeSetAction) { - RecordingModule.recordTime(hour, minute); - } else if (action === TimePickerAndroid.dismissedAction) { - RecordingModule.recordDismissed(); - } - }, - ({code, message}) => RecordingModule.recordError(), - ); - }, -}; - -BatchedBridge.registerCallableModule( - 'TimePickerDialogTestModule', - TimePickerDialogTestModule, -); - -module.exports = TimePickerDialogTestModule; diff --git a/index.js b/index.js index 0532da156ec055..24af2714ae0292 100644 --- a/index.js +++ b/index.js @@ -77,7 +77,6 @@ import typeof Share from './Libraries/Share/Share'; import typeof StatusBarIOS from './Libraries/Components/StatusBar/StatusBarIOS'; import typeof StyleSheet from './Libraries/StyleSheet/StyleSheet'; import typeof Systrace from './Libraries/Performance/Systrace'; -import typeof TimePickerAndroid from './Libraries/Components/TimePickerAndroid/TimePickerAndroid'; import typeof ToastAndroid from './Libraries/Components/ToastAndroid/ToastAndroid'; import typeof * as TurboModuleRegistry from './Libraries/TurboModule/TurboModuleRegistry'; import typeof TVEventHandler from './Libraries/Components/AppleTV/TVEventHandler'; @@ -373,15 +372,6 @@ module.exports = { get Systrace(): Systrace { return require('./Libraries/Performance/Systrace'); }, - get TimePickerAndroid(): TimePickerAndroid { - warnOnce( - 'TimePickerAndroid-merged', - 'TimePickerAndroid has been merged with DatePickerIOS and DatePickerAndroid and will be removed in a future release. ' + - "It can now be installed and imported from '@react-native-community/datetimepicker' instead of 'react-native'. " + - 'See https://github.com/react-native-community/react-native-datetimepicker', - ); - return require('./Libraries/Components/TimePickerAndroid/TimePickerAndroid'); - }, get ToastAndroid(): ToastAndroid { return require('./Libraries/Components/ToastAndroid/ToastAndroid'); }, @@ -561,6 +551,19 @@ if (__DEV__) { }, }); + // $FlowFixMe This is intentional: Flow will error when attempting to access TimePickerAndroid. + Object.defineProperty(module.exports, 'TimePickerAndroid', { + configurable: true, + get() { + invariant( + false, + 'TimePickerAndroid has been removed from React Native. ' + + "It can now be installed and imported from '@react-native-community/datetimepicker' instead of 'react-native'. " + + 'See https://github.com/react-native-community/react-native-datetimepicker', + ); + }, + }); + // $FlowFixMe This is intentional: Flow will error when attempting to access ViewPagerAndroid. Object.defineProperty(module.exports, 'ViewPagerAndroid', { configurable: true,