-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonthPicker.android.js
48 lines (43 loc) · 1022 Bytes
/
MonthPicker.android.js
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
import moment from 'moment';
import invariant from 'invariant';
import RNMonthPickerDialogModule from './RNMonthPickerDialogModule';
import {
ACTION_DATE_SET,
ACTION_DISMISSED,
ACTION_NEUTRAL,
NATIVE_FORMAT,
} from './constants';
const MonthPicker = ({
value,
onChange,
minimumDate,
maximumDate,
...restProps
}) => {
invariant(value, 'value prop is required!');
RNMonthPickerDialogModule.open({
value: value.getTime(),
minimumDate: minimumDate?.getTime() ?? null,
maximumDate: maximumDate?.getTime() ?? null,
...restProps,
}).then(
({ action, year, month }) => {
let date;
switch (action) {
case ACTION_DATE_SET:
case ACTION_NEUTRAL:
date = moment(`${month}-${year}`, NATIVE_FORMAT).toDate();
break;
case ACTION_DISMISSED:
default:
date = undefined;
}
onChange && onChange(action, date);
},
error => {
throw error;
},
);
return null;
};
export default MonthPicker;