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