@momo-kits/date-picker 0.73.3-beta.5 → 0.74.2-react-native.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.
@@ -1,136 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import React, {useState} from 'react';
3
- import {StyleSheet} from 'react-native';
4
- import {isEmpty} from 'lodash';
5
- import {
6
- IconSource,
7
- TouchableOpacity,
8
- Text,
9
- Colors,
10
- ValueUtil,
11
- Image,
12
- Radius,
13
- } from '@momo-kits/core-v2';
14
- import DatePicker from './DatePicker';
15
-
16
- const DatePickerInput = ({
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,
33
- }) => {
34
- const [selected, setSelected] = useState(defaultDate || '');
35
-
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;
58
-
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
- );
82
- };
83
-
84
- DatePickerInput.propTypes = {
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,
101
- };
102
- DatePickerInput.defaultProps = {
103
- showRightIcon: true,
104
- };
105
-
106
- export default DatePickerInput;
107
-
108
- const styles = StyleSheet.create({
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
- },
136
- });
@@ -1,208 +0,0 @@
1
- import React, {Component} from 'react';
2
- import {Dimensions, StyleSheet, View} from 'react-native';
3
- import {
4
- Button,
5
- IconSource,
6
- TouchableOpacity,
7
- Text,
8
- Colors,
9
- Image,
10
- DeviceUtils,
11
- SwitchLanguage,
12
- } from '@momo-kits/core-v2';
13
- import WheelPicker from './WheelPicker';
14
-
15
- const {isIphoneX} = DeviceUtils;
16
-
17
- const widthScreen = Dimensions.get('window').width;
18
-
19
- export default class ListPicker extends Component {
20
- constructor(props) {
21
- super(props);
22
- this.data = 0;
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);
45
- }
46
- };
47
-
48
- onChangeValue = value => {
49
- const {callback} = this.props;
50
- if (typeof callback === 'function') {
51
- callback(value);
52
- }
53
- };
54
-
55
- onPressClear = () => {
56
- this.hide();
57
- };
58
-
59
- onPressChoose = () => {
60
- this.onChangeValue(this.data);
61
- this.hide();
62
- };
63
-
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
- );
75
-
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
- );
88
-
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
- }
103
-
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
- }
124
-
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
- }
154
- }
155
-
156
- const styles = StyleSheet.create({
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
- },
208
- });
@@ -1,328 +0,0 @@
1
- import React, {Component} from 'react';
2
- import {Dimensions, View} from 'react-native';
3
- import {LinearGradient, Text, Colors, ScaleSize} from '@momo-kits/core-v2';
4
- import ScrollCustom from './custom/ScrollCustom';
5
- import DatePickerHelper from './helper/DatePickerHelper';
6
-
7
- const widthScreen = Dimensions.get('window').width;
8
- // var heightScreen = Dimensions.get('window').height;
9
-
10
- export default class WheelPicker extends Component {
11
- constructor(props) {
12
- super(props);
13
- const {heightItem, value: valueItem, numberItem, arrayValue} = this.props;
14
- const value = valueItem === -1 ? 0 : valueItem;
15
- this.heightItem = heightItem;
16
- this.currentPosition = value * this.heightItem;
17
- this.prePosition = this.currentPosition;
18
- this.numberItem = this.convertNumberItem(numberItem);
19
- this.isDragging = false;
20
- this.state = {
21
- // height: 100,
22
- width: widthScreen / 3,
23
- value,
24
- items: arrayValue,
25
- };
26
- }
27
-
28
- componentDidMount() {
29
- const {value} = this.props;
30
- console.log(value);
31
- this.scrollToPosition(value);
32
- }
33
-
34
- componentWillUnmounted() {
35
- clearTimeout(this.timer);
36
- clearTimeout(this.timerUpdate);
37
- }
38
-
39
- scrollToPosition(position) {
40
- this.currentPosition = position * this.heightItem;
41
- clearTimeout(this.timer);
42
- this.timer = setTimeout(() => {
43
- if (this.ScrollWheelPicker && this.ScrollWheelPicker.scrollTo) {
44
- this.ScrollWheelPicker.scrollTo({y: this.currentPosition});
45
- }
46
- }, 500);
47
- }
48
-
49
- update(param) {
50
- this.setState(
51
- {
52
- items: param.arrayValue,
53
- value: param.value,
54
- },
55
- () => {
56
- clearTimeout(this.timerUpdate);
57
- this.timerUpdate = setTimeout(() => {
58
- this.scrollToPosition(param.value);
59
- }, 100);
60
- },
61
- );
62
- }
63
-
64
- setScrollEnabled(enable) {
65
- if (
66
- this.ScrollWheelPicker &&
67
- this.ScrollWheelPicker.setScrollEnabled &&
68
- !this.isDragging
69
- ) {
70
- this.ScrollWheelPicker.setScrollEnabled(enable);
71
- }
72
- }
73
-
74
- onValueChange() {
75
- if (this.currentPosition != null) {
76
- const {value} = this.state;
77
- const {onValueChange, onEndDrag, refName} = this.props;
78
- const position = this.parseInteger(
79
- this.currentPosition / this.heightItem,
80
- );
81
- if (position !== value) {
82
- this.setState(
83
- {
84
- value: position,
85
- },
86
- () => {
87
- this.scrollToPosition(position);
88
- },
89
- );
90
- }
91
- if (onValueChange) {
92
- onValueChange(position);
93
- }
94
- if (onEndDrag) {
95
- onEndDrag(refName);
96
- }
97
- }
98
- }
99
-
100
- parseInteger(number) {
101
- const mode = (number * 10) % 10;
102
- if (mode > 5) {
103
- return parseInt(number, 10) + 1;
104
- }
105
- return parseInt(number, 10);
106
- }
107
-
108
- checkEvenNumber(number) {
109
- const mode = number % 2;
110
- if (mode > 0) {
111
- return false;
112
- }
113
- return true;
114
- }
115
-
116
- convertNumberItem(number) {
117
- let numberItem = number;
118
- if (this.checkEvenNumber(numberItem)) {
119
- numberItem += 1;
120
- }
121
-
122
- return numberItem;
123
- }
124
-
125
- renderHiddenItem(numberItem, heightItem, offset = 0) {
126
- const numberItemTop = parseInt(numberItem / 2, 10) - offset;
127
- const view = [];
128
- // eslint-disable-next-line no-plusplus
129
- for (let i = 0; i < numberItemTop; i++) {
130
- view.push(
131
- <View
132
- key={`itemTop${i}`}
133
- style={{
134
- flex: 1,
135
- height: heightItem,
136
- }}
137
- />,
138
- );
139
- }
140
-
141
- return view;
142
- }
143
-
144
- onStartDrag(rawPosition) {
145
- this.currentPosition = rawPosition;
146
- const {onBeginDrag, refName} = this.props;
147
- this.isDragging = true;
148
- if (onBeginDrag) {
149
- onBeginDrag(refName);
150
- }
151
- this.createCheckDragging();
152
- }
153
-
154
- onEndDrag() {
155
- if (this.isDragging) {
156
- this.isDragging = false;
157
- this.onValueChange();
158
- }
159
- if (this.checkEndDrag) {
160
- clearInterval(this.checkEndDrag);
161
- }
162
- }
163
-
164
- createCheckDragging() {
165
- this.checkEndDrag = setInterval(() => {
166
- this.checkPosition();
167
- }, 50);
168
- }
169
-
170
- checkPosition() {
171
- if (this.currentPosition === this.prePosition) {
172
- this.onEndDrag();
173
- } else {
174
- this.prePosition = this.currentPosition;
175
- }
176
- }
177
-
178
- render() {
179
- const numberHiddenItem = parseInt(this.numberItem / 2, 10);
180
- const positionCenter = parseInt(this.heightItem * numberHiddenItem, 10);
181
- const heightContain = parseInt(this.heightItem * this.numberItem, 10);
182
- const {items, value, width} = this.state;
183
- const {preFix, bottomOffset} = this.props;
184
- return (
185
- <View
186
- style={{
187
- flex: 1,
188
- height: heightContain + 40,
189
- }}>
190
- <Text.Description2
191
- weight="semibold"
192
- style={{
193
- color: Colors.black_17,
194
- marginLeft: 6,
195
- marginBottom: 3,
196
- }}>
197
- {DatePickerHelper.capitalizeFirstLetter(preFix || '')}
198
- </Text.Description2>
199
- <View
200
- style={{
201
- flex: 1,
202
- height: heightContain,
203
- marginHorizontal: 6,
204
- paddingBottom: 20,
205
- borderWidth: 1,
206
- borderColor: Colors.black_04,
207
- borderRadius: 8,
208
- overflow: 'hidden',
209
- }}
210
- onLayout={event => {
211
- if (
212
- event &&
213
- event.nativeEvent &&
214
- event.nativeEvent.layout &&
215
- event.nativeEvent.layout.height &&
216
- event.nativeEvent.layout.width
217
- ) {
218
- this.setState({
219
- // height: event.nativeEvent.layout.height,
220
- width: event.nativeEvent.layout.width,
221
- });
222
- }
223
- }}>
224
- <View
225
- style={{
226
- position: 'absolute',
227
- top: positionCenter,
228
- left: 0,
229
- height: this.heightItem, // + 12,
230
- width,
231
- backgroundColor: '#f2f8ff',
232
- }}
233
- />
234
-
235
- <ScrollCustom
236
- ref={refName => {
237
- this.ScrollWheelPicker = refName;
238
- }}
239
- onScrollEndDrag={event => {
240
- if (
241
- event &&
242
- event.nativeEvent &&
243
- event.nativeEvent.contentOffset &&
244
- event.nativeEvent.contentOffset.y != null &&
245
- !this.isDragging
246
- ) {
247
- this.onStartDrag(event.nativeEvent.contentOffset.y);
248
- }
249
- }}
250
- onScroll={event => {
251
- if (
252
- event &&
253
- event.nativeEvent &&
254
- event.nativeEvent.contentOffset &&
255
- event.nativeEvent.contentOffset.y != null
256
- ) {
257
- this.currentPosition = event.nativeEvent.contentOffset.y;
258
- }
259
- }}>
260
- {this.renderHiddenItem(this.numberItem, this.heightItem)}
261
- {items.map((valueItem, index) => (
262
- <View
263
- // eslint-disable-next-line react/no-array-index-key
264
- key={index}
265
- style={{
266
- flex: 1,
267
- height: this.heightItem,
268
- justifyContent: 'center',
269
- alignItems: 'center',
270
- }}>
271
- <Text.Action2
272
- weight={value === index ? 'bold' : 'semibold'}
273
- style={{
274
- color: value === index ? Colors.black_17 : Colors.black_12,
275
-
276
- fontSize: 15,
277
- }}>
278
- {valueItem}
279
- {/* {reversePreFix ? `${valueItem} ${preFix}` : `${preFix} ${valueItem}`} */}
280
- </Text.Action2>
281
- </View>
282
- ))}
283
- {this.renderHiddenItem(
284
- this.numberItem,
285
- this.heightItem,
286
- bottomOffset,
287
- )}
288
- </ScrollCustom>
289
- <LinearGradient
290
- pointerEvents="none"
291
- locations={[0.2, 0.85]}
292
- colors={['rgba(255, 255, 255, 1)', 'rgba(255, 255, 255, 0)']}
293
- style={{
294
- height: this.heightItem * 2,
295
- width,
296
- position: 'absolute',
297
- top: 0,
298
- overflow: 'hidden',
299
- }}
300
- />
301
- <LinearGradient
302
- pointerEvents="none"
303
- locations={[0, 0.85]}
304
- colors={['rgba(255, 255, 255, 0)', 'rgba(255, 255, 255, 1)']}
305
- style={{
306
- height: this.heightItem * 2,
307
- width,
308
- position: 'absolute',
309
- bottom: 0,
310
- overflow: 'hidden',
311
- }}
312
- />
313
- </View>
314
- </View>
315
- );
316
- }
317
- }
318
-
319
- WheelPicker.defaultProps = {
320
- arrayValue: [],
321
- preFix: '',
322
- value: 0,
323
- heightItem: 42,
324
- numberItem: 5,
325
- bottomOffset: 0,
326
- };
327
-
328
- module.exports = WheelPicker;