@momo-kits/date-picker 0.0.71-beta → 0.0.71-beta.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,604 +1,770 @@
1
1
  /* eslint-disable max-len */
2
2
  /* eslint-disable react/no-unused-prop-types */
3
- import React, { Component } from 'react';
4
- import {
5
- View, StyleSheet, Dimensions
6
- } from 'react-native';
3
+ import React, {Component} from 'react';
4
+ import {View, StyleSheet, Dimensions} from 'react-native';
7
5
  import PropTypes from 'prop-types';
8
6
  import {
9
- BottomPopupHeader, Button, Text, ScreenUtils, SwitchLanguage, Spacing
10
- } from '@momo-kits/core';
7
+ BottomPopupHeader,
8
+ Button,
9
+ Text,
10
+ ScreenUtils,
11
+ SwitchLanguage,
12
+ Spacing,
13
+ Colors,
14
+ } from '@momo-kits/core-v2';
11
15
  import WheelPicker from './WheelPicker';
12
16
  import DatePickerHelper from './helper/DatePickerHelper';
13
17
 
14
- const { ifIphoneX } = ScreenUtils;
18
+ const {ifIphoneX} = ScreenUtils;
15
19
 
16
20
  const widthScreen = Dimensions.get('window').width;
17
21
  const styles = StyleSheet.create({
18
- container: {
19
- width: widthScreen,
20
- alignItems: 'center',
21
- justifyContent: 'center',
22
- paddingHorizontal: 6,
23
- },
24
- content: {
25
- flexDirection: 'row',
26
- width: widthScreen,
27
- alignItems: 'center',
28
- justifyContent: 'center',
29
- },
30
- column: {
31
- borderWidth: 2,
32
- borderColor: 'red',
33
- },
34
- header: {
35
- borderRadius: 16,
36
- marginBottom: 0, // Spacing.S,
37
- },
38
- view: {
39
- backgroundColor: 'white',
40
- borderTopRightRadius: 16,
41
- borderTopLeftRadius: 16,
42
- overflow: 'hidden'
43
- },
44
- titleCancel: {
45
- fontSize: 17,
46
- color: '#4A90E2'
47
- },
48
- titleConfirm: {
49
- fontSize: 17,
50
- color: '#4A90E2',
51
- textAlign: 'right'
52
- }
22
+ container: {
23
+ width: widthScreen,
24
+ alignItems: 'center',
25
+ justifyContent: 'center',
26
+ paddingHorizontal: 6,
27
+ },
28
+ content: {
29
+ flexDirection: 'row',
30
+ width: widthScreen,
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ paddingHorizontal: 21,
34
+ paddingTop: 12,
35
+ },
36
+ column: {
37
+ borderWidth: 2,
38
+ borderColor: 'red',
39
+ },
40
+ header: {
41
+ borderTopLeftRadius: 12,
42
+ borderTopRightRadius: 12,
43
+ //backgroundColor:'red',
44
+ height: 64,
45
+ borderBottomColor: Colors.black_04,
46
+ borderBottomWidth: 1,
47
+ alignItems: 'center',
48
+ justifyContent: 'center',
49
+ marginBottom: 0, // Spacing.S,
50
+ },
51
+ view: {
52
+ backgroundColor: 'white',
53
+ borderTopRightRadius: 16,
54
+ borderTopLeftRadius: 16,
55
+ overflow: 'hidden',
56
+ },
57
+ titleCancel: {
58
+ fontSize: 17,
59
+ color: '#4A90E2',
60
+ },
61
+ titleConfirm: {
62
+ fontSize: 17,
63
+ color: '#4A90E2',
64
+ textAlign: 'right',
65
+ },
53
66
  });
54
67
 
55
- const getStrings = (strings) => (strings?.length === 1 ? `0${strings}` : strings);
68
+ const getStrings = strings => (strings?.length === 1 ? `0${strings}` : strings);
69
+
56
70
  class DatePicker extends Component {
57
- constructor(props) {
58
- super(props);
59
- this.initDefault(props);
71
+ constructor(props) {
72
+ super(props);
73
+ this.initDefault(props);
74
+ }
75
+
76
+ // onBackPress = () => {
77
+ // this.hide();
78
+ // return true;
79
+ // }
80
+
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
+
90
+ this.setStateMonth(this.dayIndex, this.monthIndex, this.yearIndex);
91
+ const {onCreateRef} = this.props;
92
+ if (typeof onCreateRef === 'function') onCreateRef(this);
93
+ }
94
+
95
+ componentWillUnmount() {
96
+ // BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
97
+ }
98
+
99
+ initDefault(props) {
100
+ if (props) {
101
+ const propsMinDate = props.minDate ? props.minDate : props.minValue;
102
+ const propsMaxDate = props.maxDate ? props.maxDate : props.maxValue;
103
+ const propsSelectedDate = props.selectedDate
104
+ ? props.selectedDate
105
+ : props.value;
106
+
107
+ if (propsMinDate) {
108
+ this.minDate = DatePickerHelper.formatDate(propsMinDate, props.format);
109
+ } else if (props.maxAge) {
110
+ this.minDate = DatePickerHelper.calculateDateSinceYearAgo(props.maxAge);
111
+ } else {
112
+ this.minDate = null;
113
+ }
114
+
115
+ if (propsMaxDate) {
116
+ this.maxDate = DatePickerHelper.formatDate(propsMaxDate, props.format);
117
+ } else if (props.minAge) {
118
+ this.maxDate = DatePickerHelper.calculateDateSinceYearAgo(props.minAge);
119
+ } else {
120
+ this.maxDate = null;
121
+ }
122
+
123
+ if (
124
+ this.maxDate &&
125
+ this.minDate &&
126
+ this.maxDate.getTime() < this.minDate.getTime()
127
+ ) {
128
+ this.maxDate = null;
129
+ this.minDate = null;
130
+ }
131
+
132
+ if (propsSelectedDate) {
133
+ this.selectedDate = DatePickerHelper.formatDate(
134
+ propsSelectedDate,
135
+ props.format,
136
+ );
137
+ if (this.selectedDate) {
138
+ if (
139
+ this.minDate &&
140
+ this.selectedDate.getTime() < this.minDate.getTime()
141
+ ) {
142
+ this.selectedDate = null;
143
+ } else if (
144
+ this.maxDate &&
145
+ this.maxDate.getTime() < this.selectedDate.getTime()
146
+ ) {
147
+ this.selectedDate = null;
148
+ }
149
+ }
150
+ } else {
151
+ this.selectedDate = null;
152
+ }
153
+ if (props.format === 'hh:mm') {
154
+ this.selectedDate = props.isRanged
155
+ ? {
156
+ from: DatePickerHelper.formatDate(
157
+ propsSelectedDate.from,
158
+ props.format,
159
+ ),
160
+ to: DatePickerHelper.formatDate(
161
+ propsSelectedDate.to,
162
+ props.format,
163
+ ),
164
+ }
165
+ : DatePickerHelper.formatDate(propsSelectedDate, props.format);
166
+ }
60
167
  }
61
-
62
- // onBackPress = () => {
63
- // this.hide();
64
- // return true;
65
- // }
66
-
67
- componentDidMount() {
68
- // BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
69
- // BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
70
-
71
- // setTimeout(() => {
72
- // BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
73
- // BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
74
- // }, 200);
75
-
76
- this.setStateMonth(this.dayIndex, this.monthIndex, this.yearIndex);
77
- const { onCreateRef } = this.props;
78
- if (typeof onCreateRef === 'function') onCreateRef(this);
168
+ this.createDataDate(
169
+ this.minDate,
170
+ this.maxDate,
171
+ props.minuteArray,
172
+ props.startTime,
173
+ props.endTime,
174
+ props.rangeHour,
175
+ );
176
+ this.selectedIndexDate();
177
+ }
178
+
179
+ createDataDate(minDate, maxDate, minuteArray, startTime, endTime, rangeHour) {
180
+ this.minDay = 1;
181
+ this.minMonth = 1;
182
+ this.minYear = 1970;
183
+
184
+ this.maxDay = 31;
185
+ this.maxMonth = 12;
186
+ this.maxYear = 2100;
187
+ if (minDate) {
188
+ this.minDay = minDate.getDate();
189
+ this.minMonth = minDate.getMonth() + 1;
190
+ this.minYear = minDate.getFullYear();
79
191
  }
80
-
81
- componentWillUnmount() {
82
- // BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
192
+ if (maxDate) {
193
+ this.maxDay = maxDate.getDate();
194
+ this.maxMonth = maxDate.getMonth() + 1;
195
+ this.maxYear = maxDate.getFullYear();
83
196
  }
84
-
85
- initDefault(props) {
86
- if (props) {
87
- const propsMinDate = props.minDate ? props.minDate : props.minValue;
88
- const propsMaxDate = props.maxDate ? props.maxDate : props.maxValue;
89
- const propsSelectedDate = props.selectedDate ? props.selectedDate : props.value;
90
-
91
- if (propsMinDate) {
92
- this.minDate = DatePickerHelper.formatDate(propsMinDate, props.format);
93
- } else if (props.maxAge) {
94
- this.minDate = DatePickerHelper.calculateDateSinceYearAgo(props.maxAge);
95
- } else {
96
- this.minDate = null;
97
- }
98
-
99
- if (propsMaxDate) {
100
- this.maxDate = DatePickerHelper.formatDate(propsMaxDate, props.format);
101
- } else if (props.minAge) {
102
- this.maxDate = DatePickerHelper.calculateDateSinceYearAgo(props.minAge);
103
- } else {
104
- this.maxDate = null;
105
- }
106
-
107
- if (this.maxDate && this.minDate && this.maxDate.getTime() < this.minDate.getTime()) {
108
- this.maxDate = null;
109
- this.minDate = null;
110
- }
111
-
112
- if (propsSelectedDate) {
113
- this.selectedDate = DatePickerHelper.formatDate(propsSelectedDate, props.format);
114
- if (this.selectedDate) {
115
- if (this.minDate && this.selectedDate.getTime() < this.minDate.getTime()) {
116
- this.selectedDate = null;
117
- } else if (this.maxDate && this.maxDate.getTime() < this.selectedDate.getTime()) {
118
- this.selectedDate = null;
119
- }
120
- }
121
- } else {
122
- this.selectedDate = null;
123
- }
124
- if (props.format === 'hh:mm') {
125
- this.selectedDate = props.isRanged ? {
126
- from: DatePickerHelper.formatDate(propsSelectedDate.from, props.format),
127
- to: DatePickerHelper.formatDate(propsSelectedDate.to, props.format)
128
- } : DatePickerHelper.formatDate(propsSelectedDate, props.format);
129
- }
130
- }
131
- this.createDataDate(this.minDate, this.maxDate, props.minuteArray, props.rangeHour);
132
- this.selectedIndexDate();
197
+ this.days = DatePickerHelper.makeRange(1, 31);
198
+ this.months = DatePickerHelper.makeRange(1, 12);
199
+ this.years = DatePickerHelper.makeRange(this.minYear, this.maxYear);
200
+ this.hours = DatePickerHelper.makeRange(0, 23, true);
201
+ if (Array.isArray(minuteArray)) {
202
+ this.minutes = minuteArray;
203
+ } else {
204
+ this.minutes = DatePickerHelper.makeRange(0, 59, true);
133
205
  }
134
-
135
- createDataDate(minDate, maxDate, minuteArray, rangeHour) {
136
- this.minDay = 1;
137
- this.minMonth = 1;
138
- this.minYear = 1970;
139
-
140
- this.maxDay = 31;
141
- this.maxMonth = 12;
142
- this.maxYear = 2100;
143
- if (minDate) {
144
- this.minDay = minDate.getDate();
145
- this.minMonth = minDate.getMonth() + 1;
146
- this.minYear = minDate.getFullYear();
147
- }
148
- if (maxDate) {
149
- this.maxDay = maxDate.getDate();
150
- this.maxMonth = maxDate.getMonth() + 1;
151
- this.maxYear = maxDate.getFullYear();
152
- }
153
- this.days = DatePickerHelper.makeRange(1, 31);
154
- this.months = DatePickerHelper.makeRange(1, 12);
155
- this.years = DatePickerHelper.makeRange(this.minYear, this.maxYear);
156
- this.hours = DatePickerHelper.makeRange(0, 23, true);
157
- if (Array.isArray(minuteArray)) {
158
- this.minutes = minuteArray;
159
- } else {
160
- this.minutes = DatePickerHelper.makeRange(0, 59, true);
161
- }
162
- this.ranged = rangeHour || DatePickerHelper.arrayRange;
206
+ this.ranged = rangeHour || DatePickerHelper.arrayRange;
207
+ }
208
+
209
+ selectedIndexDate() {
210
+ const {format, isRanged} = this.props;
211
+ let current = new Date();
212
+ if (this.minDate && current.getTime() < this.minDate.getTime()) {
213
+ current = this.minDate;
214
+ } else if (this.maxDate && current.getTime() > this.maxDate.getTime()) {
215
+ current = this.maxDate;
163
216
  }
217
+ if (format === 'hh:mm' && isRanged) {
218
+ const valueHours_1 = this.selectedDate?.from
219
+ ? `${getStrings(
220
+ this.selectedDate?.from?.getHours()?.toString(),
221
+ )}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}`
222
+ : '00:00';
223
+ const valueHours_2 = this.selectedDate?.to
224
+ ? `${getStrings(
225
+ this.selectedDate?.to?.getHours()?.toString(),
226
+ )}:${getStrings(this.selectedDate?.to?.getMinutes()?.toString())}`
227
+ : '00:00';
228
+ this.hourRangeIndex_1 = valueHours_1
229
+ ? this.ranged.indexOf(valueHours_1)
230
+ : this.ranged.indexOf(
231
+ `${current.getHours().toString()}:${current
232
+ .getMinutes()
233
+ .toString()}`,
234
+ );
235
+
236
+ this.hourRangeIndex_2 = valueHours_2
237
+ ? this.ranged.indexOf(valueHours_2)
238
+ : this.ranged.indexOf(
239
+ `${current.getHours().toString()}:${current
240
+ .getMinutes()
241
+ .toString()}`,
242
+ );
243
+ return;
244
+ }
245
+ this.dayIndex = this.selectedDate
246
+ ? this.days.indexOf(this.selectedDate.getDate().toString())
247
+ : this.days.indexOf(current.getDate().toString());
248
+
249
+ this.monthIndex = this.selectedDate
250
+ ? this.months.indexOf((this.selectedDate.getMonth() + 1).toString())
251
+ : this.months.indexOf((current.getMonth() + 1).toString());
252
+
253
+ this.yearIndex = this.selectedDate
254
+ ? this.years.indexOf(this.selectedDate.getFullYear().toString())
255
+ : this.years.indexOf(current.getFullYear().toString());
256
+
257
+ if (format === 'hh:mm' && !isRanged) {
258
+ const valueHours = this.selectedDate
259
+ ? this.selectedDate?.getHours()?.toString()?.length === 1
260
+ ? `0${this.selectedDate.getHours().toString()}`
261
+ : this.selectedDate?.getHours()?.toString() || ''
262
+ : '';
263
+ const valueMinute = this.selectedDate
264
+ ? this.selectedDate?.getMinutes()?.toString()?.length === 1
265
+ ? `0${this.selectedDate.getMinutes().toString()}`
266
+ : this.selectedDate?.getMinutes()?.toString() || ''
267
+ : '';
268
+
269
+ this.hourIndex = this.selectedDate
270
+ ? this.hours.indexOf(valueHours)
271
+ : this.hours.indexOf(
272
+ current.getHours().toString().length === 1
273
+ ? `0${current.getHours().toString()}`
274
+ : current.getHours().toString(),
275
+ );
276
+
277
+ this.minuteIndex = this.selectedDate
278
+ ? this.minutes.indexOf(valueMinute)
279
+ : this.minutes.indexOf(
280
+ current.getMinutes().toString().length === 1
281
+ ? `0${current.getMinutes().toString()}`
282
+ : current.getMinutes().toString(),
283
+ );
284
+ }
285
+ }
286
+
287
+ onBeginDrag = refName => {
288
+ // eslint-disable-next-line no-restricted-syntax
289
+ for (const i in this.arrayRef) {
290
+ if (
291
+ i &&
292
+ i !== refName &&
293
+ this.arrayRef &&
294
+ this.arrayRef[i] &&
295
+ this.arrayRef[i].update
296
+ ) {
297
+ this.arrayRef[i].setScrollEnabled(false);
298
+ }
299
+ }
300
+ };
301
+
302
+ onEndDrag = refName => {
303
+ // eslint-disable-next-line no-restricted-syntax
304
+ for (const i in this.arrayRef) {
305
+ if (
306
+ i &&
307
+ i !== refName &&
308
+ this.arrayRef &&
309
+ this.arrayRef[i] &&
310
+ this.arrayRef[i].update
311
+ ) {
312
+ this.arrayRef[i].setScrollEnabled(true);
313
+ }
314
+ }
315
+ };
164
316
 
165
- selectedIndexDate() {
166
- const { format, isRanged } = this.props;
167
- let current = new Date();
168
- if (this.minDate && current.getTime() < this.minDate.getTime()) {
169
- current = this.minDate;
170
- } else if (this.maxDate && current.getTime() > this.maxDate.getTime()) {
171
- current = this.maxDate;
172
- }
173
- if (format === 'hh:mm' && isRanged) {
174
- const valueHours_1 = this.selectedDate ? `${getStrings(this.selectedDate?.from?.getHours()?.toString())}:${getStrings(this.selectedDate?.from?.getMinutes()?.toString())}` : '';
175
-
176
- const valueHours_2 = this.selectedDate ? `${getStrings(this.selectedDate?.to?.getHours()?.toString())}:${getStrings(this.selectedDate?.to?.getMinutes()?.toString())}` : '';
177
-
178
- this.hourRangeIndex_1 = this.selectedDate
179
- ? this.ranged.indexOf(valueHours_1)
180
- : this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
181
-
182
- this.hourRangeIndex_2 = this.selectedDate
183
- ? this.ranged.indexOf(valueHours_2)
184
- : this.ranged.indexOf(`${current.getHours().toString()}:${current.getMinutes().toString()}`);
185
- return;
186
- }
187
- this.dayIndex = this.selectedDate
188
- ? this.days.indexOf(this.selectedDate.getDate().toString())
189
- : this.days.indexOf(current.getDate().toString());
190
-
191
- this.monthIndex = this.selectedDate
192
- ? this.months.indexOf((this.selectedDate.getMonth() + 1).toString())
193
- : this.months.indexOf((current.getMonth() + 1).toString());
194
-
195
- this.yearIndex = this.selectedDate
196
- ? this.years.indexOf(this.selectedDate.getFullYear().toString())
197
- : this.years.indexOf(current.getFullYear().toString());
198
-
199
- if (format === 'hh:mm' && !isRanged) {
200
- const valueHours = this.selectedDate ? this.selectedDate?.getHours()?.toString()?.length === 1 ? `0${this.selectedDate.getHours().toString()}` : this.selectedDate?.getHours()?.toString() || '' : '';
201
- const valueMinute = this.selectedDate ? this.selectedDate?.getMinutes()?.toString()?.length === 1 ? `0${this.selectedDate.getMinutes().toString()}` : this.selectedDate?.getMinutes()?.toString() || '' : '';
202
-
203
- this.hourIndex = this.selectedDate
204
- ? this.hours.indexOf(valueHours)
205
- : this.hours.indexOf(current.getHours().toString());
317
+ show = () => {};
206
318
 
207
- this.minuteIndex = this.selectedDate
208
- ? this.minutes.indexOf(valueMinute)
209
- : this.minutes.indexOf(current.getMinutes().toString());
319
+ hide = () => {
320
+ const {onClose, requestClose} = this.props;
321
+ if (requestClose && typeof requestClose === 'function') {
322
+ requestClose(() => {
323
+ if (onClose && typeof onClose === 'function') {
324
+ onClose();
210
325
  }
326
+ });
211
327
  }
212
-
213
- onBeginDrag = (refName) => {
214
- // eslint-disable-next-line no-restricted-syntax
215
- for (const i in this.arrayRef) {
216
- if (i && i !== refName && this.arrayRef && this.arrayRef[i] && this.arrayRef[i].update) {
217
- this.arrayRef[i].setScrollEnabled(false);
218
- }
219
- }
328
+ };
329
+
330
+ finish = () => {
331
+ const {format, onSelected, isRanged, selectedDate} = this.props;
332
+ if (isRanged && format === 'hh:mm') {
333
+ const from = this.ranged[this.hourRangeIndex_1];
334
+ const to = this.ranged[this.hourRangeIndex_2];
335
+
336
+ if (onSelected && typeof onSelected === 'function') {
337
+ onSelected({
338
+ from,
339
+ to,
340
+ });
341
+ }
342
+ this.hide();
343
+ return;
220
344
  }
221
-
222
- onEndDrag = (refName) => {
223
- // eslint-disable-next-line no-restricted-syntax
224
- for (const i in this.arrayRef) {
225
- if (i && i !== refName && this.arrayRef && this.arrayRef[i] && this.arrayRef[i].update) {
226
- this.arrayRef[i].setScrollEnabled(true);
227
- }
228
- }
345
+ const day = this.days[this.dayIndex];
346
+ const month = this.months[this.monthIndex];
347
+ const year = this.years[this.yearIndex];
348
+ const hour = this.hours[this.hourIndex] || '00';
349
+ const minute = this.minutes[this.minuteIndex] || '00';
350
+ const selectedDateFormatted = DatePickerHelper.toString(
351
+ day,
352
+ month,
353
+ year,
354
+ hour,
355
+ minute,
356
+ format,
357
+ );
358
+ if (onSelected && typeof onSelected === 'function') {
359
+ onSelected(
360
+ selectedDateFormatted ||
361
+ selectedDate ||
362
+ DatePickerHelper.getCurrentDate(format),
363
+ );
229
364
  }
230
-
231
- show = () => {
232
-
365
+ this.hide();
366
+ };
367
+
368
+ renderUpdate(param) {
369
+ if (param && param.day != null) {
370
+ this.dayIndex = param.day;
371
+ this.updateWheelPiker('DayView', {
372
+ arrayValue: this.days,
373
+ value: param.day,
374
+ });
233
375
  }
234
376
 
235
- hide = () => {
236
- const { onClose, requestClose } = this.props;
237
- if (requestClose && typeof requestClose === 'function') {
238
- requestClose(() => {
239
- if (onClose && typeof onClose === 'function') {
240
- onClose();
241
- }
242
- });
243
- }
377
+ if (param && param.month != null) {
378
+ this.monthIndex = param.month;
379
+ this.updateWheelPiker('MonthView', {
380
+ arrayValue: this.months,
381
+ value: param.month,
382
+ });
244
383
  }
245
384
 
246
- finish = () => {
247
- const {
248
- format, onSelected, isRanged, selectedDate
249
- } = this.props;
250
- if (isRanged && format === 'hh:mm') {
251
- const from = this.ranged[this.hourRangeIndex_1];
252
- const to = this.ranged[this.hourRangeIndex_2];
253
- if (onSelected && typeof onSelected === 'function') {
254
- onSelected({ from, to });
255
- }
256
- this.hide();
257
- return;
258
- }
259
- const day = this.days[this.dayIndex];
260
- const month = this.months[this.monthIndex];
261
- const year = this.years[this.yearIndex];
262
- const hour = this.hours[this.hourIndex];
263
- const minute = this.minutes[this.minuteIndex];
264
-
265
- const selectedDateFormatted = DatePickerHelper.toString(day, month, year, hour, minute, format);
266
-
267
- if (onSelected && typeof onSelected === 'function') {
268
- onSelected(selectedDateFormatted || selectedDate || DatePickerHelper.getCurrentDate(format));
269
- }
270
- this.hide();
385
+ if (param && param.year != null) {
386
+ this.yearIndex = param.year;
387
+ this.updateWheelPiker('YearView', {
388
+ arrayValue: this.years,
389
+ value: param.year,
390
+ });
271
391
  }
272
392
 
273
- renderUpdate(param) {
274
- if (param && param.day != null) {
275
- this.dayIndex = param.day;
276
- this.updateWheelPiker('DayView', {
277
- arrayValue: this.days,
278
- value: param.day
279
- });
280
- }
281
-
282
- if (param && param.month != null) {
283
- this.monthIndex = param.month;
284
- this.updateWheelPiker('MonthView', {
285
- arrayValue: this.months,
286
- value: param.month
287
- });
288
- }
289
-
290
- if (param && param.year != null) {
291
- this.yearIndex = param.year;
292
- this.updateWheelPiker('YearView', {
293
- arrayValue: this.years,
294
- value: param.year
295
- });
296
- }
297
-
298
- if (param && param.hour != null) {
299
- this.hourIndex = param.hour;
300
- this.updateWheelPiker('HourView', {
301
- arrayValue: this.hours,
302
- value: param.hour
303
- });
304
- }
305
-
306
- if (param && param.minute != null) {
307
- this.minuteIndex = param.minute;
308
- this.updateWheelPiker('MinuteView', {
309
- arrayValue: this.minutes,
310
- value: param.minute
311
- });
312
- }
393
+ if (param && param.hour != null) {
394
+ this.hourIndex = param.hour;
395
+ this.updateWheelPiker('HourView', {
396
+ arrayValue: this.hours,
397
+ value: param.hour,
398
+ });
399
+ }
313
400
 
314
- if (param && param.hourRange_1 != null) {
315
- this.hourRangeIndex_1 = param.hourRange_1;
316
- this.updateWheelPiker('HourRange1', {
317
- arrayValue: this.ranged,
318
- value: param.hourRange_1
319
- });
320
- }
401
+ if (param && param.minute != null) {
402
+ this.minuteIndex = param.minute;
403
+ this.updateWheelPiker('MinuteView', {
404
+ arrayValue: this.minutes,
405
+ value: param.minute,
406
+ });
407
+ }
321
408
 
322
- if (param && param.hourRange_2 != null) {
323
- this.hourRangeIndex_2 = param.hourRange_2;
324
- this.updateWheelPiker('HourRange2', {
325
- arrayValue: this.ranged,
326
- value: param.hourRange_2
327
- });
328
- }
409
+ if (param && param.hourRange_1 != null) {
410
+ this.hourRangeIndex_1 = param.hourRange_1;
411
+ this.updateWheelPiker('HourRange1', {
412
+ arrayValue: this.ranged,
413
+ value: param.hourRange_1,
414
+ });
329
415
  }
330
416
 
331
- setStateDate(dayIndex, monthIndex, yearIndex) {
332
- const day = parseInt(this.days[dayIndex]);
333
- const month = parseInt(this.months[monthIndex]);
334
- const year = parseInt(this.years[yearIndex]);
417
+ if (param && param.hourRange_2 != null) {
418
+ this.hourRangeIndex_2 = param.hourRange_2;
419
+ this.updateWheelPiker('HourRange2', {
420
+ arrayValue: this.ranged,
421
+ value: param.hourRange_2,
422
+ });
423
+ }
424
+ }
335
425
 
336
- let isUpDate = false;
337
- let minDay = 1;
338
- let maxDay = DatePickerHelper.getMaxDate(month, year);
426
+ setStateDate(dayIndex, monthIndex, yearIndex) {
427
+ const day = parseInt(this.days[dayIndex]);
428
+ const month = parseInt(this.months[monthIndex]);
429
+ const year = parseInt(this.years[yearIndex]);
339
430
 
340
- if (this.maxDay && year === this.maxYear && this.maxMonth === month) {
341
- maxDay = this.maxDay;
342
- }
431
+ let isUpDate = false;
432
+ let minDay = 1;
433
+ let maxDay = DatePickerHelper.getMaxDate(month, year);
343
434
 
344
- if (this.minDay && year === this.minYear && this.minMonth === month) {
345
- minDay = this.minDay;
346
- }
435
+ if (this.maxDay && year === this.maxYear && this.maxMonth === month) {
436
+ maxDay = this.maxDay;
437
+ }
347
438
 
348
- if (maxDay !== this.days?.length || minDay !== parseInt(this.days[0])) {
349
- isUpDate = true;
350
- }
439
+ if (this.minDay && year === this.minYear && this.minMonth === month) {
440
+ minDay = this.minDay;
441
+ }
351
442
 
352
- let index = dayIndex;
443
+ if (maxDay !== this.days?.length || minDay !== parseInt(this.days[0])) {
444
+ isUpDate = true;
445
+ }
353
446
 
354
- if (isUpDate) {
355
- this.days = DatePickerHelper.makeRange(minDay, maxDay);
356
- index = day > maxDay ? this.days?.length - 1 : (day < minDay ? 0 : this.days.indexOf(day.toString()));
357
- }
447
+ let index = dayIndex;
358
448
 
359
- this.renderUpdate({
360
- day: index,
361
- month: monthIndex,
362
- year: yearIndex
363
- });
449
+ if (isUpDate) {
450
+ this.days = DatePickerHelper.makeRange(minDay, maxDay);
451
+ index =
452
+ day > maxDay
453
+ ? this.days?.length - 1
454
+ : day < minDay
455
+ ? 0
456
+ : this.days.indexOf(day.toString());
364
457
  }
365
458
 
366
- setStateMonth(dayIndex, monthIndex, yearIndex) {
367
- const month = parseInt(this.months[monthIndex]);
368
- const year = parseInt(this.years[yearIndex]);
459
+ this.renderUpdate({
460
+ day: index,
461
+ month: monthIndex,
462
+ year: yearIndex,
463
+ });
464
+ }
369
465
 
370
- let isUpDate = false;
371
- let minMonth = 1;
372
- let maxMonth = 12;
466
+ setStateMonth(dayIndex, monthIndex, yearIndex) {
467
+ const month = parseInt(this.months[monthIndex]);
468
+ const year = parseInt(this.years[yearIndex]);
373
469
 
374
- if (this.maxMonth && year === this.maxYear) {
375
- maxMonth = this.maxMonth;
376
- }
377
- if (this.minMonth && year === this.minYear) {
378
- minMonth = this.minMonth;
379
- }
380
- if (maxMonth !== this.months?.length || minMonth !== parseInt(this.months[0])) {
381
- isUpDate = true;
382
- }
383
- let index = monthIndex;
384
- if (isUpDate) {
385
- this.months = DatePickerHelper.makeRange(minMonth, maxMonth);
386
- index = month > maxMonth
387
- ? this.months?.length - 1
388
- : (month < minMonth ? 0 : this.months?.indexOf(month.toString()));
389
- }
390
- this.setStateDate(dayIndex, index, yearIndex);
391
- }
470
+ let isUpDate = false;
471
+ let minMonth = 1;
472
+ let maxMonth = 12;
392
473
 
393
- updateWheelPiker(refName, param) {
394
- let refWheelPicker;
395
- if (this.arrayRef) {
396
- refWheelPicker = this.arrayRef[refName];
397
- if (refWheelPicker && refWheelPicker.update) {
398
- this.arrayRef[refName].update(param);
399
- }
400
- }
474
+ if (this.maxMonth && year === this.maxYear) {
475
+ maxMonth = this.maxMonth;
401
476
  }
402
-
403
- renderColumn(refName, valueInput, arrayValue, label, bottomOffset, callback, reversePreFix) {
404
- if (!this.arrayRef) {
405
- this.arrayRef = {};
406
- }
407
- return (
408
- <WheelPicker
409
- bottomOffset={bottomOffset}
410
- key={refName}
411
- refName={refName}
412
- ref={(ref) => {
413
- this.arrayRef[refName] = ref;
414
- }}
415
- value={valueInput}
416
- arrayValue={arrayValue}
417
- reversePreFix={reversePreFix}
418
- preFix={label}
419
- onBeginDrag={this.onBeginDrag}
420
- onEndDrag={this.onEndDrag}
421
- onValueChange={(value) => {
422
- if (callback) {
423
- callback(value);
424
- }
425
- }}
426
- />
427
- );
477
+ if (this.minMonth && year === this.minYear) {
478
+ minMonth = this.minMonth;
428
479
  }
429
-
430
- renderHeader() {
431
- const {
432
- title, placeholder, body, buttonTitle, onButtonPress, headerStyle, iconClosePosition = 'right'
433
- } = this.props;
434
- return (
435
- <BottomPopupHeader
436
- iconClosePosition={iconClosePosition}
437
- body={body}
438
- onClose={this.hide}
439
- title={title || placeholder}
440
- buttonTitle={buttonTitle}
441
- onButtonPress={onButtonPress}
442
- style={[styles.header, headerStyle]}
443
- />
444
- );
445
- // return (
446
- // <View style={styles.header}>
447
- // <TouchableOpacity
448
- // onPress={this.hide}
449
- // >
450
- // <Text style={styles.titleCancel}>
451
- // {titleCancel}
452
- // </Text>
453
- // </TouchableOpacity>
454
- // <Text style={styles.title}>
455
- // {title || placeholder}
456
- // </Text>
457
- // <TouchableOpacity onPress={this.finish}>
458
- // <Text style={styles.titleConfirm}>
459
- // {titleConfirm}
460
-
461
- // </Text>
462
- // </TouchableOpacity>
463
- // </View>
464
- // );
480
+ if (
481
+ maxMonth !== this.months?.length ||
482
+ minMonth !== parseInt(this.months[0])
483
+ ) {
484
+ isUpDate = true;
465
485
  }
466
-
467
- renderDescription = () => {
468
- const { description, descriptionStyle, renderDescription } = this.props;
469
- if (renderDescription) return renderDescription;
470
- return description ? (
471
- <Text.Title style={[{ marginBottom: Spacing.S }, descriptionStyle]}>{description}</Text.Title>
472
- ) : null;
473
- };
474
-
475
- renderContent() {
476
- const {
477
- format, labelDay, labelMonth, labelYear, bottomOffset, labelMinute, labelHour, isRanged
478
- } = this.props;
479
- if (isRanged && format === 'hh:mm') {
480
- return (
481
- <View style={styles.container}>
482
- {this.renderDescription()}
483
- <View style={styles.content}>
484
- {this.renderColumn('HourRange1', this.hourRangeIndex_1, this.ranged, SwitchLanguage.from, bottomOffset, (value) => {
485
- this.renderUpdate({ hourRange_1: value });
486
- }, true)}
487
- {this.renderColumn('HourRange2', this.hourRangeIndex_2, this.ranged, SwitchLanguage.to, bottomOffset, (value) => {
488
- this.renderUpdate({ hourRange_2: value });
489
- }, true)}
490
- </View>
491
- </View>
492
- );
493
- }
494
- return (
495
- <View style={styles.container}>
496
- {this.renderDescription()}
497
- <View style={styles.content}>
498
- {
499
- format.indexOf('dd') !== -1
500
- ? this.renderColumn('DayView', this.dayIndex, this.days, labelDay || SwitchLanguage.day, bottomOffset, (value) => {
501
- this.renderUpdate({ day: value });
502
- })
503
- : null
504
- }
505
- {
506
- format.indexOf('MM') !== -1
507
- ? this.renderColumn('MonthView', this.monthIndex, this.months, labelMonth || SwitchLanguage.month, bottomOffset, (value) => {
508
- this.setStateDate(this.dayIndex, value, this.yearIndex);
509
- })
510
- : null
511
- }
512
- {
513
- format.indexOf('YYYY') !== -1
514
- ? this.renderColumn('YearView', this.yearIndex, this.years, labelYear || SwitchLanguage.year, bottomOffset, (value) => {
515
- this.setStateMonth(this.dayIndex, this.monthIndex, value);
516
- })
517
- : null
518
- }
519
- {
520
- format.indexOf('hh') !== -1
521
- ? this.renderColumn('HourView', this.hourIndex, this.hours, labelHour || SwitchLanguage.hour, bottomOffset, (value) => {
522
- this.renderUpdate({ hour: value });
523
- }, true)
524
- : null
525
- }
526
- {
527
- format.indexOf('mm') !== -1
528
- ? this.renderColumn('MinuteView', this.minuteIndex, this.minutes, labelMinute || SwitchLanguage.minute, bottomOffset, (value) => {
529
- this.renderUpdate({ minute: value });
530
- }, true)
531
- : null
532
- }
533
- </View>
534
-
535
- </View>
536
- );
486
+ let index = monthIndex;
487
+ if (isUpDate) {
488
+ this.months = DatePickerHelper.makeRange(minMonth, maxMonth);
489
+ index =
490
+ month > maxMonth
491
+ ? this.months?.length - 1
492
+ : month < minMonth
493
+ ? 0
494
+ : this.months?.indexOf(month.toString());
537
495
  }
538
-
539
- renderFooter() {
540
- const { titleFooter, renderFooter } = this.props;
541
- return renderFooter ? renderFooter() : (
542
- <View style={{ paddingHorizontal: 12, marginBottom: ifIphoneX(29, 11), marginTop: 28 }}>
543
- <Button
544
- onPress={this.finish}
545
- title={titleFooter || SwitchLanguage.confirm}
546
- type="primary"
547
- />
548
- </View>
549
-
550
- );
496
+ this.setStateDate(dayIndex, index, yearIndex);
497
+ }
498
+
499
+ updateWheelPiker(refName, param) {
500
+ let refWheelPicker;
501
+ if (this.arrayRef) {
502
+ refWheelPicker = this.arrayRef[refName];
503
+ if (refWheelPicker && refWheelPicker.update) {
504
+ this.arrayRef[refName].update(param);
505
+ }
551
506
  }
552
-
553
- render() {
554
- const { style } = this.props;
555
- return (
556
- <View style={[styles.view, style]}>
557
- {this.renderHeader()}
558
- {this.renderContent()}
559
- {this.renderFooter()}
560
- </View>
561
- );
507
+ }
508
+
509
+ renderColumn(
510
+ refName,
511
+ valueInput,
512
+ arrayValue,
513
+ label,
514
+ bottomOffset,
515
+ callback,
516
+ reversePreFix,
517
+ ) {
518
+ if (!this.arrayRef) {
519
+ this.arrayRef = {};
520
+ }
521
+ return (
522
+ <WheelPicker
523
+ bottomOffset={bottomOffset}
524
+ key={refName}
525
+ refName={refName}
526
+ ref={ref => {
527
+ this.arrayRef[refName] = ref;
528
+ }}
529
+ value={valueInput}
530
+ arrayValue={arrayValue}
531
+ reversePreFix={reversePreFix}
532
+ preFix={label}
533
+ onBeginDrag={this.onBeginDrag}
534
+ onEndDrag={this.onEndDrag}
535
+ onValueChange={value => {
536
+ if (callback) {
537
+ callback(value);
538
+ }
539
+ }}
540
+ />
541
+ );
542
+ }
543
+
544
+ renderHeader() {
545
+ const {
546
+ title,
547
+ placeholder,
548
+ body,
549
+ buttonTitle,
550
+ onButtonPress,
551
+ headerStyle,
552
+ iconClosePosition = 'right',
553
+ iconType,
554
+ headerButtonStyle,
555
+ } = this.props;
556
+ return (
557
+ <BottomPopupHeader
558
+ iconType={iconType}
559
+ iconClosePosition={iconClosePosition}
560
+ body={body}
561
+ onClose={this.hide}
562
+ title={title || placeholder}
563
+ buttonTitle={buttonTitle}
564
+ onButtonPress={onButtonPress}
565
+ style={[styles.header, headerStyle]}
566
+ headerButtonStyle={headerButtonStyle}
567
+ />
568
+ );
569
+ }
570
+
571
+ renderDescription = () => {
572
+ const {description, descriptionStyle, renderDescription} = this.props;
573
+ if (renderDescription) return renderDescription;
574
+ return description ? (
575
+ <Text.Paragraph style={[{marginBottom: Spacing.S}, descriptionStyle]}>
576
+ {description}
577
+ </Text.Paragraph>
578
+ ) : null;
579
+ };
580
+
581
+ renderContent() {
582
+ const {
583
+ format,
584
+ labelDay,
585
+ labelMonth,
586
+ labelYear,
587
+ bottomOffset,
588
+ labelMinute,
589
+ labelHour,
590
+ isRanged,
591
+ } = this.props;
592
+
593
+ if (isRanged && format === 'hh:mm') {
594
+ return (
595
+ <View style={styles.container}>
596
+ {this.renderDescription()}
597
+ <View style={styles.content}>
598
+ {this.renderColumn(
599
+ 'HourRange1',
600
+ this.hourRangeIndex_1,
601
+ this.ranged,
602
+ SwitchLanguage.from,
603
+ bottomOffset,
604
+ value => {
605
+ this.renderUpdate({hourRange_1: value});
606
+ },
607
+ true,
608
+ )}
609
+ {this.renderColumn(
610
+ 'HourRange2',
611
+ this.hourRangeIndex_2,
612
+ this.ranged,
613
+ SwitchLanguage.to,
614
+ bottomOffset,
615
+ value => {
616
+ this.renderUpdate({hourRange_2: value});
617
+ },
618
+ true,
619
+ )}
620
+ </View>
621
+ </View>
622
+ );
562
623
  }
624
+ return (
625
+ <View style={styles.container}>
626
+ {this.renderDescription()}
627
+ <View style={styles.content}>
628
+ {format.indexOf('dd') !== -1
629
+ ? this.renderColumn(
630
+ 'DayView',
631
+ this.dayIndex,
632
+ this.days,
633
+ labelDay || SwitchLanguage.day,
634
+ bottomOffset,
635
+ value => {
636
+ this.renderUpdate({day: value});
637
+ },
638
+ )
639
+ : null}
640
+ {format.indexOf('MM') !== -1
641
+ ? this.renderColumn(
642
+ 'MonthView',
643
+ this.monthIndex,
644
+ this.months,
645
+ labelMonth || SwitchLanguage.month,
646
+ bottomOffset,
647
+ value => {
648
+ this.setStateDate(this.dayIndex, value, this.yearIndex);
649
+ },
650
+ )
651
+ : null}
652
+ {format.indexOf('YYYY') !== -1
653
+ ? this.renderColumn(
654
+ 'YearView',
655
+ this.yearIndex,
656
+ this.years,
657
+ labelYear || SwitchLanguage.year,
658
+ bottomOffset,
659
+ value => {
660
+ this.setStateMonth(this.dayIndex, this.monthIndex, value);
661
+ },
662
+ )
663
+ : null}
664
+ {format.indexOf('hh') !== -1
665
+ ? this.renderColumn(
666
+ 'HourView',
667
+ this.hourIndex,
668
+ this.hours,
669
+ labelHour || SwitchLanguage.hour,
670
+ bottomOffset,
671
+ value => {
672
+ this.renderUpdate({hour: value});
673
+ },
674
+ true,
675
+ )
676
+ : null}
677
+ {format.indexOf('mm') !== -1
678
+ ? this.renderColumn(
679
+ 'MinuteView',
680
+ this.minuteIndex,
681
+ this.minutes,
682
+ labelMinute || SwitchLanguage.minute,
683
+ bottomOffset,
684
+ value => {
685
+ this.renderUpdate({minute: value});
686
+ },
687
+ true,
688
+ )
689
+ : null}
690
+ </View>
691
+ </View>
692
+ );
693
+ }
694
+
695
+ renderFooter() {
696
+ const {titleFooter, renderFooter, footerButtonStyle} = this.props;
697
+ return renderFooter ? (
698
+ renderFooter()
699
+ ) : (
700
+ <View
701
+ style={{
702
+ paddingHorizontal: 12,
703
+ marginBottom: ifIphoneX(35, 12),
704
+ marginTop: 16,
705
+ }}>
706
+ <Button
707
+ onPress={this.finish}
708
+ buttonStyle={[footerButtonStyle]}
709
+ title={titleFooter || SwitchLanguage.confirm}
710
+ type="primary"
711
+ />
712
+ </View>
713
+ );
714
+ }
715
+
716
+ render() {
717
+ const {style} = this.props;
718
+ return (
719
+ <View style={[styles.view, style]}>
720
+ {this.renderHeader()}
721
+ {this.renderContent()}
722
+ {this.renderFooter()}
723
+ </View>
724
+ );
725
+ }
563
726
  }
564
727
 
565
728
  DatePicker.propTypes = {
566
- selectedDate: PropTypes.any,
567
- format: PropTypes.string,
568
- placeholder: PropTypes.string,
569
- minDate: PropTypes.string,
570
- maxDate: PropTypes.string,
571
- titleFooter: PropTypes.string,
572
- title: PropTypes.string,
573
- // titleCancel: PropTypes.string,
574
- // titleConfirm: PropTypes.string,
575
- labelMonth: PropTypes.string,
576
- labelHour: PropTypes.string,
577
- labelMinute: PropTypes.string,
578
- labelDay: PropTypes.string,
579
- labelYear: PropTypes.string,
580
- onSelected: PropTypes.func,
581
- bottomOffset: PropTypes.number,
582
- renderDescription: PropTypes.any,
583
- description: PropTypes.string,
584
- renderFooter: PropTypes.any,
585
- style: PropTypes.any,
586
- rangeHour: PropTypes.array,
729
+ selectedDate: PropTypes.any,
730
+ format: PropTypes.string,
731
+ placeholder: PropTypes.string,
732
+ minDate: PropTypes.string,
733
+ maxDate: PropTypes.string,
734
+ titleFooter: PropTypes.string,
735
+ title: PropTypes.string,
736
+ // titleCancel: PropTypes.string,
737
+ // titleConfirm: PropTypes.string,
738
+ labelMonth: PropTypes.string,
739
+ labelHour: PropTypes.string,
740
+ labelMinute: PropTypes.string,
741
+ labelDay: PropTypes.string,
742
+ labelYear: PropTypes.string,
743
+ onSelected: PropTypes.func,
744
+ bottomOffset: PropTypes.number,
745
+ renderDescription: PropTypes.any,
746
+ description: PropTypes.string,
747
+ renderFooter: PropTypes.any,
748
+ style: PropTypes.any,
749
+ rangeHour: PropTypes.array,
750
+ iconClosePosition: PropTypes.oneOf(['left', 'right']),
751
+ iconType: PropTypes.oneOf(['icon', 'text']),
752
+ startTime: PropTypes.array,
753
+ endTime: PropTypes.array,
587
754
  };
588
755
 
589
756
  DatePicker.defaultProps = {
590
- format: 'dd/MM/YYYY',
591
- placeholder: SwitchLanguage.chooseDate,
592
- minDate: '1/1/1970',
593
- // titleCancel: SwitchLanguage.cancel,
594
- // titleConfirm: SwitchLanguage.done,
595
- // labelMonth: SwitchLanguage.month,
596
- // labelDay: SwitchLanguage.day,
597
- // labelYear: SwitchLanguage.year,
598
- // labelHour: SwitchLanguage.hour,
599
- // labelMinute: SwitchLanguage.minute,
600
- bottomOffset: 0,
757
+ format: 'dd/MM/YYYY',
758
+ placeholder: SwitchLanguage.chooseDate,
759
+ minDate: '1/1/1970',
760
+ // titleCancel: SwitchLanguage.cancel,
761
+ // titleConfirm: SwitchLanguage.done,
762
+ // labelMonth: SwitchLanguage.month,
763
+ // labelDay: SwitchLanguage.day,
764
+ // labelYear: SwitchLanguage.year,
765
+ // labelHour: SwitchLanguage.hour,
766
+ // labelMinute: SwitchLanguage.minute,
767
+ bottomOffset: 0,
601
768
  };
602
769
 
603
770
  export default DatePicker;
604
-