@momo-kits/date-picker 0.0.66-alpha.1 → 0.0.66-alpha.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/datePicker/DatePicker.js +20 -7
- package/datePicker/DatePickerInput.js +117 -120
- package/datePicker/ListPicker.js +185 -174
- package/datePicker/WheelPicker.js +13 -14
- package/datePicker/helper/DatePickerHelper.js +58 -22
- package/package.json +15 -15
package/datePicker/DatePicker.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
SwitchLanguage,
|
|
12
12
|
Spacing,
|
|
13
13
|
Colors,
|
|
14
|
-
} from '@momo-kits/core';
|
|
14
|
+
} from '@momo-kits/core-v2';
|
|
15
15
|
import WheelPicker from './WheelPicker';
|
|
16
16
|
import DatePickerHelper from './helper/DatePickerHelper';
|
|
17
17
|
|
|
@@ -73,7 +73,20 @@ class DatePicker extends Component {
|
|
|
73
73
|
this.initDefault(props);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
// onBackPress = () => {
|
|
77
|
+
// this.hide();
|
|
78
|
+
// return true;
|
|
79
|
+
// }
|
|
80
|
+
|
|
76
81
|
componentDidMount() {
|
|
82
|
+
// BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
|
|
83
|
+
// BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
|
|
84
|
+
|
|
85
|
+
// setTimeout(() => {
|
|
86
|
+
// BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
|
|
87
|
+
// BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
|
|
88
|
+
// }, 200);
|
|
89
|
+
|
|
77
90
|
this.setStateMonth(this.dayIndex, this.monthIndex, this.yearIndex);
|
|
78
91
|
const {onCreateRef} = this.props;
|
|
79
92
|
if (typeof onCreateRef === 'function') onCreateRef(this);
|
|
@@ -191,8 +204,6 @@ class DatePicker extends Component {
|
|
|
191
204
|
this.minutes = DatePickerHelper.makeRange(0, 59, true);
|
|
192
205
|
}
|
|
193
206
|
this.ranged = rangeHour || DatePickerHelper.arrayRange;
|
|
194
|
-
this.startTime = startTime || DatePickerHelper.arrayRange;
|
|
195
|
-
this.endTime = endTime || DatePickerHelper.arrayRange;
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
selectedIndexDate() {
|
|
@@ -321,6 +332,7 @@ class DatePicker extends Component {
|
|
|
321
332
|
if (isRanged && format === 'hh:mm') {
|
|
322
333
|
const from = this.ranged[this.hourRangeIndex_1];
|
|
323
334
|
const to = this.ranged[this.hourRangeIndex_2];
|
|
335
|
+
|
|
324
336
|
if (onSelected && typeof onSelected === 'function') {
|
|
325
337
|
onSelected({
|
|
326
338
|
from,
|
|
@@ -560,9 +572,9 @@ class DatePicker extends Component {
|
|
|
560
572
|
const {description, descriptionStyle, renderDescription} = this.props;
|
|
561
573
|
if (renderDescription) return renderDescription;
|
|
562
574
|
return description ? (
|
|
563
|
-
<Text.
|
|
575
|
+
<Text.Paragraph style={[{marginBottom: Spacing.S}, descriptionStyle]}>
|
|
564
576
|
{description}
|
|
565
|
-
</Text.
|
|
577
|
+
</Text.Paragraph>
|
|
566
578
|
) : null;
|
|
567
579
|
};
|
|
568
580
|
|
|
@@ -577,6 +589,7 @@ class DatePicker extends Component {
|
|
|
577
589
|
labelHour,
|
|
578
590
|
isRanged,
|
|
579
591
|
} = this.props;
|
|
592
|
+
|
|
580
593
|
if (isRanged && format === 'hh:mm') {
|
|
581
594
|
return (
|
|
582
595
|
<View style={styles.container}>
|
|
@@ -585,7 +598,7 @@ class DatePicker extends Component {
|
|
|
585
598
|
{this.renderColumn(
|
|
586
599
|
'HourRange1',
|
|
587
600
|
this.hourRangeIndex_1,
|
|
588
|
-
this.
|
|
601
|
+
this.ranged,
|
|
589
602
|
SwitchLanguage.from,
|
|
590
603
|
bottomOffset,
|
|
591
604
|
value => {
|
|
@@ -596,7 +609,7 @@ class DatePicker extends Component {
|
|
|
596
609
|
{this.renderColumn(
|
|
597
610
|
'HourRange2',
|
|
598
611
|
this.hourRangeIndex_2,
|
|
599
|
-
this.
|
|
612
|
+
this.ranged,
|
|
600
613
|
SwitchLanguage.to,
|
|
601
614
|
bottomOffset,
|
|
602
615
|
value => {
|
|
@@ -1,139 +1,136 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
|
-
import React, {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import React, {useState} from 'react';
|
|
3
|
+
import {StyleSheet} from 'react-native';
|
|
4
|
+
import {isEmpty} from 'lodash';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
IconSource,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
Text,
|
|
9
|
+
Colors,
|
|
10
|
+
ValueUtil,
|
|
11
|
+
Image,
|
|
12
|
+
Radius,
|
|
13
|
+
} from '@momo-kits/core-v2';
|
|
13
14
|
import DatePicker from './DatePicker';
|
|
14
15
|
|
|
15
16
|
const DatePickerInput = ({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
navigator,
|
|
18
|
+
defaultDate,
|
|
19
|
+
maxDate,
|
|
20
|
+
minDate,
|
|
21
|
+
format = 'dd/MM/YYYY',
|
|
22
|
+
onSelected,
|
|
23
|
+
onClose,
|
|
24
|
+
style,
|
|
25
|
+
textStyle,
|
|
26
|
+
icon,
|
|
27
|
+
iconStyle,
|
|
28
|
+
error,
|
|
29
|
+
disabled,
|
|
30
|
+
minuteArray,
|
|
31
|
+
title,
|
|
32
|
+
showRightIcon,
|
|
32
33
|
}) => {
|
|
33
|
-
|
|
34
|
+
const [selected, setSelected] = useState(defaultDate || '');
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
const onPress = () => {
|
|
37
|
+
navigator?.showBottom?.({
|
|
38
|
+
screen: DatePicker,
|
|
39
|
+
params: {
|
|
40
|
+
dragDisabled: true,
|
|
41
|
+
minDate,
|
|
42
|
+
maxDate,
|
|
43
|
+
format,
|
|
44
|
+
title,
|
|
45
|
+
selectedDate: selected,
|
|
46
|
+
onClose,
|
|
47
|
+
minuteArray,
|
|
48
|
+
onSelected: dateSelected => {
|
|
49
|
+
onSelected?.(dateSelected);
|
|
50
|
+
setSelected(dateSelected);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
let otherStyle = {};
|
|
56
|
+
if (error) otherStyle = styles.error;
|
|
57
|
+
if (disabled) otherStyle = styles.disabled;
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<View />
|
|
82
|
-
)}
|
|
83
|
-
</TouchableOpacity>
|
|
84
|
-
);
|
|
59
|
+
return (
|
|
60
|
+
<TouchableOpacity
|
|
61
|
+
disabled={disabled}
|
|
62
|
+
onPress={onPress}
|
|
63
|
+
style={[styles.container, ValueUtil.extractStyle(style), otherStyle]}>
|
|
64
|
+
<Text.Paragraph
|
|
65
|
+
style={[
|
|
66
|
+
styles.defaultText,
|
|
67
|
+
ValueUtil.extractStyle(textStyle),
|
|
68
|
+
isEmpty(selected) ? {color: Colors.black_09} : {},
|
|
69
|
+
]}>
|
|
70
|
+
{isEmpty(selected) ? format : selected}
|
|
71
|
+
</Text.Paragraph>
|
|
72
|
+
{showRightIcon ? (
|
|
73
|
+
<Image
|
|
74
|
+
source={icon || IconSource.ic_calendar}
|
|
75
|
+
style={[styles.icon, ValueUtil.extractStyle(iconStyle)]}
|
|
76
|
+
/>
|
|
77
|
+
) : (
|
|
78
|
+
<View />
|
|
79
|
+
)}
|
|
80
|
+
</TouchableOpacity>
|
|
81
|
+
);
|
|
85
82
|
};
|
|
86
83
|
|
|
87
84
|
DatePickerInput.propTypes = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
85
|
+
defaultDate: PropTypes.string,
|
|
86
|
+
format: PropTypes.oneOf(['hh:mm', 'MM/YYYY', 'dd/MM', 'dd/MM/YYYY']),
|
|
87
|
+
icon: PropTypes.any,
|
|
88
|
+
maxDate: PropTypes.string,
|
|
89
|
+
minDate: PropTypes.string,
|
|
90
|
+
navigator: PropTypes.object,
|
|
91
|
+
onClose: PropTypes.func,
|
|
92
|
+
onSelected: PropTypes.func,
|
|
93
|
+
iconStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
94
|
+
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
95
|
+
textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
96
|
+
error: PropTypes.bool,
|
|
97
|
+
disabled: PropTypes.bool,
|
|
98
|
+
minuteArray: PropTypes.arrayOf(PropTypes.string),
|
|
99
|
+
showRightIcon: PropTypes.bool,
|
|
100
|
+
title: PropTypes.string,
|
|
104
101
|
};
|
|
105
102
|
DatePickerInput.defaultProps = {
|
|
106
|
-
|
|
103
|
+
showRightIcon: true,
|
|
107
104
|
};
|
|
108
105
|
|
|
109
106
|
export default DatePickerInput;
|
|
110
107
|
|
|
111
108
|
const styles = StyleSheet.create({
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
109
|
+
icon: {
|
|
110
|
+
width: 16,
|
|
111
|
+
height: 16,
|
|
112
|
+
resizeMode: 'contain',
|
|
113
|
+
tintColor: Colors.black_09,
|
|
114
|
+
},
|
|
115
|
+
container: {
|
|
116
|
+
flexDirection: 'row',
|
|
117
|
+
height: 42,
|
|
118
|
+
borderRadius: Radius.S,
|
|
119
|
+
borderColor: Colors.black_06,
|
|
120
|
+
borderWidth: 1,
|
|
121
|
+
alignItems: 'center',
|
|
122
|
+
justifyContent: 'space-between',
|
|
123
|
+
paddingHorizontal: 12,
|
|
124
|
+
backgroundColor: Colors.black_01,
|
|
125
|
+
},
|
|
126
|
+
error: {
|
|
127
|
+
borderColor: Colors.red_03,
|
|
128
|
+
},
|
|
129
|
+
defaultText: {
|
|
130
|
+
// fontSize: 14
|
|
131
|
+
},
|
|
132
|
+
disabled: {
|
|
133
|
+
backgroundColor: Colors.black_05,
|
|
134
|
+
borderWidth: 0,
|
|
135
|
+
},
|
|
139
136
|
});
|
package/datePicker/ListPicker.js
CHANGED
|
@@ -1,197 +1,208 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
1
|
+
import React, {Component} from 'react';
|
|
2
|
+
import {Dimensions, StyleSheet, View} from 'react-native';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '@momo-kits/core';
|
|
4
|
+
Button,
|
|
5
|
+
IconSource,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
Text,
|
|
8
|
+
Colors,
|
|
9
|
+
Image,
|
|
10
|
+
DeviceUtils,
|
|
11
|
+
SwitchLanguage,
|
|
12
|
+
} from '@momo-kits/core-v2';
|
|
13
13
|
import WheelPicker from './WheelPicker';
|
|
14
14
|
|
|
15
|
-
const {
|
|
15
|
+
const {isIphoneX} = DeviceUtils;
|
|
16
16
|
|
|
17
17
|
const widthScreen = Dimensions.get('window').width;
|
|
18
18
|
|
|
19
19
|
export default class ListPicker extends Component {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this.data = 0;
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
});
|
|
25
|
+
hide = () => {
|
|
26
|
+
const {onClose, requestClose} = this.props;
|
|
27
|
+
if (requestClose && typeof requestClose === 'function') {
|
|
28
|
+
requestClose(() => {
|
|
29
|
+
if (onClose && typeof onClose === 'function') {
|
|
30
|
+
onClose();
|
|
33
31
|
}
|
|
34
|
-
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
onBeginDrag = () => {
|
|
37
|
+
if (this.refs.picker) {
|
|
38
|
+
this.refs.picker.setScrollEnabled(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
onEndDrag = () => {
|
|
43
|
+
if (this.refs.picker) {
|
|
44
|
+
this.refs.picker.setScrollEnabled(true);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
onChangeValue = value => {
|
|
49
|
+
const {callback} = this.props;
|
|
50
|
+
if (typeof callback === 'function') {
|
|
51
|
+
callback(value);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
onPressClear = () => {
|
|
56
|
+
this.hide();
|
|
57
|
+
};
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
onPressChoose = () => {
|
|
60
|
+
this.onChangeValue(this.data);
|
|
61
|
+
this.hide();
|
|
62
|
+
};
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
renderRight = () => (
|
|
65
|
+
<TouchableOpacity onPress={this.onPressChoose}>
|
|
66
|
+
<Text.Paragraph
|
|
67
|
+
style={{
|
|
68
|
+
fontWeight: 'bold',
|
|
69
|
+
color: Colors.pink_05,
|
|
70
|
+
}}>
|
|
71
|
+
{SwitchLanguage.save}
|
|
72
|
+
</Text.Paragraph>
|
|
73
|
+
</TouchableOpacity>
|
|
74
|
+
);
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
renderLeftIcon = () => (
|
|
77
|
+
<TouchableOpacity onPress={() => this.hide()}>
|
|
78
|
+
<Image
|
|
79
|
+
source={IconSource.ic_close_x_24}
|
|
80
|
+
style={{
|
|
81
|
+
width: 25,
|
|
82
|
+
height: 25,
|
|
83
|
+
tintColor: Colors.black_17,
|
|
84
|
+
}}
|
|
85
|
+
/>
|
|
86
|
+
</TouchableOpacity>
|
|
87
|
+
);
|
|
80
88
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
renderHeader() {
|
|
90
|
+
const {title = ''} = this.props;
|
|
91
|
+
return (
|
|
92
|
+
<View style={styles.header}>
|
|
93
|
+
{this.renderLeftIcon()}
|
|
94
|
+
<Text style={styles.title}>{title}</Text>
|
|
95
|
+
{this.props.typeStyle === 'aboveAction' ? (
|
|
96
|
+
this.renderRight()
|
|
97
|
+
) : (
|
|
98
|
+
<View style={{width: 25}} />
|
|
99
|
+
)}
|
|
100
|
+
</View>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
95
103
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
104
|
+
renderContent() {
|
|
105
|
+
const {arrData = [], stylePicker, initValue} = this.props;
|
|
106
|
+
return (
|
|
107
|
+
<View style={styles.contentStyle}>
|
|
108
|
+
<WheelPicker
|
|
109
|
+
stylePicker={stylePicker}
|
|
110
|
+
bottomOffset={1}
|
|
111
|
+
value={initValue}
|
|
112
|
+
key="picker"
|
|
113
|
+
ref="picker"
|
|
114
|
+
arrayValue={arrData}
|
|
115
|
+
onBeginDrag={this.onBeginDrag}
|
|
116
|
+
onEndDrag={this.onEndDrag}
|
|
117
|
+
onValueChange={value => {
|
|
118
|
+
this.data = value;
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
116
124
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
125
|
+
render() {
|
|
126
|
+
return (
|
|
127
|
+
<View style={styles.view}>
|
|
128
|
+
{this.renderHeader()}
|
|
129
|
+
{this.renderContent()}
|
|
130
|
+
{this.props.typeStyle === 'aboveAction' ? null : (
|
|
131
|
+
<View style={styles.btnView}>
|
|
132
|
+
<Button
|
|
133
|
+
style={{flex: 1}}
|
|
134
|
+
title={SwitchLanguage.cancel}
|
|
135
|
+
buttonStyle={{
|
|
136
|
+
backgroundColor: Colors.second_text_color,
|
|
137
|
+
}}
|
|
138
|
+
onPress={this.onPressClear}
|
|
139
|
+
/>
|
|
140
|
+
<Button
|
|
141
|
+
style={{
|
|
142
|
+
flex: 1,
|
|
143
|
+
marginLeft: 15,
|
|
144
|
+
}}
|
|
145
|
+
title={SwitchLanguage.choose}
|
|
146
|
+
type="primary"
|
|
147
|
+
onPress={this.onPressChoose}
|
|
148
|
+
/>
|
|
149
|
+
</View>
|
|
150
|
+
)}
|
|
151
|
+
</View>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
143
154
|
}
|
|
144
155
|
|
|
145
156
|
const styles = StyleSheet.create({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
157
|
+
container: {
|
|
158
|
+
flexDirection: 'row',
|
|
159
|
+
width: widthScreen,
|
|
160
|
+
alignItems: 'center',
|
|
161
|
+
justifyContent: 'center',
|
|
162
|
+
},
|
|
163
|
+
contentStyle: {
|
|
164
|
+
height: 230,
|
|
165
|
+
},
|
|
166
|
+
column: {
|
|
167
|
+
borderWidth: 2,
|
|
168
|
+
borderColor: 'red',
|
|
169
|
+
},
|
|
170
|
+
header: {
|
|
171
|
+
flexDirection: 'row',
|
|
172
|
+
height: 50,
|
|
173
|
+
width: widthScreen,
|
|
174
|
+
paddingHorizontal: 16,
|
|
175
|
+
alignItems: 'center',
|
|
176
|
+
justifyContent: 'space-between',
|
|
177
|
+
backgroundColor: '#fff',
|
|
178
|
+
borderBottomWidth: 1,
|
|
179
|
+
borderColor: '#DADADA',
|
|
180
|
+
},
|
|
181
|
+
view: {
|
|
182
|
+
backgroundColor: 'white',
|
|
183
|
+
paddingBottom: 10 + (isIphoneX() ? 10 : 0),
|
|
184
|
+
},
|
|
185
|
+
title: {
|
|
186
|
+
fontWeight: 'bold',
|
|
187
|
+
color: Colors.black_17,
|
|
188
|
+
flex: 1,
|
|
189
|
+
fontSize: 16,
|
|
190
|
+
textAlign: 'center',
|
|
191
|
+
},
|
|
192
|
+
titleCancel: {
|
|
193
|
+
fontSize: 17,
|
|
194
|
+
color: '#4A90E2',
|
|
195
|
+
},
|
|
196
|
+
titleConfirm: {
|
|
197
|
+
fontSize: 17,
|
|
198
|
+
color: '#4A90E2',
|
|
199
|
+
textAlign: 'right',
|
|
200
|
+
},
|
|
201
|
+
btnView: {
|
|
202
|
+
flexDirection: 'row',
|
|
203
|
+
justifyContent: 'space-between',
|
|
204
|
+
marginHorizontal: 15,
|
|
205
|
+
height: 60,
|
|
206
|
+
alignItems: 'center',
|
|
207
|
+
},
|
|
197
208
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, {Component} from 'react';
|
|
2
2
|
import {Dimensions, View} from 'react-native';
|
|
3
|
-
import {LinearGradient, Text, Colors, ScaleSize} from '@momo-kits/core';
|
|
3
|
+
import {LinearGradient, Text, Colors, ScaleSize} from '@momo-kits/core-v2';
|
|
4
4
|
import ScrollCustom from './custom/ScrollCustom';
|
|
5
5
|
import DatePickerHelper from './helper/DatePickerHelper';
|
|
6
6
|
|
|
@@ -27,6 +27,7 @@ export default class WheelPicker extends Component {
|
|
|
27
27
|
|
|
28
28
|
componentDidMount() {
|
|
29
29
|
const {value} = this.props;
|
|
30
|
+
console.log(value);
|
|
30
31
|
this.scrollToPosition(value);
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -186,20 +187,19 @@ export default class WheelPicker extends Component {
|
|
|
186
187
|
flex: 1,
|
|
187
188
|
height: heightContain + 40,
|
|
188
189
|
}}>
|
|
189
|
-
<Text.
|
|
190
|
-
weight="
|
|
190
|
+
<Text.Description2
|
|
191
|
+
weight="semibold"
|
|
191
192
|
style={{
|
|
192
193
|
color: Colors.black_17,
|
|
193
194
|
marginLeft: 6,
|
|
194
195
|
marginBottom: 3,
|
|
195
196
|
}}>
|
|
196
197
|
{DatePickerHelper.capitalizeFirstLetter(preFix || '')}
|
|
197
|
-
</Text.
|
|
198
|
+
</Text.Description2>
|
|
198
199
|
<View
|
|
199
200
|
style={{
|
|
200
201
|
flex: 1,
|
|
201
202
|
height: heightContain,
|
|
202
|
-
//backgroundColor: 'blue',
|
|
203
203
|
marginHorizontal: 6,
|
|
204
204
|
paddingBottom: 20,
|
|
205
205
|
borderWidth: 1,
|
|
@@ -233,7 +233,6 @@ export default class WheelPicker extends Component {
|
|
|
233
233
|
/>
|
|
234
234
|
|
|
235
235
|
<ScrollCustom
|
|
236
|
-
accessibilityLabel={`Select ${preFix}/ScrollView`}
|
|
237
236
|
ref={refName => {
|
|
238
237
|
this.ScrollWheelPicker = refName;
|
|
239
238
|
}}
|
|
@@ -261,24 +260,24 @@ export default class WheelPicker extends Component {
|
|
|
261
260
|
{this.renderHiddenItem(this.numberItem, this.heightItem)}
|
|
262
261
|
{items.map((valueItem, index) => (
|
|
263
262
|
<View
|
|
264
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
263
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
265
264
|
key={index}
|
|
266
|
-
accessibilityLabel={`Selected/${valueItem}/${preFix}`}
|
|
267
|
-
access
|
|
268
265
|
style={{
|
|
269
266
|
flex: 1,
|
|
270
267
|
height: this.heightItem,
|
|
271
268
|
justifyContent: 'center',
|
|
272
269
|
alignItems: 'center',
|
|
273
270
|
}}>
|
|
274
|
-
<Text
|
|
271
|
+
<Text.Action2
|
|
272
|
+
weight={value === index ? 'bold' : 'semibold'}
|
|
275
273
|
style={{
|
|
276
|
-
color: value === index ? Colors.black_17 :
|
|
277
|
-
|
|
278
|
-
fontSize:
|
|
274
|
+
color: value === index ? Colors.black_17 : Colors.black_12,
|
|
275
|
+
|
|
276
|
+
fontSize: 15,
|
|
279
277
|
}}>
|
|
280
278
|
{valueItem}
|
|
281
|
-
|
|
279
|
+
{/* {reversePreFix ? `${valueItem} ${preFix}` : `${preFix} ${valueItem}`} */}
|
|
280
|
+
</Text.Action2>
|
|
282
281
|
</View>
|
|
283
282
|
))}
|
|
284
283
|
{this.renderHiddenItem(
|
|
@@ -49,7 +49,7 @@ export default class DatePickerHelper {
|
|
|
49
49
|
'22:00',
|
|
50
50
|
'22:30',
|
|
51
51
|
'23:00',
|
|
52
|
-
'23:30'
|
|
52
|
+
'23:30',
|
|
53
53
|
];
|
|
54
54
|
|
|
55
55
|
static makeRange(min, max, isDouble) {
|
|
@@ -57,7 +57,8 @@ export default class DatePickerHelper {
|
|
|
57
57
|
// eslint-disable-next-line no-plusplus
|
|
58
58
|
for (let i = min; i <= max; i++) {
|
|
59
59
|
const string = String(i);
|
|
60
|
-
const value =
|
|
60
|
+
const value =
|
|
61
|
+
string.length === 1 && isDouble ? `0${string}` : string;
|
|
61
62
|
array.push(value);
|
|
62
63
|
}
|
|
63
64
|
return array;
|
|
@@ -69,7 +70,14 @@ export default class DatePickerHelper {
|
|
|
69
70
|
const day = current.getDate().toString();
|
|
70
71
|
const month = (current.getMonth() + 1).toString();
|
|
71
72
|
const year = current.getFullYear().toString();
|
|
72
|
-
return DatePickerHelper.toString(
|
|
73
|
+
return DatePickerHelper.toString(
|
|
74
|
+
day,
|
|
75
|
+
month,
|
|
76
|
+
year,
|
|
77
|
+
null,
|
|
78
|
+
null,
|
|
79
|
+
format,
|
|
80
|
+
);
|
|
73
81
|
}
|
|
74
82
|
return '';
|
|
75
83
|
}
|
|
@@ -77,10 +85,17 @@ export default class DatePickerHelper {
|
|
|
77
85
|
static formatDate(date, format) {
|
|
78
86
|
if (date && format) {
|
|
79
87
|
const {
|
|
80
|
-
year,
|
|
88
|
+
year,
|
|
89
|
+
month,
|
|
90
|
+
day,
|
|
91
|
+
hour,
|
|
92
|
+
minute,
|
|
93
|
+
second = 0,
|
|
81
94
|
} = DatePickerHelper.getDateTimeFromFormat(date, format);
|
|
82
|
-
if (
|
|
83
|
-
|
|
95
|
+
if (
|
|
96
|
+
DatePickerHelper.checkValidDate(year, month, day) &&
|
|
97
|
+
DatePickerHelper.checkValidTime(hour, minute, second)
|
|
98
|
+
) {
|
|
84
99
|
return new Date(year, month, day, hour, minute, second);
|
|
85
100
|
}
|
|
86
101
|
return null;
|
|
@@ -119,8 +134,14 @@ export default class DatePickerHelper {
|
|
|
119
134
|
|
|
120
135
|
const today = new Date();
|
|
121
136
|
|
|
122
|
-
const year =
|
|
123
|
-
|
|
137
|
+
const year =
|
|
138
|
+
yearIndex > -1 ? dateItems?.[yearIndex] : today.getFullYear();
|
|
139
|
+
const month =
|
|
140
|
+
monthIndex > -1
|
|
141
|
+
? dateItems?.[monthIndex] - 1
|
|
142
|
+
: today.getMonth() === 0
|
|
143
|
+
? 1
|
|
144
|
+
: today.getMonth() - 1;
|
|
124
145
|
const day = dayIndex > -1 ? dateItems?.[dayIndex] : today.getDate();
|
|
125
146
|
|
|
126
147
|
const hour = hourIndex > -1 ? dateItems[hourIndex] : 0;
|
|
@@ -142,7 +163,7 @@ export default class DatePickerHelper {
|
|
|
142
163
|
return number;
|
|
143
164
|
}
|
|
144
165
|
return `0${number}`;
|
|
145
|
-
}
|
|
166
|
+
};
|
|
146
167
|
|
|
147
168
|
static toString(day, month, year, hour, minute, format) {
|
|
148
169
|
if (day && month && year && format) {
|
|
@@ -160,24 +181,32 @@ export default class DatePickerHelper {
|
|
|
160
181
|
const year = parseInt(y);
|
|
161
182
|
const month = parseInt(m);
|
|
162
183
|
const day = parseInt(d);
|
|
163
|
-
const months31 = [
|
|
164
|
-
const months30 = [
|
|
165
|
-
const months28 = [
|
|
166
|
-
const isLeap = (
|
|
184
|
+
const months31 = [1, 3, 5, 7, 8, 10, 12];
|
|
185
|
+
const months30 = [4, 6, 9, 11];
|
|
186
|
+
const months28 = [2];
|
|
187
|
+
const isLeap = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
|
167
188
|
if (year != null && month != null && day != null) {
|
|
168
189
|
const isDayValid = day > 0;
|
|
169
|
-
const isMonthValid =
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
190
|
+
const isMonthValid =
|
|
191
|
+
(months31.indexOf(parseInt(month)) != -1 && day <= 31) ||
|
|
192
|
+
(months30.indexOf(month) != -1 && day <= 30) ||
|
|
193
|
+
(months30.indexOf(month) != -1 && day <= 31) ||
|
|
194
|
+
(months28.indexOf(month) != -1 && day <= 28) ||
|
|
195
|
+
(months28.indexOf(month) != -1 && day <= 29 && isLeap);
|
|
174
196
|
return isDayValid && isMonthValid;
|
|
175
197
|
}
|
|
176
198
|
return false;
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
static checkValidTime(hour, minute, second) {
|
|
180
|
-
if (
|
|
202
|
+
if (
|
|
203
|
+
hour >= 0 &&
|
|
204
|
+
hour < 24 &&
|
|
205
|
+
minute >= 0 &&
|
|
206
|
+
minute < 60 &&
|
|
207
|
+
second >= 0 &&
|
|
208
|
+
second < 60
|
|
209
|
+
) {
|
|
181
210
|
return true;
|
|
182
211
|
}
|
|
183
212
|
return false;
|
|
@@ -185,11 +214,18 @@ export default class DatePickerHelper {
|
|
|
185
214
|
|
|
186
215
|
static calculateDateSinceYearAgo(yearAgo) {
|
|
187
216
|
let nowDate = new Date();
|
|
188
|
-
nowDate = new Date(
|
|
217
|
+
nowDate = new Date(
|
|
218
|
+
nowDate.getFullYear() - yearAgo,
|
|
219
|
+
nowDate.getMonth(),
|
|
220
|
+
nowDate.getDate(),
|
|
221
|
+
);
|
|
189
222
|
return nowDate;
|
|
190
223
|
}
|
|
191
224
|
|
|
192
|
-
static getMaxDate(
|
|
225
|
+
static getMaxDate(
|
|
226
|
+
month = new Date().getMonth(),
|
|
227
|
+
year = new Date().getFullYear(),
|
|
228
|
+
) {
|
|
193
229
|
const monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
194
230
|
// Adjust for leap years
|
|
195
231
|
if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) {
|
|
@@ -201,5 +237,5 @@ export default class DatePickerHelper {
|
|
|
201
237
|
|
|
202
238
|
static capitalizeFirstLetter(string) {
|
|
203
239
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
204
|
-
|
|
240
|
+
}
|
|
205
241
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
2
|
+
"name": "@momo-kits/date-picker",
|
|
3
|
+
"version": "0.0.66-alpha.11",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@momo-kits/core-v2": ">=0.0.5-beta",
|
|
9
|
+
"lodash": "^4.17.15",
|
|
10
|
+
"prop-types": "^15.7.2",
|
|
11
|
+
"react": "16.9.0",
|
|
12
|
+
"react-native": ">=0.55"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {},
|
|
15
|
+
"license": "MoMo"
|
|
16
|
+
}
|