react-native-dates-picker 0.0.9 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -28
- package/lib/commonjs/CalendarContext.js.map +1 -1
- package/lib/commonjs/DateTimePicker.js +15 -8
- package/lib/commonjs/DateTimePicker.js.map +1 -1
- package/lib/commonjs/components/Calendar.js +14 -12
- package/lib/commonjs/components/Calendar.js.map +1 -1
- package/lib/commonjs/components/DatePicker.js +46 -58
- package/lib/commonjs/components/DatePicker.js.map +1 -1
- package/lib/commonjs/components/Day.js +18 -16
- package/lib/commonjs/components/Day.js.map +1 -1
- package/lib/commonjs/components/DaySelector.js +12 -12
- package/lib/commonjs/components/DaySelector.js.map +1 -1
- package/lib/commonjs/components/Header.js +27 -25
- package/lib/commonjs/components/Header.js.map +1 -1
- package/lib/commonjs/components/MonthSelector.js +9 -7
- package/lib/commonjs/components/MonthSelector.js.map +1 -1
- package/lib/commonjs/components/TimeSelector.js +22 -17
- package/lib/commonjs/components/TimeSelector.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/Wheel.js +9 -4
- package/lib/commonjs/components/WheelPicker/Wheel.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/WheelNative.js +14 -47
- package/lib/commonjs/components/WheelPicker/WheelNative.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/index.js +10 -0
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/index.js.map +1 -0
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +130 -0
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -0
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js +174 -0
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -0
- package/lib/commonjs/components/WheelPicker/WheelWeb.js +51 -38
- package/lib/commonjs/components/WheelPicker/WheelWeb.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/animated-math.js +26 -0
- package/lib/commonjs/components/WheelPicker/animated-math.js.map +1 -0
- package/lib/commonjs/components/WheelPicker/period-native.js +36 -0
- package/lib/commonjs/components/WheelPicker/period-native.js.map +1 -0
- package/lib/commonjs/components/WheelPicker/period-picker.js +19 -0
- package/lib/commonjs/components/WheelPicker/period-picker.js.map +1 -0
- package/lib/commonjs/components/WheelPicker/period-web.js +34 -0
- package/lib/commonjs/components/WheelPicker/period-web.js.map +1 -0
- package/lib/commonjs/components/YearSelector.js +10 -8
- package/lib/commonjs/components/YearSelector.js.map +1 -1
- package/lib/commonjs/enums.js +5 -4
- package/lib/commonjs/enums.js.map +1 -1
- package/lib/commonjs/utils.js +4 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/CalendarContext.js.map +1 -1
- package/lib/module/DateTimePicker.js +11 -6
- package/lib/module/DateTimePicker.js.map +1 -1
- package/lib/module/components/Calendar.js +4 -4
- package/lib/module/components/Calendar.js.map +1 -1
- package/lib/module/components/DatePicker.js +36 -50
- package/lib/module/components/DatePicker.js.map +1 -1
- package/lib/module/components/Day.js +8 -8
- package/lib/module/components/Day.js.map +1 -1
- package/lib/module/components/DaySelector.js +4 -4
- package/lib/module/components/DaySelector.js.map +1 -1
- package/lib/module/components/Header.js +3 -3
- package/lib/module/components/Header.js.map +1 -1
- package/lib/module/components/MonthSelector.js +3 -2
- package/lib/module/components/MonthSelector.js.map +1 -1
- package/lib/module/components/TimeSelector.js +10 -7
- package/lib/module/components/TimeSelector.js.map +1 -1
- package/lib/module/components/WheelPicker/Wheel.js +6 -3
- package/lib/module/components/WheelPicker/Wheel.js.map +1 -1
- package/lib/module/components/WheelPicker/WheelNative.js +10 -45
- package/lib/module/components/WheelPicker/WheelNative.js.map +1 -1
- package/lib/module/components/WheelPicker/WheelNativePicker/index.js +3 -0
- package/lib/module/components/WheelPicker/WheelNativePicker/index.js.map +1 -0
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +122 -0
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -0
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js +165 -0
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -0
- package/lib/module/components/WheelPicker/WheelWeb.js +48 -37
- package/lib/module/components/WheelPicker/WheelWeb.js.map +1 -1
- package/lib/module/components/WheelPicker/animated-math.js +20 -0
- package/lib/module/components/WheelPicker/animated-math.js.map +1 -0
- package/lib/module/components/WheelPicker/period-native.js +27 -0
- package/lib/module/components/WheelPicker/period-native.js.map +1 -0
- package/lib/module/components/WheelPicker/period-picker.js +10 -0
- package/lib/module/components/WheelPicker/period-picker.js.map +1 -0
- package/lib/module/components/WheelPicker/period-web.js +26 -0
- package/lib/module/components/WheelPicker/period-web.js.map +1 -0
- package/lib/module/components/YearSelector.js +3 -3
- package/lib/module/components/YearSelector.js.map +1 -1
- package/lib/module/enums.js +4 -3
- package/lib/module/enums.js.map +1 -1
- package/lib/module/utils.js +4 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/CalendarContext.d.ts.map +1 -1
- package/lib/typescript/DateTimePicker.d.ts +3 -3
- package/lib/typescript/DateTimePicker.d.ts.map +1 -1
- package/lib/typescript/components/Calendar.d.ts +3 -3
- package/lib/typescript/components/Calendar.d.ts.map +1 -1
- package/lib/typescript/components/DatePicker.d.ts +2 -2
- package/lib/typescript/components/DatePicker.d.ts.map +1 -1
- package/lib/typescript/components/Day.d.ts +4 -5
- package/lib/typescript/components/Day.d.ts.map +1 -1
- package/lib/typescript/components/DaySelector.d.ts +2 -2
- package/lib/typescript/components/DaySelector.d.ts.map +1 -1
- package/lib/typescript/components/Header.d.ts +3 -3
- package/lib/typescript/components/Header.d.ts.map +1 -1
- package/lib/typescript/components/MonthSelector.d.ts +2 -2
- package/lib/typescript/components/MonthSelector.d.ts.map +1 -1
- package/lib/typescript/components/TimeSelector.d.ts +2 -2
- package/lib/typescript/components/TimeSelector.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/Wheel.d.ts +5 -6
- package/lib/typescript/components/WheelPicker/Wheel.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/WheelNative.d.ts +7 -8
- package/lib/typescript/components/WheelPicker/WheelNative.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/WheelNativePicker/index.d.ts +3 -0
- package/lib/typescript/components/WheelPicker/WheelNativePicker/index.d.ts.map +1 -0
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts +16 -0
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts.map +1 -0
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts +19 -0
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts.map +1 -0
- package/lib/typescript/components/WheelPicker/WheelWeb.d.ts +6 -5
- package/lib/typescript/components/WheelPicker/WheelWeb.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/animated-math.d.ts +5 -0
- package/lib/typescript/components/WheelPicker/animated-math.d.ts.map +1 -0
- package/lib/typescript/components/WheelPicker/period-native.d.ts +8 -0
- package/lib/typescript/components/WheelPicker/period-native.d.ts.map +1 -0
- package/lib/typescript/components/WheelPicker/period-picker.d.ts +8 -0
- package/lib/typescript/components/WheelPicker/period-picker.d.ts.map +1 -0
- package/lib/typescript/components/WheelPicker/period-web.d.ts +8 -0
- package/lib/typescript/components/WheelPicker/period-web.d.ts.map +1 -0
- package/lib/typescript/components/YearSelector.d.ts +2 -2
- package/lib/typescript/components/YearSelector.d.ts.map +1 -1
- package/lib/typescript/enums.d.ts +2 -1
- package/lib/typescript/enums.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +5 -2
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils.d.ts +2 -2
- package/lib/typescript/utils.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/DateTimePicker.tsx +20 -15
- package/src/components/Calendar.tsx +8 -8
- package/src/components/DatePicker.tsx +38 -66
- package/src/components/Day.tsx +9 -9
- package/src/components/DaySelector.tsx +6 -6
- package/src/components/Header.tsx +5 -5
- package/src/components/MonthSelector.tsx +4 -3
- package/src/components/TimeSelector.tsx +11 -12
- package/src/components/WheelPicker/Wheel.tsx +10 -10
- package/src/components/WheelPicker/WheelNative.tsx +13 -47
- package/src/components/WheelPicker/WheelNativePicker/index.ts +3 -0
- package/src/components/WheelPicker/WheelNativePicker/wheel-picker-item.tsx +140 -0
- package/src/components/WheelPicker/WheelNativePicker/wheel-picker.tsx +220 -0
- package/src/components/WheelPicker/WheelWeb.tsx +92 -65
- package/src/components/WheelPicker/animated-math.ts +33 -0
- package/src/components/WheelPicker/period-native.tsx +39 -0
- package/src/components/WheelPicker/period-picker.tsx +16 -0
- package/src/components/WheelPicker/period-web.tsx +37 -0
- package/src/components/YearSelector.tsx +4 -4
- package/src/enums.ts +4 -3
- package/src/types.ts +6 -2
- package/src/utils.ts +3 -3
- /package/src/{CalendarContext.tsx → CalendarContext.ts} +0 -0
package/src/DateTimePicker.tsx
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { memo, useCallback, useEffect, useReducer } from 'react';
|
|
1
|
+
import React, { memo, useCallback, useEffect, useReducer } from 'react';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import utc from 'dayjs/plugin/utc';
|
|
4
|
+
import localeData from 'dayjs/plugin/localeData';
|
|
5
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
6
|
+
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
7
|
+
import 'dayjs/locale/zh-cn';
|
|
2
8
|
import {
|
|
3
9
|
getFormatted,
|
|
4
10
|
getDate,
|
|
@@ -21,12 +27,6 @@ import type {
|
|
|
21
27
|
MultiChange,
|
|
22
28
|
} from './types';
|
|
23
29
|
import Calendar from './components/Calendar';
|
|
24
|
-
import dayjs from 'dayjs';
|
|
25
|
-
import utc from 'dayjs/plugin/utc';
|
|
26
|
-
import localeData from 'dayjs/plugin/localeData';
|
|
27
|
-
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
28
|
-
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
29
|
-
import 'dayjs/locale/zh-cn';
|
|
30
30
|
|
|
31
31
|
dayjs.extend(utc);
|
|
32
32
|
dayjs.extend(localeData);
|
|
@@ -73,13 +73,12 @@ export interface DatePickerWheelProps
|
|
|
73
73
|
onChange?: SingleChange;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
const DateTimePicker
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
) => {
|
|
76
|
+
const DateTimePicker: React.FC<
|
|
77
|
+
| DatePickerSingleProps
|
|
78
|
+
| DatePickerRangeProps
|
|
79
|
+
| DatePickerMultipleProps
|
|
80
|
+
| DatePickerWheelProps
|
|
81
|
+
> = (props) => {
|
|
83
82
|
const {
|
|
84
83
|
mode = 'single',
|
|
85
84
|
locale = 'zh-cn',
|
|
@@ -121,6 +120,7 @@ const DateTimePicker = (
|
|
|
121
120
|
currentDate = dayjs(dates[0]);
|
|
122
121
|
|
|
123
122
|
if (minDate && currentDate.isBefore(minDate)) currentDate = dayjs(minDate);
|
|
123
|
+
if (maxDate && currentDate.isAfter(maxDate)) currentDate = dayjs(maxDate);
|
|
124
124
|
|
|
125
125
|
let currentYear = currentDate.year();
|
|
126
126
|
|
|
@@ -201,7 +201,12 @@ const DateTimePicker = (
|
|
|
201
201
|
type: CalendarActionKind.CHANGE_SELECTED_DATE,
|
|
202
202
|
payload: { date },
|
|
203
203
|
});
|
|
204
|
-
|
|
204
|
+
|
|
205
|
+
dispatch({
|
|
206
|
+
type: CalendarActionKind.CHANGE_CURRENT_DATE,
|
|
207
|
+
payload: currentDate,
|
|
208
|
+
});
|
|
209
|
+
}, [mode, date, startDate, endDate, dates, minDate, timePicker, currentDate]);
|
|
205
210
|
|
|
206
211
|
const setCalendarView = useCallback((view: CalendarViews) => {
|
|
207
212
|
dispatch({ type: CalendarActionKind.SET_CALENDAR_VIEW, payload: view });
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ReactNode, memo } from 'react';
|
|
1
|
+
import React, { ReactNode, memo } from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import type {
|
|
3
|
+
import { CONTAINER_HEIGHT } from 'src/enums';
|
|
4
|
+
import { useCalendarContext } from 'src/CalendarContext';
|
|
5
|
+
import type { CalendarViews } from 'src/enums';
|
|
6
|
+
import type { HeaderProps, CalendarThemeProps } from 'src/types';
|
|
6
7
|
import Header from './Header';
|
|
7
8
|
import YearSelector from './YearSelector';
|
|
8
9
|
import MonthSelector from './MonthSelector';
|
|
9
10
|
import DaySelector from './DaySelector';
|
|
10
11
|
import TimeSelector from './TimeSelector';
|
|
11
12
|
import DatePicker from './DatePicker';
|
|
12
|
-
import { CALENDAR_HEIGHT } from '../enums';
|
|
13
13
|
|
|
14
14
|
const CalendarView: Record<CalendarViews, ReactNode> = {
|
|
15
15
|
year: <YearSelector />,
|
|
@@ -23,12 +23,12 @@ interface PropTypes extends HeaderProps {
|
|
|
23
23
|
containerStyle?: CalendarThemeProps['containerStyle'];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const Calendar = ({
|
|
26
|
+
const Calendar: React.FC<PropTypes> = ({
|
|
27
27
|
buttonPrevIcon,
|
|
28
28
|
buttonNextIcon,
|
|
29
29
|
height,
|
|
30
30
|
containerStyle,
|
|
31
|
-
}
|
|
31
|
+
}) => {
|
|
32
32
|
const { calendarView, mode } = useCalendarContext();
|
|
33
33
|
|
|
34
34
|
const styles = StyleSheet.create({
|
|
@@ -36,7 +36,7 @@ const Calendar = ({
|
|
|
36
36
|
width: '100%',
|
|
37
37
|
},
|
|
38
38
|
calendarContainer: {
|
|
39
|
-
height: height ||
|
|
39
|
+
height: height || CONTAINER_HEIGHT,
|
|
40
40
|
alignItems: 'center',
|
|
41
41
|
},
|
|
42
42
|
});
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
1
|
+
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
|
-
import { useCalendarContext } from '
|
|
4
|
-
import
|
|
5
|
-
import { CALENDAR_HEIGHT } from '../enums';
|
|
3
|
+
import { useCalendarContext } from 'src/CalendarContext';
|
|
4
|
+
import { CONTAINER_HEIGHT } from 'src/enums';
|
|
6
5
|
import {
|
|
7
6
|
getFormatted,
|
|
8
7
|
getParsedDate,
|
|
9
8
|
getDaysNumInMonth,
|
|
10
9
|
getTimeRange,
|
|
11
10
|
getDate,
|
|
12
|
-
} from '
|
|
11
|
+
} from 'src/utils';
|
|
12
|
+
import Wheel from './WheelPicker/Wheel';
|
|
13
13
|
|
|
14
|
-
function createNumberList(start: number, end: number) {
|
|
15
|
-
return new Array(end - start)
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
function createNumberList(start: number, end: number, first: number = 1) {
|
|
15
|
+
return new Array(end - start).fill(0).map((_, index) => ({
|
|
16
|
+
value: index + first + start,
|
|
17
|
+
text: String(index + first + start).padStart(2, '0'),
|
|
18
|
+
}));
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
const DatePicker = () => {
|
|
21
|
+
const DatePicker: React.FC = () => {
|
|
21
22
|
const {
|
|
22
23
|
columns,
|
|
23
24
|
currentDate,
|
|
@@ -41,6 +42,7 @@ const DatePicker = () => {
|
|
|
41
42
|
|
|
42
43
|
const { year: startYear, month: startMonth } = getParsedDate(minDate);
|
|
43
44
|
const { year: endYear, month: endMonth } = getParsedDate(maxDate);
|
|
45
|
+
const { hour, minute, second } = getParsedDate(currentDate);
|
|
44
46
|
const years = createNumberList(startYear - 1, endYear);
|
|
45
47
|
const months = useMemo(
|
|
46
48
|
() =>
|
|
@@ -57,114 +59,82 @@ const DatePicker = () => {
|
|
|
57
59
|
);
|
|
58
60
|
const hours = useMemo(
|
|
59
61
|
() =>
|
|
60
|
-
createNumberList(
|
|
62
|
+
createNumberList(
|
|
63
|
+
...getTimeRange(currentDate, minDate, maxDate, 'hour'),
|
|
64
|
+
0
|
|
65
|
+
),
|
|
61
66
|
[currentDate, maxDate, minDate]
|
|
62
67
|
);
|
|
63
68
|
const minutes = useMemo(
|
|
64
69
|
() =>
|
|
65
70
|
createNumberList(
|
|
66
|
-
...getTimeRange(currentDate, minDate, maxDate, 'minute')
|
|
71
|
+
...getTimeRange(currentDate, minDate, maxDate, 'minute'),
|
|
72
|
+
0
|
|
67
73
|
),
|
|
68
74
|
[currentDate, maxDate, minDate]
|
|
69
75
|
);
|
|
70
76
|
const seconds = useMemo(
|
|
71
77
|
() =>
|
|
72
78
|
createNumberList(
|
|
73
|
-
...getTimeRange(currentDate, minDate, maxDate, 'second')
|
|
79
|
+
...getTimeRange(currentDate, minDate, maxDate, 'second'),
|
|
80
|
+
0
|
|
74
81
|
),
|
|
75
82
|
[currentDate, maxDate, minDate]
|
|
76
83
|
);
|
|
77
84
|
|
|
78
85
|
const handleChangeDate = useCallback(
|
|
79
|
-
(
|
|
80
|
-
|
|
81
|
-
data: Array<string>,
|
|
82
|
-
type: 'date' | 'hour' | 'minute' | 'second'
|
|
83
|
-
) => {
|
|
84
|
-
const newDate = getDate(currentDate)[type](Number(data[value]));
|
|
86
|
+
(value: number, type: 'date' | 'hour' | 'minute' | 'second') => {
|
|
87
|
+
const newDate = getDate(currentDate).set(type, value);
|
|
85
88
|
onSelectDate(getFormatted(newDate));
|
|
86
89
|
},
|
|
87
90
|
[currentDate, onSelectDate]
|
|
88
91
|
);
|
|
89
92
|
|
|
90
|
-
const createIndicatorStyle = useCallback(
|
|
91
|
-
(index: number) => {
|
|
92
|
-
const len = columns?.length || 0;
|
|
93
|
-
if (!index && len > 1)
|
|
94
|
-
return { borderTopRightRadius: 0, borderBottomRightRadius: 0 };
|
|
95
|
-
else if (index === len - 1 && len > 1)
|
|
96
|
-
return { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 };
|
|
97
|
-
else if (len > 2) return { borderRadius: 0 };
|
|
98
|
-
else return undefined;
|
|
99
|
-
},
|
|
100
|
-
[columns]
|
|
101
|
-
);
|
|
102
|
-
|
|
103
93
|
return (
|
|
104
94
|
<View style={styles.container}>
|
|
105
95
|
<View style={styles.datePickerContainer}>
|
|
106
|
-
{columns?.map((item
|
|
96
|
+
{columns?.map((item) => (
|
|
107
97
|
<View style={styles.wheelContainer} key={item}>
|
|
108
98
|
{item === 'year' && (
|
|
109
99
|
<Wheel
|
|
110
|
-
value={
|
|
100
|
+
value={year}
|
|
111
101
|
items={years}
|
|
112
|
-
|
|
113
|
-
setValue={(value) => onSelectYear(Number(years[value]))}
|
|
114
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
102
|
+
setValue={(value) => onSelectYear(value)}
|
|
115
103
|
/>
|
|
116
104
|
)}
|
|
117
105
|
{item === 'month' && (
|
|
118
106
|
<Wheel
|
|
119
|
-
value={
|
|
107
|
+
value={month + 1}
|
|
120
108
|
items={months}
|
|
121
|
-
|
|
122
|
-
setValue={(value) => onSelectMonth(Number(months[value]) - 1)}
|
|
123
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
109
|
+
setValue={(value) => onSelectMonth(value - 1)}
|
|
124
110
|
/>
|
|
125
111
|
)}
|
|
126
112
|
{item === 'day' && (
|
|
127
113
|
<Wheel
|
|
128
|
-
value={
|
|
129
|
-
String(getDate(currentDate).date()).padStart(2, '0')
|
|
130
|
-
)}
|
|
131
|
-
key={days.length}
|
|
114
|
+
value={getDate(currentDate).date()}
|
|
132
115
|
items={days}
|
|
133
|
-
setValue={(value) => handleChangeDate(value,
|
|
134
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
116
|
+
setValue={(value) => handleChangeDate(value, 'date')}
|
|
135
117
|
/>
|
|
136
118
|
)}
|
|
137
119
|
{item === 'hour' && (
|
|
138
120
|
<Wheel
|
|
139
|
-
value={
|
|
140
|
-
String(getDate(currentDate).hour()).padStart(2, '0')
|
|
141
|
-
)}
|
|
142
|
-
key={hours.length}
|
|
121
|
+
value={hour}
|
|
143
122
|
items={hours}
|
|
144
|
-
setValue={(value) => handleChangeDate(value,
|
|
145
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
123
|
+
setValue={(value) => handleChangeDate(value, 'hour')}
|
|
146
124
|
/>
|
|
147
125
|
)}
|
|
148
126
|
{item === 'minute' && (
|
|
149
127
|
<Wheel
|
|
150
|
-
value={
|
|
151
|
-
String(getDate(currentDate).minute()).padStart(2, '0')
|
|
152
|
-
)}
|
|
153
|
-
key={minutes.length}
|
|
128
|
+
value={minute}
|
|
154
129
|
items={minutes}
|
|
155
|
-
setValue={(value) => handleChangeDate(value,
|
|
156
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
130
|
+
setValue={(value) => handleChangeDate(value, 'minute')}
|
|
157
131
|
/>
|
|
158
132
|
)}
|
|
159
133
|
{item === 'second' && (
|
|
160
134
|
<Wheel
|
|
161
|
-
value={
|
|
162
|
-
String(getDate(currentDate).second()).padStart(2, '0')
|
|
163
|
-
)}
|
|
164
|
-
key={seconds.length}
|
|
135
|
+
value={second}
|
|
165
136
|
items={seconds}
|
|
166
|
-
setValue={(value) => handleChangeDate(value,
|
|
167
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
137
|
+
setValue={(value) => handleChangeDate(value, 'second')}
|
|
168
138
|
/>
|
|
169
139
|
)}
|
|
170
140
|
</View>
|
|
@@ -179,16 +149,18 @@ const styles = StyleSheet.create({
|
|
|
179
149
|
flex: 1,
|
|
180
150
|
alignItems: 'center',
|
|
181
151
|
justifyContent: 'center',
|
|
152
|
+
width: '100%',
|
|
182
153
|
},
|
|
183
154
|
wheelContainer: {
|
|
184
155
|
flex: 1,
|
|
185
156
|
},
|
|
186
157
|
datePickerContainer: {
|
|
158
|
+
width: '100%',
|
|
187
159
|
flexDirection: 'row',
|
|
188
160
|
alignItems: 'center',
|
|
189
161
|
justifyContent: 'center',
|
|
190
162
|
paddingHorizontal: 16,
|
|
191
|
-
height:
|
|
163
|
+
height: CONTAINER_HEIGHT / 2,
|
|
192
164
|
},
|
|
193
165
|
});
|
|
194
166
|
|
package/src/components/Day.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { memo, useCallback } from 'react';
|
|
1
|
+
import React, { memo, useCallback } from 'react';
|
|
2
2
|
import { View, Text, Pressable, StyleSheet } from 'react-native';
|
|
3
|
-
import { CalendarThemeProps, IDayObject } from '../types';
|
|
4
|
-
import { CALENDAR_HEIGHT } from '../enums';
|
|
5
|
-
import { addColorAlpha } from '../utils';
|
|
6
3
|
import { isEqual } from 'lodash';
|
|
4
|
+
import { CalendarThemeProps, IDayObject } from 'src/types';
|
|
5
|
+
import { CONTAINER_HEIGHT } from 'src/enums';
|
|
6
|
+
import { addColorAlpha } from 'src/utils';
|
|
7
7
|
|
|
8
8
|
export const daySize = 46;
|
|
9
9
|
|
|
@@ -16,13 +16,13 @@ interface Props extends Omit<IDayObject, 'day'> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function EmptyDayPure({ height }: { height?: number }) {
|
|
19
|
-
const style = styles(height ||
|
|
19
|
+
const style = styles(height || CONTAINER_HEIGHT);
|
|
20
20
|
return <View style={style.dayCell} />;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export const EmptyDay = memo(EmptyDayPure);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const Day: React.FC<Props> = ({
|
|
26
26
|
date,
|
|
27
27
|
text,
|
|
28
28
|
disabled,
|
|
@@ -35,7 +35,7 @@ function Day({
|
|
|
35
35
|
onSelectDate,
|
|
36
36
|
theme,
|
|
37
37
|
height,
|
|
38
|
-
}
|
|
38
|
+
}) => {
|
|
39
39
|
const onPress = useCallback(() => {
|
|
40
40
|
onSelectDate(date);
|
|
41
41
|
}, [onSelectDate, date]);
|
|
@@ -83,7 +83,7 @@ function Day({
|
|
|
83
83
|
const rangeRootBackground =
|
|
84
84
|
selectedRangeBackgroundColor ?? addColorAlpha(selectedItemColor, 0.15);
|
|
85
85
|
|
|
86
|
-
const style = styles(height ||
|
|
86
|
+
const style = styles(height || CONTAINER_HEIGHT);
|
|
87
87
|
|
|
88
88
|
return (
|
|
89
89
|
<View style={style.dayCell}>
|
|
@@ -138,7 +138,7 @@ function Day({
|
|
|
138
138
|
</Pressable>
|
|
139
139
|
</View>
|
|
140
140
|
);
|
|
141
|
-
}
|
|
141
|
+
};
|
|
142
142
|
|
|
143
143
|
const styles = (height: number) =>
|
|
144
144
|
StyleSheet.create({
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { useMemo, useCallback } from 'react';
|
|
1
|
+
import React, { useMemo, useCallback } from 'react';
|
|
2
2
|
import { Text, View, StyleSheet } from 'react-native';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
|
-
import { useCalendarContext } from '
|
|
5
|
-
import Day, { EmptyDay } from './Day';
|
|
4
|
+
import { useCalendarContext } from 'src/CalendarContext';
|
|
6
5
|
import {
|
|
7
6
|
getParsedDate,
|
|
8
7
|
getMonthDays,
|
|
@@ -12,9 +11,10 @@ import {
|
|
|
12
11
|
isDateBetween,
|
|
13
12
|
getDate,
|
|
14
13
|
getFormatted,
|
|
15
|
-
} from '
|
|
14
|
+
} from 'src/utils';
|
|
15
|
+
import Day, { EmptyDay } from './Day';
|
|
16
16
|
|
|
17
|
-
const DaySelector = () => {
|
|
17
|
+
const DaySelector: React.FC = () => {
|
|
18
18
|
const {
|
|
19
19
|
mode,
|
|
20
20
|
date,
|
|
@@ -117,7 +117,7 @@ const DaySelector = () => {
|
|
|
117
117
|
if (inRange && !leftCrop && !rightCrop) isSelected = false;
|
|
118
118
|
}
|
|
119
119
|
} else if (mode === 'single')
|
|
120
|
-
isSelected = areDatesOnSameDay(day.date,
|
|
120
|
+
isSelected = areDatesOnSameDay(day.date, date);
|
|
121
121
|
|
|
122
122
|
return {
|
|
123
123
|
...day,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { View, Text, Pressable, StyleSheet, Image } from 'react-native';
|
|
3
|
-
import { useCalendarContext } from '../CalendarContext';
|
|
4
3
|
import dayjs from 'dayjs';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
4
|
+
import { useCalendarContext } from 'src/CalendarContext';
|
|
5
|
+
import type { HeaderProps } from 'src/types';
|
|
6
|
+
import { getDateYear, getYearRange, YEAR_PAGE_SIZE } from 'src/utils';
|
|
7
7
|
|
|
8
|
-
const Header = ({ buttonPrevIcon, buttonNextIcon }
|
|
8
|
+
const Header: React.FC<HeaderProps> = ({ buttonPrevIcon, buttonNextIcon }) => {
|
|
9
9
|
const {
|
|
10
10
|
mode,
|
|
11
11
|
date,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import { Text, View, Pressable, StyleSheet } from 'react-native';
|
|
2
|
-
import { useCalendarContext } from '
|
|
3
|
-
import { getParsedDate, getMonths } from '
|
|
3
|
+
import { useCalendarContext } from 'src/CalendarContext';
|
|
4
|
+
import { getParsedDate, getMonths } from 'src/utils';
|
|
4
5
|
|
|
5
|
-
const MonthSelector = () => {
|
|
6
|
+
const MonthSelector: React.FC = () => {
|
|
6
7
|
const { currentDate, onSelectMonth, theme } = useCalendarContext();
|
|
7
8
|
const { month } = getParsedDate(currentDate);
|
|
8
9
|
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
2
|
import { Text, View, StyleSheet } from 'react-native';
|
|
3
|
-
import { useCalendarContext } from '
|
|
3
|
+
import { useCalendarContext } from 'src/CalendarContext';
|
|
4
|
+
import { CONTAINER_HEIGHT } from 'src/enums';
|
|
5
|
+
import { getParsedDate, getDate, getFormatted } from 'src/utils';
|
|
4
6
|
import Wheel from './WheelPicker/Wheel';
|
|
5
|
-
import { CALENDAR_HEIGHT } from '../enums';
|
|
6
|
-
import { getParsedDate, getDate, getFormatted } from '../utils';
|
|
7
7
|
|
|
8
8
|
function createNumberList(num: number) {
|
|
9
|
-
return new Array(num)
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
9
|
+
return new Array(num).fill(0).map((_, index) => ({
|
|
10
|
+
text: index.toString().padStart(2, '0'),
|
|
11
|
+
value: index,
|
|
12
|
+
}));
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
const hours = createNumberList(24);
|
|
17
16
|
const minutes = createNumberList(60);
|
|
18
17
|
const seconds = createNumberList(60);
|
|
19
18
|
|
|
20
|
-
const TimeSelector = () => {
|
|
19
|
+
const TimeSelector: React.FC = () => {
|
|
21
20
|
const { date, onSelectDate, theme } = useCalendarContext();
|
|
22
21
|
const { hour, minute, second } = getParsedDate(date);
|
|
23
22
|
|
|
@@ -87,8 +86,8 @@ const styles = StyleSheet.create({
|
|
|
87
86
|
flexDirection: 'row',
|
|
88
87
|
alignItems: 'center',
|
|
89
88
|
justifyContent: 'center',
|
|
90
|
-
width:
|
|
91
|
-
height:
|
|
89
|
+
width: CONTAINER_HEIGHT / 2,
|
|
90
|
+
height: CONTAINER_HEIGHT / 2,
|
|
92
91
|
},
|
|
93
92
|
timePickerText: {
|
|
94
93
|
fontSize: 24,
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
2
3
|
import WheelNative from './WheelNative';
|
|
3
4
|
import WheelWeb from './WheelWeb';
|
|
5
|
+
import { PickerOption } from 'src/types';
|
|
4
6
|
|
|
5
7
|
interface WheelProps {
|
|
6
8
|
value: number;
|
|
7
9
|
setValue?: (value: number) => void;
|
|
8
|
-
items:
|
|
9
|
-
indicatorStyle?: ViewStyle;
|
|
10
|
+
items: Array<PickerOption>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
13
|
+
const Wheel: React.FC<WheelProps> = (props) => {
|
|
14
|
+
const Component = Platform.OS === 'web' ? WheelWeb : WheelNative;
|
|
15
|
+
return <Component {...props} />;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default memo(Wheel);
|
|
@@ -1,61 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import WheelPicker from '
|
|
3
|
-
import {
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import WheelPicker from './WheelNativePicker';
|
|
3
|
+
import { PickerOption } from 'src/types';
|
|
4
4
|
|
|
5
5
|
interface WheelProps {
|
|
6
|
-
value: number;
|
|
7
|
-
setValue?: (value:
|
|
8
|
-
items:
|
|
9
|
-
indicatorStyle?: ViewStyle;
|
|
6
|
+
value: number | string;
|
|
7
|
+
setValue?: (value: any) => void;
|
|
8
|
+
items: PickerOption[];
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
const WheelNative: React.FC<WheelProps> = ({
|
|
13
12
|
value,
|
|
14
13
|
setValue = () => {},
|
|
15
14
|
items,
|
|
16
|
-
|
|
17
|
-
}: WheelProps) {
|
|
18
|
-
const { theme } = useCalendarContext();
|
|
19
|
-
|
|
15
|
+
}) => {
|
|
20
16
|
return (
|
|
21
17
|
<WheelPicker
|
|
22
|
-
|
|
18
|
+
value={value}
|
|
23
19
|
options={items}
|
|
24
20
|
onChange={setValue}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...theme?.wheelPickerContainerStyle,
|
|
28
|
-
}}
|
|
29
|
-
itemStyle={theme?.wheelPickerItemStyle}
|
|
30
|
-
itemTextStyle={{
|
|
31
|
-
...styles.wheelPickerText,
|
|
32
|
-
...theme?.wheelPickerTextStyle,
|
|
33
|
-
}}
|
|
34
|
-
selectedIndicatorStyle={{
|
|
35
|
-
...styles.wheelSelectedIndicator,
|
|
36
|
-
...indicatorStyle,
|
|
37
|
-
...theme?.wheelPickerIndicatorStyle,
|
|
38
|
-
}}
|
|
39
|
-
itemHeight={45}
|
|
40
|
-
decelerationRate={theme?.wheelPickerDecelerationRate}
|
|
21
|
+
itemHeight={44}
|
|
22
|
+
decelerationRate="fast"
|
|
41
23
|
/>
|
|
42
24
|
);
|
|
43
|
-
}
|
|
25
|
+
};
|
|
44
26
|
|
|
45
|
-
|
|
46
|
-
container: {
|
|
47
|
-
display: 'flex',
|
|
48
|
-
...Platform.select({
|
|
49
|
-
web: {
|
|
50
|
-
userSelect: 'none',
|
|
51
|
-
},
|
|
52
|
-
}),
|
|
53
|
-
},
|
|
54
|
-
wheelSelectedIndicator: {
|
|
55
|
-
borderRadius: 10,
|
|
56
|
-
},
|
|
57
|
-
wheelPickerText: {
|
|
58
|
-
fontSize: 18,
|
|
59
|
-
fontWeight: '500',
|
|
60
|
-
},
|
|
61
|
-
});
|
|
27
|
+
export default memo(WheelNative);
|