mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: Related to #22100 . I had this issue before(#22154 & #22172). Turn Flow strict mode on for Libraries/Components/TimePickerAndroid/TimePickerAndroid.android.js. - [x] npm run prettier - [x] npm run flow - [x] npm run flow-check-ios - [x] npm run flow-check-android - [x] npm run lint - [x] npm run test - [x] ./scripts/run-android-local-unit-tests.sh [GENERAL][ENHANCEMENT][TimePickerAndroid.android.js] - apply flow strict-local Pull Request resolved: https://github.com/facebook/react-native/pull/22188 Reviewed By: TheSavior Differential Revision: D12972356 Pulled By: RSNara fbshipit-source-id: 838604a791dfdc86bacf8b49f6c399920a3f57bc
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
/**
|
|
* 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';
|
|
|
|
const TimePickerModule = require('NativeModules').TimePickerAndroid;
|
|
|
|
import type {
|
|
TimePickerOptions,
|
|
TimePickerResult,
|
|
} from './TimePickerAndroidTypes';
|
|
|
|
/**
|
|
* 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<TimePickerResult> {
|
|
return TimePickerModule.open(options);
|
|
}
|
|
|
|
/**
|
|
* A time has been selected.
|
|
*/
|
|
static +timeSetAction: 'timeSetAction' = 'timeSetAction';
|
|
/**
|
|
* The dialog has been dismissed.
|
|
*/
|
|
static +dismissedAction: 'dismissedAction' = 'dismissedAction';
|
|
}
|
|
|
|
module.exports = TimePickerAndroid;
|