@momo-kits/date-picker 0.92.7 → 0.92.8-beta.0
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 +55 -34
- package/package.json +2 -2
- package/publish.sh +22 -22
- 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);
|
|
@@ -102,47 +109,61 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
newDate.min,
|
|
112
|
-
),
|
|
112
|
+
const changedDate = new Date(
|
|
113
|
+
newDate.year,
|
|
114
|
+
newDate.month - 1,
|
|
115
|
+
newDate.day,
|
|
116
|
+
newDate.hour,
|
|
117
|
+
newDate.min
|
|
113
118
|
);
|
|
114
119
|
|
|
120
|
+
if (changedDate <= maxDate && changedDate >= minDate) {
|
|
121
|
+
onChange?.(changedDate);
|
|
122
|
+
}
|
|
123
|
+
|
|
115
124
|
setCurrentDate(newDate);
|
|
116
125
|
};
|
|
117
126
|
|
|
118
127
|
const paddingArray = ['', ''];
|
|
119
128
|
|
|
120
129
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
121
|
-
|
|
130
|
+
if (containerWidth !== e.nativeEvent.layout.width) {
|
|
131
|
+
setContainerWidth(e.nativeEvent.layout.width);
|
|
132
|
+
}
|
|
122
133
|
};
|
|
123
134
|
|
|
124
135
|
return (
|
|
125
136
|
<View onLayout={onLayout} style={styles.datePicker}>
|
|
126
137
|
{data.map((dataItem, index) => {
|
|
127
138
|
return (
|
|
128
|
-
<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
)
|
|
143
163
|
})}
|
|
144
164
|
</View>
|
|
145
165
|
);
|
|
146
166
|
};
|
|
147
167
|
|
|
168
|
+
export type {DateTimePickerProps};
|
|
148
169
|
export {DateTimePicker};
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Prepare dist files
|
|
2
4
|
rm -rf dist
|
|
3
5
|
mkdir dist
|
|
4
|
-
|
|
5
|
-
cp . ./dist
|
|
6
|
-
|
|
7
|
-
# GET VERSION from mck_package.json
|
|
8
|
-
VERSIONSTRING=( v$(jq .version package.json) )
|
|
9
|
-
VERSION=(${VERSIONSTRING//[\"]/})
|
|
10
|
-
echo VERSION: $VERSION
|
|
11
|
-
|
|
12
|
-
rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
|
|
13
|
-
|
|
14
|
-
# #babel component to dist
|
|
15
|
-
#babel ./dist -d dist --copy-files
|
|
16
|
-
|
|
17
|
-
#copy option
|
|
18
|
-
#cp -r ./src/ dist
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#npm login
|
|
22
|
-
#publish dist to npm
|
|
6
|
+
rsync -r --exclude=/dist ./* dist
|
|
23
7
|
cd dist
|
|
24
|
-
|
|
8
|
+
|
|
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
|
+
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
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
PACKAGE_NAME=$(npm pkg get name)
|
|
24
|
+
NEW_PACKAGE_VERSION=$(npm pkg get version)
|
|
25
|
+
|
|
26
|
+
# Clean up
|
|
25
27
|
cd ..
|
|
26
28
|
rm -rf dist
|
|
27
|
-
|
|
28
|
-
##curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/date-picker new version release: '*"$VERSION"*' `https://www.npmjs.com/package/@momo-kits/date-picker`"}'
|
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
|
/**
|