@momo-kits/date-picker 0.150.2-beta.3 → 0.150.2-beta.30
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/WheelPicker.tsx +13 -11
- package/WheelPickerItem.tsx +11 -9
- package/index.tsx +16 -28
- package/package.json +1 -1
- package/styles.ts +3 -4
- package/utils.ts +1 -3
package/WheelPicker.tsx
CHANGED
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
View,
|
|
16
16
|
} from 'react-native';
|
|
17
17
|
import styles from './styles';
|
|
18
|
-
import {ApplicationContext} from '@momo-kits/foundation';
|
|
19
|
-
import {WheelPickerProps} from './types';
|
|
20
|
-
import {debounce, itemSize} from './utils';
|
|
18
|
+
import { ApplicationContext } from '@momo-kits/foundation';
|
|
19
|
+
import { WheelPickerProps } from './types';
|
|
20
|
+
import { debounce, itemSize } from './utils';
|
|
21
21
|
import WheelPickerItem from './WheelPickerItem';
|
|
22
22
|
|
|
23
23
|
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
|
@@ -28,7 +28,7 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
28
28
|
onChange,
|
|
29
29
|
selectedData,
|
|
30
30
|
}) => {
|
|
31
|
-
const {theme} = useContext(ApplicationContext);
|
|
31
|
+
const { theme } = useContext(ApplicationContext);
|
|
32
32
|
const flatListRef = useRef<any>(null);
|
|
33
33
|
const scrollAnimatedValue = useRef(new Animated.Value(0)).current;
|
|
34
34
|
const canMomentum = useRef(false);
|
|
@@ -76,7 +76,7 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
76
76
|
});
|
|
77
77
|
}, 100);
|
|
78
78
|
|
|
79
|
-
const renderItem = useCallback(({item, index}: ListRenderItemInfo<any>) => {
|
|
79
|
+
const renderItem = useCallback(({ item, index }: ListRenderItemInfo<any>) => {
|
|
80
80
|
return (
|
|
81
81
|
<WheelPickerItem
|
|
82
82
|
item={item}
|
|
@@ -90,14 +90,14 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
90
90
|
const renderOverlay = () => {
|
|
91
91
|
return (
|
|
92
92
|
<View style={styles.overlay}>
|
|
93
|
-
<View style={[styles.selectedItem, {height: itemSize}]} />
|
|
93
|
+
<View style={[styles.selectedItem, { height: itemSize }]} />
|
|
94
94
|
</View>
|
|
95
95
|
);
|
|
96
96
|
};
|
|
97
97
|
|
|
98
98
|
const getItemLayout = (
|
|
99
99
|
_data: ArrayLike<unknown> | null | undefined,
|
|
100
|
-
index: number
|
|
100
|
+
index: number,
|
|
101
101
|
) => ({
|
|
102
102
|
length: itemSize,
|
|
103
103
|
offset: itemSize * index,
|
|
@@ -128,8 +128,11 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
128
128
|
{
|
|
129
129
|
borderColor: theme.colors.border.default,
|
|
130
130
|
backgroundColor: theme.colors.background.surface,
|
|
131
|
+
maxHeight: itemSize * 5,
|
|
131
132
|
},
|
|
132
|
-
]}
|
|
133
|
+
]}
|
|
134
|
+
>
|
|
135
|
+
{renderOverlay()}
|
|
133
136
|
<AnimatedFlatList
|
|
134
137
|
windowSize={7}
|
|
135
138
|
initialNumToRender={initItemNum}
|
|
@@ -142,10 +145,10 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
142
145
|
onScrollToIndexFailed={onScrollToIndexFailed}
|
|
143
146
|
onMomentumScrollBegin={onMomentumScrollBegin}
|
|
144
147
|
onScroll={Animated.event(
|
|
145
|
-
[{nativeEvent: {contentOffset: {y: scrollAnimatedValue}}}],
|
|
148
|
+
[{ nativeEvent: { contentOffset: { y: scrollAnimatedValue } } }],
|
|
146
149
|
{
|
|
147
150
|
useNativeDriver: true,
|
|
148
|
-
}
|
|
151
|
+
},
|
|
149
152
|
)}
|
|
150
153
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
151
154
|
ref={flatListRef}
|
|
@@ -153,7 +156,6 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
153
156
|
data={data}
|
|
154
157
|
renderItem={renderItem}
|
|
155
158
|
/>
|
|
156
|
-
{renderOverlay()}
|
|
157
159
|
</View>
|
|
158
160
|
);
|
|
159
161
|
};
|
package/WheelPickerItem.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, {FC, memo, useContext} from 'react';
|
|
2
|
-
import {Animated} from 'react-native';
|
|
1
|
+
import React, { FC, memo, useContext } from 'react';
|
|
2
|
+
import { Animated } from 'react-native';
|
|
3
3
|
import styles from './styles';
|
|
4
|
-
import {ApplicationContext
|
|
5
|
-
import {WheelPickerItemProps} from './types';
|
|
4
|
+
import { ApplicationContext } from '@momo-kits/foundation';
|
|
5
|
+
import { WheelPickerItemProps } from './types';
|
|
6
6
|
|
|
7
7
|
const WheelPickerItem: FC<WheelPickerItemProps> = ({
|
|
8
8
|
item,
|
|
@@ -10,7 +10,7 @@ const WheelPickerItem: FC<WheelPickerItemProps> = ({
|
|
|
10
10
|
scrollAnimatedValue,
|
|
11
11
|
itemSize,
|
|
12
12
|
}) => {
|
|
13
|
-
const {theme} = useContext(ApplicationContext);
|
|
13
|
+
const { theme } = useContext(ApplicationContext);
|
|
14
14
|
const position = Animated.divide(scrollAnimatedValue, itemSize);
|
|
15
15
|
const distance = Animated.subtract(index, position);
|
|
16
16
|
const opacity =
|
|
@@ -34,7 +34,8 @@ const WheelPickerItem: FC<WheelPickerItemProps> = ({
|
|
|
34
34
|
opacity,
|
|
35
35
|
height: itemSize,
|
|
36
36
|
},
|
|
37
|
-
]}
|
|
37
|
+
]}
|
|
38
|
+
>
|
|
38
39
|
<Animated.Text
|
|
39
40
|
style={{
|
|
40
41
|
fontFamily: `${theme.font}-Semibold`,
|
|
@@ -43,9 +44,10 @@ const WheelPickerItem: FC<WheelPickerItemProps> = ({
|
|
|
43
44
|
scale,
|
|
44
45
|
},
|
|
45
46
|
],
|
|
46
|
-
fontSize:
|
|
47
|
-
lineHeight:
|
|
48
|
-
}}
|
|
47
|
+
fontSize: 16,
|
|
48
|
+
lineHeight: 22,
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
49
51
|
{item}
|
|
50
52
|
</Animated.Text>
|
|
51
53
|
</Animated.View>
|
package/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {FC, useEffect, useMemo, useState} from 'react';
|
|
2
|
-
import {Dimensions, LayoutChangeEvent, View} from 'react-native';
|
|
3
|
-
import {
|
|
1
|
+
import React, { FC, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { Dimensions, LayoutChangeEvent, View } from 'react-native';
|
|
3
|
+
import { Spacing, Text } from '@momo-kits/foundation';
|
|
4
4
|
import WheelPicker from './WheelPicker';
|
|
5
5
|
import {
|
|
6
6
|
getDaysInMonth,
|
|
@@ -8,10 +8,9 @@ import {
|
|
|
8
8
|
getMinutes,
|
|
9
9
|
getMonths,
|
|
10
10
|
getYears,
|
|
11
|
-
itemSize,
|
|
12
11
|
timeMode,
|
|
13
12
|
} from './utils';
|
|
14
|
-
import {DateObject, DateTimePickerProps, PickerDataObject} from './types';
|
|
13
|
+
import { DateObject, DateTimePickerProps, PickerDataObject } from './types';
|
|
15
14
|
import styles from './styles';
|
|
16
15
|
|
|
17
16
|
const date = new Date();
|
|
@@ -63,21 +62,21 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
63
62
|
const dayData = useMemo(
|
|
64
63
|
() =>
|
|
65
64
|
getDaysInMonth(+currentDate.year, +currentDate.month, minDate, maxDate),
|
|
66
|
-
[currentDate.year, currentDate.month, minDate, maxDate]
|
|
65
|
+
[currentDate.year, currentDate.month, minDate, maxDate],
|
|
67
66
|
);
|
|
68
67
|
const monthData = useMemo(
|
|
69
68
|
() => getMonths(minDate, maxDate, +currentDate.year),
|
|
70
|
-
[currentDate.year, minDate, maxDate]
|
|
69
|
+
[currentDate.year, minDate, maxDate],
|
|
71
70
|
);
|
|
72
71
|
const yearData = useMemo(
|
|
73
72
|
() => getYears(minDate, maxDate),
|
|
74
|
-
[minDate, maxDate]
|
|
73
|
+
[minDate, maxDate],
|
|
75
74
|
);
|
|
76
75
|
const hourData = useMemo(() => getHours(isOnlyHour ? 12 : 24), []);
|
|
77
76
|
const minData = useMemo(() => getMinutes(minuteInterval), []);
|
|
78
77
|
|
|
79
78
|
const setupData = () => {
|
|
80
|
-
const componentData: {[key: string]: DateObject} = {
|
|
79
|
+
const componentData: { [key: string]: DateObject } = {
|
|
81
80
|
DD: {
|
|
82
81
|
name: 'day',
|
|
83
82
|
data: dayData,
|
|
@@ -90,8 +89,8 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
90
89
|
name: 'year',
|
|
91
90
|
data: yearData,
|
|
92
91
|
},
|
|
93
|
-
HH: {name: 'hour', data: hourData},
|
|
94
|
-
mm: {name: 'min', data: minData},
|
|
92
|
+
HH: { name: 'hour', data: hourData },
|
|
93
|
+
mm: { name: 'min', data: minData },
|
|
95
94
|
};
|
|
96
95
|
|
|
97
96
|
const initialData = formatParts.map(part => {
|
|
@@ -105,7 +104,7 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
105
104
|
});
|
|
106
105
|
|
|
107
106
|
if (isOnlyHour) {
|
|
108
|
-
initialData.push({name: 'timeMode', data: timeMode});
|
|
107
|
+
initialData.push({ name: 'timeMode', data: timeMode });
|
|
109
108
|
}
|
|
110
109
|
|
|
111
110
|
setData(initialData);
|
|
@@ -131,7 +130,7 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
131
130
|
newDate.month - 1,
|
|
132
131
|
newDate.day,
|
|
133
132
|
newDate.hour,
|
|
134
|
-
newDate.min
|
|
133
|
+
newDate.min,
|
|
135
134
|
);
|
|
136
135
|
|
|
137
136
|
if (
|
|
@@ -156,23 +155,12 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
156
155
|
};
|
|
157
156
|
|
|
158
157
|
return (
|
|
159
|
-
<View
|
|
160
|
-
onLayout={onLayout}
|
|
161
|
-
style={[
|
|
162
|
-
style,
|
|
163
|
-
styles.datePicker,
|
|
164
|
-
{
|
|
165
|
-
height:
|
|
166
|
-
arrayLabelTime.length > 0
|
|
167
|
-
? itemSize * 5 + scaleSize(20) //date label height
|
|
168
|
-
: itemSize * 5,
|
|
169
|
-
},
|
|
170
|
-
]}>
|
|
158
|
+
<View onLayout={onLayout} style={[style, styles.datePicker]}>
|
|
171
159
|
{data.map((dataItem, index) => {
|
|
172
160
|
return (
|
|
173
161
|
<View key={`${dataItem.name}_${index}`}>
|
|
174
162
|
{arrayLabelTime[index] && (
|
|
175
|
-
<View style={
|
|
163
|
+
<View style={styles.dateTimeContainer}>
|
|
176
164
|
<Text typography="action_s_bold">{arrayLabelTime[index]}</Text>
|
|
177
165
|
</View>
|
|
178
166
|
)}
|
|
@@ -196,5 +184,5 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
196
184
|
);
|
|
197
185
|
};
|
|
198
186
|
|
|
199
|
-
export type {DateTimePickerProps};
|
|
200
|
-
export {DateTimePicker};
|
|
187
|
+
export type { DateTimePickerProps };
|
|
188
|
+
export { DateTimePicker };
|
package/package.json
CHANGED
package/styles.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {StyleSheet} from 'react-native';
|
|
2
|
-
import {Colors, Radius} from '@momo-kits/foundation';
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors, Radius, Spacing } from '@momo-kits/foundation';
|
|
3
3
|
|
|
4
4
|
export default StyleSheet.create({
|
|
5
5
|
wheelItem: {
|
|
@@ -10,7 +10,6 @@ export default StyleSheet.create({
|
|
|
10
10
|
wheelPicker: {
|
|
11
11
|
borderWidth: 1,
|
|
12
12
|
borderRadius: Radius.S,
|
|
13
|
-
flex: 1,
|
|
14
13
|
},
|
|
15
14
|
overlay: {
|
|
16
15
|
position: 'absolute',
|
|
@@ -19,7 +18,6 @@ export default StyleSheet.create({
|
|
|
19
18
|
right: 0,
|
|
20
19
|
left: 0,
|
|
21
20
|
justifyContent: 'center',
|
|
22
|
-
zIndex: -1,
|
|
23
21
|
},
|
|
24
22
|
selectedItem: {
|
|
25
23
|
backgroundColor: Colors.blue_10,
|
|
@@ -29,4 +27,5 @@ export default StyleSheet.create({
|
|
|
29
27
|
flexDirection: 'row',
|
|
30
28
|
justifyContent: 'space-evenly',
|
|
31
29
|
},
|
|
30
|
+
dateTimeContainer: { alignItems: 'center', marginBottom: Spacing.S },
|
|
32
31
|
});
|