@momo-kits/date-picker 0.92.16-beta.0 → 0.92.16-beta.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/WheelPicker.tsx +13 -6
- package/index.tsx +47 -27
- package/package.json +2 -2
- package/publish.sh +14 -7
- package/styles.ts +3 -2
- package/types.ts +6 -1
package/WheelPicker.tsx
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
FC,
|
|
3
|
+
memo,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import {Animated, View} from 'react-native';
|
|
3
10
|
import {FlatList} from 'react-native-gesture-handler';
|
|
4
11
|
import styles from './styles';
|
|
@@ -24,7 +31,7 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
24
31
|
useEffect(() => {
|
|
25
32
|
scrollListener.current && clearInterval(Number(scrollListener.current));
|
|
26
33
|
scrollListener.current = scrollAnimatedValue.addListener(
|
|
27
|
-
({value}) => (active.current = value)
|
|
34
|
+
({value}) => (active.current = value)
|
|
28
35
|
);
|
|
29
36
|
|
|
30
37
|
return () => {
|
|
@@ -44,7 +51,7 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
44
51
|
let aDiff = Math.abs(Number(a) - Number(value));
|
|
45
52
|
let bDiff = Math.abs(Number(b) - Number(value));
|
|
46
53
|
|
|
47
|
-
if (aDiff
|
|
54
|
+
if (aDiff === bDiff) {
|
|
48
55
|
return a < b ? a : b;
|
|
49
56
|
} else {
|
|
50
57
|
return bDiff < aDiff ? b : a;
|
|
@@ -156,7 +163,7 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
156
163
|
|
|
157
164
|
const getItemLayout = (
|
|
158
165
|
data: unknown[] | undefined | null,
|
|
159
|
-
index: number
|
|
166
|
+
index: number
|
|
160
167
|
) => ({
|
|
161
168
|
length: itemSize,
|
|
162
169
|
offset: itemSize * index,
|
|
@@ -191,7 +198,7 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
191
198
|
[{nativeEvent: {contentOffset: {y: scrollAnimatedValue}}}],
|
|
192
199
|
{
|
|
193
200
|
useNativeDriver: true,
|
|
194
|
-
}
|
|
201
|
+
}
|
|
195
202
|
)}
|
|
196
203
|
onMomentumScrollEnd={onMomentumScrollEnd}
|
|
197
204
|
ref={flatListRef}
|
|
@@ -205,4 +212,4 @@ const WheelPicker: FC<WheelPickerProps> = ({
|
|
|
205
212
|
);
|
|
206
213
|
};
|
|
207
214
|
|
|
208
|
-
export default WheelPicker;
|
|
215
|
+
export default memo(WheelPicker);
|
package/index.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {FC, useEffect, useState} from 'react';
|
|
2
|
-
import {Dimensions, LayoutChangeEvent, View} from 'react-native';
|
|
3
|
-
import {Spacing} from '@momo-kits/foundation';
|
|
1
|
+
import React, { FC, useEffect, useState } from 'react';
|
|
2
|
+
import { Dimensions, LayoutChangeEvent, Platform, View } from 'react-native';
|
|
3
|
+
import { Spacing, Text } from '@momo-kits/foundation';
|
|
4
4
|
import WheelPicker from './WheelPicker';
|
|
5
5
|
import {
|
|
6
6
|
getDaysInMonth,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
getYears,
|
|
11
11
|
timeMode,
|
|
12
12
|
} from './utils';
|
|
13
|
-
import {DateObject, DateTimePickerProps, PickerDataObject} from './types';
|
|
13
|
+
import { DateObject, DateTimePickerProps, PickerDataObject } from './types';
|
|
14
14
|
import styles from './styles';
|
|
15
15
|
|
|
16
16
|
const date = new Date();
|
|
@@ -28,6 +28,7 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
28
28
|
selectedValue = date,
|
|
29
29
|
minDate = minDateDefault,
|
|
30
30
|
maxDate = maxDateDefault,
|
|
31
|
+
arrayLabelTime = []
|
|
31
32
|
}) => {
|
|
32
33
|
const [data, setData] = useState<DateObject[]>([]);
|
|
33
34
|
let [currentDate, setCurrentDate] = useState<PickerDataObject>({
|
|
@@ -41,21 +42,27 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
41
42
|
|
|
42
43
|
useEffect(() => {
|
|
43
44
|
setupData();
|
|
44
|
-
return () => {};
|
|
45
|
+
return () => { };
|
|
45
46
|
}, [selectedValue, currentDate]);
|
|
46
47
|
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (Platform.OS === 'android') {
|
|
50
|
+
onChange?.(selectedValue);
|
|
51
|
+
}
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
47
54
|
const setupData = () => {
|
|
48
55
|
const formatParts = format.split(/[^A-Za-z]+/);
|
|
49
56
|
const isOnlyHour = formatParts.length === 1 && formatParts[0] === 'HH';
|
|
50
57
|
|
|
51
|
-
const componentData: {[key: string]: DateObject} = {
|
|
58
|
+
const componentData: { [key: string]: DateObject } = {
|
|
52
59
|
DD: {
|
|
53
60
|
name: 'day',
|
|
54
61
|
data: getDaysInMonth(
|
|
55
62
|
+currentDate.year,
|
|
56
63
|
+currentDate.month,
|
|
57
64
|
minDate,
|
|
58
|
-
maxDate
|
|
65
|
+
maxDate
|
|
59
66
|
),
|
|
60
67
|
},
|
|
61
68
|
MM: {
|
|
@@ -66,8 +73,8 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
66
73
|
name: 'year',
|
|
67
74
|
data: getYears(minDate, maxDate),
|
|
68
75
|
},
|
|
69
|
-
HH: {name: 'hour', data: getHours(isOnlyHour ? 12 : 24)},
|
|
70
|
-
mm: {name: 'min', data: getMinutes(minuteInterval)},
|
|
76
|
+
HH: { name: 'hour', data: getHours(isOnlyHour ? 12 : 24) },
|
|
77
|
+
mm: { name: 'min', data: getMinutes(minuteInterval) },
|
|
71
78
|
};
|
|
72
79
|
|
|
73
80
|
const initialData = formatParts.map(part => {
|
|
@@ -81,7 +88,7 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
81
88
|
});
|
|
82
89
|
|
|
83
90
|
if (isOnlyHour) {
|
|
84
|
-
initialData.push({name: 'timeMode', data: timeMode});
|
|
91
|
+
initialData.push({ name: 'timeMode', data: timeMode });
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
setData(initialData);
|
|
@@ -107,43 +114,56 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
107
114
|
newDate.month - 1,
|
|
108
115
|
newDate.day,
|
|
109
116
|
newDate.hour,
|
|
110
|
-
newDate.min
|
|
117
|
+
newDate.min
|
|
111
118
|
);
|
|
112
119
|
|
|
113
120
|
if (changedDate <= maxDate && changedDate >= minDate) {
|
|
114
121
|
onChange?.(changedDate);
|
|
115
122
|
}
|
|
123
|
+
|
|
116
124
|
setCurrentDate(newDate);
|
|
117
125
|
};
|
|
118
126
|
|
|
119
127
|
const paddingArray = ['', ''];
|
|
120
128
|
|
|
121
129
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
122
|
-
|
|
130
|
+
if (containerWidth !== e.nativeEvent.layout.width) {
|
|
131
|
+
setContainerWidth(e.nativeEvent.layout.width);
|
|
132
|
+
}
|
|
123
133
|
};
|
|
124
134
|
|
|
125
135
|
return (
|
|
126
136
|
<View onLayout={onLayout} style={styles.datePicker}>
|
|
127
137
|
{data.map((dataItem, index) => {
|
|
128
138
|
return (
|
|
129
|
-
<
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
<View>
|
|
140
|
+
{arrayLabelTime[index] && (
|
|
141
|
+
<View style={{ alignItems: 'center', marginBottom: Spacing.M }}>
|
|
142
|
+
<Text typography="header_default_bold">
|
|
143
|
+
{arrayLabelTime[index]}
|
|
144
|
+
</Text>
|
|
145
|
+
</View>
|
|
146
|
+
)}
|
|
147
|
+
<WheelPicker
|
|
148
|
+
key={`${dataItem.name}_${index}`}
|
|
149
|
+
selectedData={String(currentDate[dataItem.name])}
|
|
150
|
+
onChange={onPickerChange}
|
|
151
|
+
data={[...paddingArray, ...dataItem.data, ...paddingArray]}
|
|
152
|
+
name={dataItem.name}
|
|
153
|
+
style={{
|
|
154
|
+
width:
|
|
155
|
+
(containerWidth -
|
|
156
|
+
Spacing.M * 2 -
|
|
157
|
+
(numOfColumns - 1) * Spacing.M) /
|
|
158
|
+
numOfColumns,
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
</View>
|
|
162
|
+
)
|
|
144
163
|
})}
|
|
145
164
|
</View>
|
|
146
165
|
);
|
|
147
166
|
};
|
|
148
167
|
|
|
168
|
+
export type {DateTimePickerProps};
|
|
149
169
|
export {DateTimePicker};
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -6,16 +6,23 @@ mkdir dist
|
|
|
6
6
|
rsync -r --exclude=/dist ./* dist
|
|
7
7
|
cd dist
|
|
8
8
|
|
|
9
|
-
if [ "$1" == "
|
|
10
|
-
npm version $(npm view @momo-kits/date-picker@
|
|
11
|
-
npm version
|
|
12
|
-
npm publish --tag
|
|
13
|
-
|
|
14
|
-
npm version $(npm view @momo-kits/date-picker version)
|
|
15
|
-
npm version
|
|
9
|
+
if [ "$1" == "stable" ]; then
|
|
10
|
+
#npm version $(npm view @momo-kits/date-picker@stable version)
|
|
11
|
+
#npm version patch
|
|
12
|
+
npm publish --tag stable --access=public
|
|
13
|
+
elif [ "$1" == "latest" ]; then
|
|
14
|
+
#npm version $(npm view @momo-kits/date-picker@latest version)
|
|
15
|
+
#npm version prerelease --preid=rc
|
|
16
16
|
npm publish --tag latest --access=public
|
|
17
|
+
else
|
|
18
|
+
#npm version $(npm view @momo-kits/date-picker@beta version)
|
|
19
|
+
#npm version prerelease --preid=beta
|
|
20
|
+
npm publish --tag beta --access=public
|
|
17
21
|
fi
|
|
18
22
|
|
|
23
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
24
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
25
|
+
|
|
19
26
|
# Clean up
|
|
20
27
|
cd ..
|
|
21
28
|
rm -rf dist
|
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: {
|
|
@@ -30,5 +30,6 @@ export default StyleSheet.create({
|
|
|
30
30
|
overflow: 'hidden',
|
|
31
31
|
flexDirection: 'row',
|
|
32
32
|
justifyContent: 'space-evenly',
|
|
33
|
+
marginBottom: Spacing.XL,
|
|
33
34
|
},
|
|
34
35
|
});
|
package/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ViewStyle} from 'react-native';
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
2
|
|
|
3
3
|
export type DateTimePickerProps = {
|
|
4
4
|
/**
|
|
@@ -30,6 +30,11 @@ export type DateTimePickerProps = {
|
|
|
30
30
|
* Optional. The maximum date that can be selected.
|
|
31
31
|
*/
|
|
32
32
|
maxDate?: Date;
|
|
33
|
+
/**
|
|
34
|
+
* Optional. Label for Time
|
|
35
|
+
*/
|
|
36
|
+
arrayLabelTime?: string[];
|
|
37
|
+
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
/**
|