-
-
Notifications
You must be signed in to change notification settings - Fork 455
Expand file tree
/
Copy pathdatetimepicker.android.js
More file actions
82 lines (77 loc) · 2.15 KB
/
datetimepicker.android.js
File metadata and controls
82 lines (77 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @format
* @flow strict-local
*/
import {ANDROID_DISPLAY, ANDROID_MODE} from './constants';
import {useEffect} from 'react';
import type {AndroidNativeProps} from './types';
import {validateAndroidProps} from './androidUtils';
import {DateTimePickerAndroid} from './DateTimePickerAndroid';
export default function RNDateTimePickerAndroid(
props: AndroidNativeProps,
): null {
validateAndroidProps(props);
const {
mode = ANDROID_MODE.date,
display = ANDROID_DISPLAY.default,
value,
onChange,
is24Hour,
minimumDate,
maximumDate,
minuteInterval,
onError,
timeZoneOffsetInMinutes,
timeZoneName,
positiveButton,
negativeButton,
neutralButton,
testID,
firstDayOfWeek,
title,
initialInputMode,
design,
fullscreen,
startOnYearSelection,
} = props;
const valueTimestamp = value.getTime();
useEffect(() => {
// This effect runs on unmount / with mode change, and will ensure the picker is closed.
// This allows for controlling the opening state of the picker through declarative logic in jsx.
return () => DateTimePickerAndroid.dismiss(mode, design);
}, [mode, design]);
useEffect(
function showOrUpdatePicker() {
const params = {
mode,
value: new Date(valueTimestamp),
display,
is24Hour,
minimumDate,
maximumDate,
minuteInterval,
timeZoneOffsetInMinutes,
timeZoneName,
onError,
onChange,
positiveButton,
negativeButton,
neutralButton,
testID,
firstDayOfWeek,
title,
initialInputMode,
design,
fullscreen,
startOnYearSelection,
};
DateTimePickerAndroid.open(params);
},
// the android dialog, when presented, will actually ignore updates to all props other than `value`
// as an alternative, use the DateTimePickerAndroid whose reason for existence is described in
// https://github.com/react-native-datetimepicker/datetimepicker/pull/327#issuecomment-723160992
// eslint-disable-next-line react-hooks/exhaustive-deps
[onChange, valueTimestamp, mode],
);
return null;
}