react-native-dates-picker 0.1.0 → 0.1.2
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/DateTimePicker.js +4 -4
- package/lib/commonjs/DateTimePicker.js.map +1 -1
- package/lib/commonjs/components/Calendar.js +1 -1
- package/lib/commonjs/components/Calendar.js.map +1 -1
- package/lib/commonjs/components/DatePicker.js +8 -26
- package/lib/commonjs/components/DatePicker.js.map +1 -1
- package/lib/commonjs/components/Day.js +1 -1
- package/lib/commonjs/components/Day.js.map +1 -1
- package/lib/commonjs/components/DaySelector.js +1 -1
- package/lib/commonjs/components/DaySelector.js.map +1 -1
- package/lib/commonjs/components/Header.js +1 -1
- package/lib/commonjs/components/Header.js.map +1 -1
- package/lib/commonjs/components/TimeSelector.js +1 -1
- package/lib/commonjs/components/TimeSelector.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/Wheel.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/WheelNative.js +0 -12
- package/lib/commonjs/components/WheelPicker/WheelNative.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +8 -2
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js +7 -2
- package/lib/commonjs/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -1
- package/lib/commonjs/components/WheelPicker/WheelWeb.js +11 -5
- package/lib/commonjs/components/WheelPicker/WheelWeb.js.map +1 -1
- package/lib/module/DateTimePicker.js +4 -4
- package/lib/module/DateTimePicker.js.map +1 -1
- package/lib/module/components/Calendar.js +1 -1
- package/lib/module/components/Calendar.js.map +1 -1
- package/lib/module/components/DatePicker.js +8 -26
- package/lib/module/components/DatePicker.js.map +1 -1
- package/lib/module/components/Day.js +1 -1
- package/lib/module/components/Day.js.map +1 -1
- package/lib/module/components/DaySelector.js +1 -1
- package/lib/module/components/DaySelector.js.map +1 -1
- package/lib/module/components/Header.js +1 -1
- package/lib/module/components/Header.js.map +1 -1
- package/lib/module/components/TimeSelector.js +1 -1
- package/lib/module/components/TimeSelector.js.map +1 -1
- package/lib/module/components/WheelPicker/Wheel.js.map +1 -1
- package/lib/module/components/WheelPicker/WheelNative.js +0 -12
- package/lib/module/components/WheelPicker/WheelNative.js.map +1 -1
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js +8 -2
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker-item.js.map +1 -1
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js +7 -2
- package/lib/module/components/WheelPicker/WheelNativePicker/wheel-picker.js.map +1 -1
- package/lib/module/components/WheelPicker/WheelWeb.js +11 -5
- package/lib/module/components/WheelPicker/WheelWeb.js.map +1 -1
- package/lib/typescript/DateTimePicker.d.ts +1 -1
- package/lib/typescript/DateTimePicker.d.ts.map +1 -1
- package/lib/typescript/components/Calendar.d.ts.map +1 -1
- package/lib/typescript/components/DatePicker.d.ts.map +1 -1
- package/lib/typescript/components/Day.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/Wheel.d.ts +0 -2
- package/lib/typescript/components/WheelPicker/Wheel.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/WheelNative.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts +1 -1
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker-item.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts +1 -2
- package/lib/typescript/components/WheelPicker/WheelNativePicker/wheel-picker.d.ts.map +1 -1
- package/lib/typescript/components/WheelPicker/WheelWeb.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +1 -2
- package/lib/typescript/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DateTimePicker.tsx +6 -6
- package/src/components/Calendar.tsx +1 -1
- package/src/components/DatePicker.tsx +2 -21
- package/src/components/Day.tsx +1 -1
- package/src/components/DaySelector.tsx +1 -1
- package/src/components/Header.tsx +1 -1
- package/src/components/TimeSelector.tsx +1 -1
- package/src/components/WheelPicker/Wheel.tsx +1 -2
- package/src/components/WheelPicker/WheelNative.tsx +0 -13
- package/src/components/WheelPicker/WheelNativePicker/wheel-picker-item.tsx +5 -2
- package/src/components/WheelPicker/WheelNativePicker/wheel-picker.tsx +9 -3
- package/src/components/WheelPicker/WheelWeb.tsx +12 -4
- package/src/types.ts +1 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useMemo } from 'react';
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
3
|
import { useCalendarContext } from '../CalendarContext';
|
|
4
|
-
import Wheel from './WheelPicker/Wheel';
|
|
5
4
|
import { CONTAINER_HEIGHT } from '../enums';
|
|
6
5
|
import {
|
|
7
6
|
getFormatted,
|
|
@@ -10,6 +9,7 @@ import {
|
|
|
10
9
|
getTimeRange,
|
|
11
10
|
getDate,
|
|
12
11
|
} from '../utils';
|
|
12
|
+
import Wheel from './WheelPicker/Wheel';
|
|
13
13
|
|
|
14
14
|
function createNumberList(start: number, end: number, first: number = 1) {
|
|
15
15
|
return new Array(end - start).fill(0).map((_, index) => ({
|
|
@@ -90,30 +90,16 @@ const DatePicker: React.FC = () => {
|
|
|
90
90
|
[currentDate, onSelectDate]
|
|
91
91
|
);
|
|
92
92
|
|
|
93
|
-
const createIndicatorStyle = useCallback(
|
|
94
|
-
(index: number) => {
|
|
95
|
-
const len = columns?.length || 0;
|
|
96
|
-
if (!index && len > 1)
|
|
97
|
-
return { borderTopRightRadius: 0, borderBottomRightRadius: 0 };
|
|
98
|
-
else if (index === len - 1 && len > 1)
|
|
99
|
-
return { borderTopLeftRadius: 0, borderBottomLeftRadius: 0 };
|
|
100
|
-
else if (len > 2) return { borderRadius: 0 };
|
|
101
|
-
else return undefined;
|
|
102
|
-
},
|
|
103
|
-
[columns]
|
|
104
|
-
);
|
|
105
|
-
|
|
106
93
|
return (
|
|
107
94
|
<View style={styles.container}>
|
|
108
95
|
<View style={styles.datePickerContainer}>
|
|
109
|
-
{columns?.map((item
|
|
96
|
+
{columns?.map((item) => (
|
|
110
97
|
<View style={styles.wheelContainer} key={item}>
|
|
111
98
|
{item === 'year' && (
|
|
112
99
|
<Wheel
|
|
113
100
|
value={year}
|
|
114
101
|
items={years}
|
|
115
102
|
setValue={(value) => onSelectYear(value)}
|
|
116
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
117
103
|
/>
|
|
118
104
|
)}
|
|
119
105
|
{item === 'month' && (
|
|
@@ -121,7 +107,6 @@ const DatePicker: React.FC = () => {
|
|
|
121
107
|
value={month + 1}
|
|
122
108
|
items={months}
|
|
123
109
|
setValue={(value) => onSelectMonth(value - 1)}
|
|
124
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
125
110
|
/>
|
|
126
111
|
)}
|
|
127
112
|
{item === 'day' && (
|
|
@@ -129,7 +114,6 @@ const DatePicker: React.FC = () => {
|
|
|
129
114
|
value={getDate(currentDate).date()}
|
|
130
115
|
items={days}
|
|
131
116
|
setValue={(value) => handleChangeDate(value, 'date')}
|
|
132
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
133
117
|
/>
|
|
134
118
|
)}
|
|
135
119
|
{item === 'hour' && (
|
|
@@ -137,7 +121,6 @@ const DatePicker: React.FC = () => {
|
|
|
137
121
|
value={hour}
|
|
138
122
|
items={hours}
|
|
139
123
|
setValue={(value) => handleChangeDate(value, 'hour')}
|
|
140
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
141
124
|
/>
|
|
142
125
|
)}
|
|
143
126
|
{item === 'minute' && (
|
|
@@ -145,7 +128,6 @@ const DatePicker: React.FC = () => {
|
|
|
145
128
|
value={minute}
|
|
146
129
|
items={minutes}
|
|
147
130
|
setValue={(value) => handleChangeDate(value, 'minute')}
|
|
148
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
149
131
|
/>
|
|
150
132
|
)}
|
|
151
133
|
{item === 'second' && (
|
|
@@ -153,7 +135,6 @@ const DatePicker: React.FC = () => {
|
|
|
153
135
|
value={second}
|
|
154
136
|
items={seconds}
|
|
155
137
|
setValue={(value) => handleChangeDate(value, 'second')}
|
|
156
|
-
indicatorStyle={createIndicatorStyle(index)}
|
|
157
138
|
/>
|
|
158
139
|
)}
|
|
159
140
|
</View>
|
package/src/components/Day.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { memo, useCallback } from 'react';
|
|
2
2
|
import { View, Text, Pressable, StyleSheet } from 'react-native';
|
|
3
|
+
import { isEqual } from 'lodash';
|
|
3
4
|
import { CalendarThemeProps, IDayObject } from '../types';
|
|
4
5
|
import { CONTAINER_HEIGHT } from '../enums';
|
|
5
6
|
import { addColorAlpha } from '../utils';
|
|
6
|
-
import { isEqual } from 'lodash';
|
|
7
7
|
|
|
8
8
|
export const daySize = 46;
|
|
9
9
|
|
|
@@ -2,7 +2,6 @@ import React, { useMemo, useCallback } from 'react';
|
|
|
2
2
|
import { Text, View, StyleSheet } from 'react-native';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import { useCalendarContext } from '../CalendarContext';
|
|
5
|
-
import Day, { EmptyDay } from './Day';
|
|
6
5
|
import {
|
|
7
6
|
getParsedDate,
|
|
8
7
|
getMonthDays,
|
|
@@ -13,6 +12,7 @@ import {
|
|
|
13
12
|
getDate,
|
|
14
13
|
getFormatted,
|
|
15
14
|
} from '../utils';
|
|
15
|
+
import Day, { EmptyDay } from './Day';
|
|
16
16
|
|
|
17
17
|
const DaySelector: React.FC = () => {
|
|
18
18
|
const {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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';
|
|
4
|
+
import { useCalendarContext } from '../CalendarContext';
|
|
5
5
|
import type { HeaderProps } from '../types';
|
|
6
6
|
import { getDateYear, getYearRange, YEAR_PAGE_SIZE } from '../utils';
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { Text, View, StyleSheet } from 'react-native';
|
|
3
3
|
import { useCalendarContext } from '../CalendarContext';
|
|
4
|
-
import Wheel from './WheelPicker/Wheel';
|
|
5
4
|
import { CONTAINER_HEIGHT } from '../enums';
|
|
6
5
|
import { getParsedDate, getDate, getFormatted } from '../utils';
|
|
6
|
+
import Wheel from './WheelPicker/Wheel';
|
|
7
7
|
|
|
8
8
|
function createNumberList(num: number) {
|
|
9
9
|
return new Array(num).fill(0).map((_, index) => ({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { memo } from 'react';
|
|
2
|
-
import { Platform
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
3
|
import WheelNative from './WheelNative';
|
|
4
4
|
import WheelWeb from './WheelWeb';
|
|
5
5
|
import { PickerOption } from '../../types';
|
|
@@ -8,7 +8,6 @@ interface WheelProps {
|
|
|
8
8
|
value: number;
|
|
9
9
|
setValue?: (value: number) => void;
|
|
10
10
|
items: Array<PickerOption>;
|
|
11
|
-
indicatorStyle?: ViewStyle;
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
const Wheel: React.FC<WheelProps> = (props) => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { memo } from 'react';
|
|
2
|
-
import { StyleSheet, Platform } from 'react-native';
|
|
3
2
|
import WheelPicker from './WheelNativePicker';
|
|
4
3
|
import { PickerOption } from '../../types';
|
|
5
4
|
|
|
@@ -19,7 +18,6 @@ const WheelNative: React.FC<WheelProps> = ({
|
|
|
19
18
|
value={value}
|
|
20
19
|
options={items}
|
|
21
20
|
onChange={setValue}
|
|
22
|
-
containerStyle={defaultStyles.container}
|
|
23
21
|
itemHeight={44}
|
|
24
22
|
decelerationRate="fast"
|
|
25
23
|
/>
|
|
@@ -27,14 +25,3 @@ const WheelNative: React.FC<WheelProps> = ({
|
|
|
27
25
|
};
|
|
28
26
|
|
|
29
27
|
export default memo(WheelNative);
|
|
30
|
-
|
|
31
|
-
const defaultStyles = StyleSheet.create({
|
|
32
|
-
container: {
|
|
33
|
-
display: 'flex',
|
|
34
|
-
...Platform.select({
|
|
35
|
-
web: {
|
|
36
|
-
userSelect: 'none',
|
|
37
|
-
},
|
|
38
|
-
}),
|
|
39
|
-
},
|
|
40
|
-
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { memo } from 'react';
|
|
2
2
|
import { Animated, Text, StyleSheet } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useCalendarContext } from '../../../CalendarContext';
|
|
4
|
+
import { PickerOption } from '../../../types';
|
|
4
5
|
|
|
5
6
|
interface ItemProps {
|
|
6
7
|
option: PickerOption | null;
|
|
@@ -23,6 +24,7 @@ const WheelPickerItem: React.FC<ItemProps> = ({
|
|
|
23
24
|
rotationFunction,
|
|
24
25
|
scaleFunction,
|
|
25
26
|
}) => {
|
|
27
|
+
const { theme } = useCalendarContext();
|
|
26
28
|
const relativeScrollIndex = Animated.subtract(index, currentScrollIndex);
|
|
27
29
|
|
|
28
30
|
const translateY = relativeScrollIndex.interpolate({
|
|
@@ -118,9 +120,10 @@ const WheelPickerItem: React.FC<ItemProps> = ({
|
|
|
118
120
|
opacity,
|
|
119
121
|
transform: [{ translateY }, { rotateX }, { scale }],
|
|
120
122
|
},
|
|
123
|
+
theme.wheelPickerItemStyle,
|
|
121
124
|
]}
|
|
122
125
|
>
|
|
123
|
-
<Text>{option?.text}</Text>
|
|
126
|
+
<Text style={theme.wheelPickerTextStyle}>{option?.text}</Text>
|
|
124
127
|
</Animated.View>
|
|
125
128
|
);
|
|
126
129
|
};
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
NativeSyntheticEvent,
|
|
4
4
|
NativeScrollEvent,
|
|
5
5
|
Animated,
|
|
6
|
-
ViewStyle,
|
|
7
6
|
View,
|
|
8
7
|
ViewProps,
|
|
9
8
|
FlatListProps,
|
|
@@ -13,13 +12,13 @@ import {
|
|
|
13
12
|
} from 'react-native';
|
|
14
13
|
import WheelPickerItem from './wheel-picker-item';
|
|
15
14
|
import { PickerOption } from '../../../types';
|
|
15
|
+
import { useCalendarContext } from '../../../CalendarContext';
|
|
16
16
|
|
|
17
17
|
interface Props {
|
|
18
18
|
value: number | string;
|
|
19
19
|
options: PickerOption[];
|
|
20
20
|
onChange: (index: number | string) => void;
|
|
21
21
|
itemHeight?: number;
|
|
22
|
-
containerStyle?: ViewStyle;
|
|
23
22
|
containerProps?: Omit<ViewProps, 'style'>;
|
|
24
23
|
scaleFunction?: (x: number) => number;
|
|
25
24
|
rotationFunction?: (x: number) => number;
|
|
@@ -42,6 +41,7 @@ const WheelPicker: React.FC<Props> = ({
|
|
|
42
41
|
containerProps = {},
|
|
43
42
|
flatListProps = {},
|
|
44
43
|
}) => {
|
|
44
|
+
const { theme } = useCalendarContext();
|
|
45
45
|
const momentumStarted = useRef(false);
|
|
46
46
|
const selectedIndex = options.findIndex((item) => item.value === value);
|
|
47
47
|
|
|
@@ -141,7 +141,11 @@ const WheelPicker: React.FC<Props> = ({
|
|
|
141
141
|
|
|
142
142
|
return (
|
|
143
143
|
<View
|
|
144
|
-
style={[
|
|
144
|
+
style={[
|
|
145
|
+
styles.container,
|
|
146
|
+
{ height: containerHeight },
|
|
147
|
+
theme.wheelPickerContainerStyle,
|
|
148
|
+
]}
|
|
145
149
|
{...containerProps}
|
|
146
150
|
>
|
|
147
151
|
<View
|
|
@@ -151,6 +155,7 @@ const WheelPicker: React.FC<Props> = ({
|
|
|
151
155
|
transform: [{ translateY: -itemHeight / 2 }],
|
|
152
156
|
height: itemHeight,
|
|
153
157
|
},
|
|
158
|
+
theme.wheelPickerSelectedIndicatorStyle,
|
|
154
159
|
]}
|
|
155
160
|
/>
|
|
156
161
|
<Animated.FlatList
|
|
@@ -198,6 +203,7 @@ const WheelPicker: React.FC<Props> = ({
|
|
|
198
203
|
|
|
199
204
|
const styles = StyleSheet.create({
|
|
200
205
|
container: {
|
|
206
|
+
display: 'flex',
|
|
201
207
|
position: 'relative',
|
|
202
208
|
},
|
|
203
209
|
selectedIndicator: {
|
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
Platform,
|
|
8
8
|
Text,
|
|
9
9
|
} from 'react-native';
|
|
10
|
-
import {
|
|
10
|
+
import { isEqual } from 'lodash';
|
|
11
11
|
import { CONTAINER_HEIGHT } from '../../enums';
|
|
12
12
|
import { PickerOption } from '../../types';
|
|
13
|
-
import {
|
|
13
|
+
import { useCalendarContext } from '../../CalendarContext';
|
|
14
|
+
import { sin } from './animated-math';
|
|
14
15
|
|
|
15
16
|
interface WheelProps {
|
|
16
17
|
value: number | string;
|
|
@@ -25,6 +26,7 @@ const WheelWeb: React.FC<WheelProps> = ({
|
|
|
25
26
|
setValue = () => {},
|
|
26
27
|
items,
|
|
27
28
|
}) => {
|
|
29
|
+
const { theme } = useCalendarContext();
|
|
28
30
|
const displayCount = 5;
|
|
29
31
|
const translateY = useRef(new Animated.Value(0)).current;
|
|
30
32
|
const renderCount =
|
|
@@ -120,7 +122,10 @@ const WheelWeb: React.FC<WheelProps> = ({
|
|
|
120
122
|
}, [displayValues, radius, value, displayCount, translateY]);
|
|
121
123
|
|
|
122
124
|
return (
|
|
123
|
-
<View
|
|
125
|
+
<View
|
|
126
|
+
style={[defaultStyles.container, theme.wheelPickerContainerStyle]}
|
|
127
|
+
{...panResponder.panHandlers}
|
|
128
|
+
>
|
|
124
129
|
<View
|
|
125
130
|
style={[
|
|
126
131
|
defaultStyles.selectedIndicator,
|
|
@@ -128,6 +133,7 @@ const WheelWeb: React.FC<WheelProps> = ({
|
|
|
128
133
|
transform: [{ translateY: -ITEM_HEIGHT / 2 }],
|
|
129
134
|
height: ITEM_HEIGHT,
|
|
130
135
|
},
|
|
136
|
+
theme.wheelPickerSelectedIndicatorStyle,
|
|
131
137
|
]}
|
|
132
138
|
/>
|
|
133
139
|
{displayValues?.map((displayValue, index) => {
|
|
@@ -156,7 +162,9 @@ const WheelWeb: React.FC<WheelProps> = ({
|
|
|
156
162
|
opacity: displayValue?.value !== value ? 0.3 : 1,
|
|
157
163
|
}}
|
|
158
164
|
>
|
|
159
|
-
<Text
|
|
165
|
+
<Text style={theme?.wheelPickerTextStyle}>
|
|
166
|
+
{displayValue?.text}
|
|
167
|
+
</Text>
|
|
160
168
|
</Animated.View>
|
|
161
169
|
);
|
|
162
170
|
})}
|
package/src/types.ts
CHANGED
|
@@ -47,8 +47,7 @@ export type CalendarThemeProps = {
|
|
|
47
47
|
wheelPickerContainerStyle?: ViewStyle;
|
|
48
48
|
wheelPickerItemStyle?: ViewStyle;
|
|
49
49
|
wheelPickerTextStyle?: TextStyle;
|
|
50
|
-
|
|
51
|
-
wheelPickerDecelerationRate?: 'normal' | 'fast' | number;
|
|
50
|
+
wheelPickerSelectedIndicatorStyle?: ViewStyle;
|
|
52
51
|
selectedRangeBackgroundColor?: string;
|
|
53
52
|
};
|
|
54
53
|
|