diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index eb76314c26..cbc45eb065 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -7234,13 +7234,19 @@ export interface DatePickerAndroidOpenOptions { } // Deduced from DatePickerAndroid.android.js -export interface DatePickerAndroidOpenReturn { - action: string; // "dateSetAction" | "dismissedAction" - year?: number; - month?: number; - day?: number; +export interface DatePickerAndroidDateSetAction { + action: 'dateSetAction'; + year: number; + month: number; + day: number; } +export interface DatePickerAndroidDismissedAction { + action: 'dismissedAction'; +} + +export type DatePickerAndroidOpenReturn = DatePickerAndroidDateSetAction | DatePickerAndroidDismissedAction + export interface DatePickerAndroidStatic { /** * Opens the standard Android date picker dialog. @@ -7265,12 +7271,12 @@ export interface DatePickerAndroidStatic { /** * A date has been selected. */ - dateSetAction: string; + dateSetAction: 'dateSetAction'; /** * The dialog has been dismissed. */ - dismissedAction: string; + dismissedAction: 'dismissedAction'; } export interface IntentAndroidStatic { @@ -8010,12 +8016,24 @@ export class StatusBar extends React.Component { */ export interface StatusBarIOSStatic extends NativeEventEmitter {} -type TimePickerAndroidOpenOptions = { +export interface TimePickerAndroidOpenOptions { hour?: number; minute?: number; is24Hour?: boolean; mode?: "clock" | "spinner" | "default"; -}; +} + +export interface TimePickerAndroidTimeSetAction { + action: 'timeSetAction'; + hour: number; + minute: number; +} + +export interface TimePickerAndroidDismissedAction { + action: 'dismissedAction'; +} + +export type TimePickerAndroidOpenReturn = TimePickerAndroidTimeSetAction | TimePickerAndroidDismissedAction; /** * Opens the standard Android time picker dialog. @@ -8057,17 +8075,17 @@ export interface TimePickerAndroidStatic { * still be resolved with action being `TimePickerAndroid.dismissedAction` and all the other keys * being undefined. **Always** check whether the `action` before reading the values. */ - open(options: TimePickerAndroidOpenOptions): Promise<{ action: string; hour: number; minute: number }>; + open(options: TimePickerAndroidOpenOptions): Promise; /** * A time has been selected. */ - timeSetAction: string; + timeSetAction: 'timeSetAction'; /** * The dialog has been dismissed. */ - dismissedAction: string; + dismissedAction: 'dismissedAction'; } /** diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 842882cc29..4186b082fb 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -78,6 +78,7 @@ import { KeyboardAvoidingView, Modal, TimePickerAndroid, + DatePickerAndroid, ViewPropTypes, requireNativeComponent, } from "react-native"; @@ -762,13 +763,29 @@ const AlertIOSTest = () => { const ModalTest = () => ; -const TimePickerAndroidTest = () => +const TimePickerAndroidTest = () => { TimePickerAndroid.open({ hour: 8, minute: 15, is24Hour: true, mode: "spinner", + }).then(result => { + if (result.action === TimePickerAndroid.timeSetAction) { + console.log('Time', result.hour, result.minute) + } }); +} + +const DatePickerAndroidTest = () => { + DatePickerAndroid.open({ + date: new Date(), + mode: 'calendar' + }).then(result => { + if (result.action === DatePickerAndroid.dateSetAction) { + console.log('Date', result.year, result.month, result.day) + } + }); +} class BridgedComponentTest extends React.Component { static propTypes = {