Add spec for TimePickerAndroid (#24897)
Summary: Part of #24875 ## Changelog [General] [Added] - Add TurboModule spec for TimePickerAndroid Pull Request resolved: https://github.com/facebook/react-native/pull/24897 Reviewed By: fkgozali Differential Revision: D15424335 Pulled By: RSNara fbshipit-source-id: a846de9353af58ad7d5e09678dd810ac33532105
This commit is contained in:
Родитель
07398592f2
Коммит
65b10b350e
|
@ -4,21 +4,30 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type {TurboModule} from 'RCTExport';
|
||||
import * as TurboModuleRegistry from 'TurboModuleRegistry';
|
||||
|
||||
export type TimePickerOptions = {|
|
||||
hour?: number,
|
||||
minute?: number,
|
||||
is24Hour?: boolean,
|
||||
mode?: 'clock' | 'spinner' | 'default',
|
||||
mode?: string,
|
||||
|};
|
||||
|
||||
export type TimePickerResult = $ReadOnly<{|
|
||||
export type TimePickerResult = {|
|
||||
action: string,
|
||||
hour: number,
|
||||
minute: number,
|
||||
|}>;
|
||||
|};
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+open: (options: TimePickerOptions) => Promise<TimePickerResult>;
|
||||
}
|
||||
|
||||
export default TurboModuleRegistry.get<Spec>('TimePickerAndroid');
|
|
@ -1,26 +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 type {
|
||||
TimePickerOptions,
|
||||
TimePickerResult,
|
||||
} from './TimePickerAndroidTypes';
|
||||
|
||||
const TimePickerAndroid = {
|
||||
async open(options: TimePickerOptions): Promise<TimePickerResult> {
|
||||
return Promise.reject({
|
||||
message: 'TimePickerAndroid is not supported on this platform.',
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = TimePickerAndroid;
|
|
@ -10,13 +10,10 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const TimePickerModule = require('../../BatchedBridge/NativeModules')
|
||||
.TimePickerAndroid;
|
||||
|
||||
import type {
|
||||
TimePickerOptions,
|
||||
TimePickerResult,
|
||||
} from './TimePickerAndroidTypes';
|
||||
import NativeTimePickerAndroid, {
|
||||
type TimePickerOptions,
|
||||
type TimePickerResult,
|
||||
} from './NativeTimePickerAndroid';
|
||||
|
||||
/**
|
||||
* Opens the standard Android time picker dialog.
|
||||
|
@ -58,8 +55,16 @@ class TimePickerAndroid {
|
|||
* 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);
|
||||
static async open(
|
||||
options: TimePickerOptions,
|
||||
): Promise<$ReadOnly<TimePickerResult>> {
|
||||
if (NativeTimePickerAndroid) {
|
||||
return NativeTimePickerAndroid.open(options);
|
||||
} else {
|
||||
return Promise.reject({
|
||||
message: 'TimePickerAndroid is not supported on this platform.',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
Загрузка…
Ссылка в новой задаче