From baf4122ccdd097ab7bd1f6d5b3139f3488b42ca1 Mon Sep 17 00:00:00 2001 From: Shawn Dempsey Date: Tue, 2 Apr 2024 17:45:19 -0700 Subject: [PATCH] [macos] Add MacOS implementation --- src/datetimepicker.macos.js | 61 ++++++++++++++++++++++ src/picker.macos.js | 12 +++++ src/specs/DateTimePickerNativeComponent.js | 29 +++++----- 3 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 src/datetimepicker.macos.js create mode 100644 src/picker.macos.js diff --git a/src/datetimepicker.macos.js b/src/datetimepicker.macos.js new file mode 100644 index 00000000..1ef92658 --- /dev/null +++ b/src/datetimepicker.macos.js @@ -0,0 +1,61 @@ +/** + * 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. + * + * This is a controlled component version of RNDateTimePicker + * + * @format + * @flow strict-local + */ +import RNDateTimePicker from './picker'; +import {dateToMilliseconds, sharedPropsValidation} from './utils'; +import { EVENT_TYPE_SET } from './constants'; +import * as React from 'react'; + +import type { + DateTimePickerEvent, + NativeEventIOS, + IOSNativeProps, +} from './types'; + +export default function Picker({ + value, + maximumDate, + minimumDate, + minuteInterval, + timeZoneOffsetInMinutes, + onChange, + pickerStyle = 'textfield-stepper', + mode = 'range', + ...other +}: IOSNativeProps): React.Node { + sharedPropsValidation({value, timeZoneOffsetInMinutes}); + + const _onChange = (event: NativeEventIOS) => { + const timestamp = event.nativeEvent.timestamp; + const unifiedEvent: DateTimePickerEvent = { + ...event, + type: EVENT_TYPE_SET, + }; + + const date = timestamp !== undefined ? new Date(timestamp) : undefined; + + onChange && onChange(unifiedEvent, date); + }; + + return ( + true} + onResponderTerminationRequest={() => false} + /> + ); +} diff --git a/src/picker.macos.js b/src/picker.macos.js new file mode 100644 index 00000000..82ed3186 --- /dev/null +++ b/src/picker.macos.js @@ -0,0 +1,12 @@ +/** + * 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 + */ +import RNDateTimePicker from './specs/DateTimePickerNativeComponent'; + +export default RNDateTimePicker; diff --git a/src/specs/DateTimePickerNativeComponent.js b/src/specs/DateTimePickerNativeComponent.js index 9c6e0f58..9886e7f7 100644 --- a/src/specs/DateTimePickerNativeComponent.js +++ b/src/specs/DateTimePickerNativeComponent.js @@ -16,25 +16,28 @@ type DateTimePickerEvent = $ReadOnly<{| utcOffset: Int32, |}>; +type DateTimePickerMode = 'date' | 'time' | 'datetime' | 'countdown' | 'single' | 'range'; +type ThemeVariant = 'dark' | 'light' | 'unspecified' +type DisplayStyle = 'default' | 'spinner' | 'compact' | 'inline'; +type PickerStyle = 'textfield-stepper' | 'clock-calendar' | 'textfield'; + type NativeProps = $ReadOnly<{| ...ViewProps, - accentColor?: ?ColorValue, - date?: ?Double, - displayIOS?: WithDefault< - 'default' | 'spinner' | 'compact' | 'inline', - 'default', - >, - locale?: ?string, + onChange?: ?BubblingEventHandler, + onPickerDismiss?: ?BubblingEventHandler, maximumDate?: ?Double, minimumDate?: ?Double, + date?: ?Double, + locale?: ?string, minuteInterval?: ?Int32, - mode?: WithDefault<'date' | 'time' | 'datetime' | 'countdown', 'date'>, - onChange?: ?BubblingEventHandler, - onPickerDismiss?: ?BubblingEventHandler, - textColor?: ?ColorValue, - themeVariant?: WithDefault<'dark' | 'light' | 'unspecified', 'unspecified'>, - timeZoneName?: ?string, + mode?: WithDefault, timeZoneOffsetInMinutes?: ?Double, + timeZoneName?: ?string, + textColor?: ?ColorValue, + accentColor?: ?ColorValue, + themeVariant?: WithDefault, + displayIOS?: WithDefault, + pickerStyleMacOSX?: WithDefault, enabled?: WithDefault, |}>;