mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Merge pull request #31990 from split/react-native-android-date-time-pickers
[react-native] Action types for Android date and time pickers
This commit is contained in:
commit
e836acc75a
42
types/react-native/index.d.ts
vendored
42
types/react-native/index.d.ts
vendored
@ -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<StatusBarProps> {
|
||||
*/
|
||||
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<TimePickerAndroidOpenReturn>;
|
||||
|
||||
/**
|
||||
* A time has been selected.
|
||||
*/
|
||||
timeSetAction: string;
|
||||
timeSetAction: 'timeSetAction';
|
||||
|
||||
/**
|
||||
* The dialog has been dismissed.
|
||||
*/
|
||||
dismissedAction: string;
|
||||
dismissedAction: 'dismissedAction';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -78,6 +78,7 @@ import {
|
||||
KeyboardAvoidingView,
|
||||
Modal,
|
||||
TimePickerAndroid,
|
||||
DatePickerAndroid,
|
||||
ViewPropTypes,
|
||||
requireNativeComponent,
|
||||
} from "react-native";
|
||||
@ -762,13 +763,29 @@ const AlertIOSTest = () => {
|
||||
|
||||
const ModalTest = () => <Modal hardwareAccelerated />;
|
||||
|
||||
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 = {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user