@momo-kits/date-picker 0.92.8-beta.10 → 0.92.8-beta.11
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 +9 -2
- package/index.tsx +44 -25
- package/package.json +16 -16
- 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';
|
|
@@ -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,14 +42,20 @@ 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(
|
|
@@ -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);
|
|
@@ -113,34 +120,46 @@ const DateTimePicker: FC<DateTimePickerProps> = ({
|
|
|
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
|
);
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
"name": "@momo-kits/date-picker",
|
|
3
|
+
"version": "0.92.8-beta.11",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@momo-kits/foundation": "latest",
|
|
8
|
+
"react-native-gesture-handler": "1.10.3",
|
|
9
|
+
"react": "16.9.0",
|
|
10
|
+
"react-native": ">=0.55",
|
|
11
|
+
"prop-types": "^15.7.2"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@momo-platform/versions": "4.1.11"
|
|
15
|
+
},
|
|
16
|
+
"license": "MoMo",
|
|
17
|
+
"dependencies": {}
|
|
18
18
|
}
|
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
|
/**
|