@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.
- package/WheelPicker.tsx +207 -0
- package/index.tsx +148 -0
- package/package.json +11 -10
- package/publish.sh +1 -2
- package/styles.ts +34 -0
- package/types.ts +88 -0
- package/utils.ts +112 -0
- package/datePicker/DatePicker.js +0 -770
- package/datePicker/DatePickerInput.js +0 -136
- package/datePicker/ListPicker.js +0 -208
- package/datePicker/WheelPicker.js +0 -328
- package/datePicker/custom/ScrollCustom.js +0 -60
- package/datePicker/helper/DatePickerHelper.js +0 -241
- package/index.js +0 -9
package/datePicker/DatePicker.js
DELETED
|
@@ -1,770 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
/* eslint-disable react/no-unused-prop-types */
|
|
3
|
-
import React, {Component} from 'react';
|
|
4
|
-
import {View, StyleSheet, Dimensions} from 'react-native';
|
|
5
|
-
import PropTypes from 'prop-types';
|
|
6
|
-
import {
|
|
7
|
-
BottomPopupHeader,
|
|
8
|
-
Button,
|
|
9
|
-
Text,
|
|
10
|
-
ScreenUtils,
|
|
11
|
-
SwitchLanguage,
|
|
12
|
-
Spacing,
|
|
13
|
-
Colors,
|
|
14
|
-
} from '@momo-kits/core-v2';
|
|
15
|
-
import WheelPicker from './WheelPicker';
|
|
16
|
-
import DatePickerHelper from './helper/DatePickerHelper';
|
|
17
|
-
|
|
18
|
-
const {ifIphoneX} = ScreenUtils;
|
|
19
|
-
|
|
20
|
-
const widthScreen = Dimensions.get('window').width;
|
|
21
|
-
const styles = StyleSheet.create({
|
|
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
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const getStrings = strings => (strings?.length === 1 ? `0${strings}` : strings);
|
|
69
|
-
|
|
70
|
-
class DatePicker extends Component {
|
|
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
|
-
}
|
|
167
|
-
}
|
|
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();
|
|
191
|
-
}
|
|
192
|
-
if (maxDate) {
|
|
193
|
-
this.maxDay = maxDate.getDate();
|
|
194
|
-
this.maxMonth = maxDate.getMonth() + 1;
|
|
195
|
-
this.maxYear = maxDate.getFullYear();
|
|
196
|
-
}
|
|
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);
|
|
205
|
-
}
|
|
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;
|
|
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
|
-
};
|
|
316
|
-
|
|
317
|
-
show = () => {};
|
|
318
|
-
|
|
319
|
-
hide = () => {
|
|
320
|
-
const {onClose, requestClose} = this.props;
|
|
321
|
-
if (requestClose && typeof requestClose === 'function') {
|
|
322
|
-
requestClose(() => {
|
|
323
|
-
if (onClose && typeof onClose === 'function') {
|
|
324
|
-
onClose();
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}
|
|
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;
|
|
344
|
-
}
|
|
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
|
-
);
|
|
364
|
-
}
|
|
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
|
-
});
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
if (param && param.month != null) {
|
|
378
|
-
this.monthIndex = param.month;
|
|
379
|
-
this.updateWheelPiker('MonthView', {
|
|
380
|
-
arrayValue: this.months,
|
|
381
|
-
value: param.month,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (param && param.year != null) {
|
|
386
|
-
this.yearIndex = param.year;
|
|
387
|
-
this.updateWheelPiker('YearView', {
|
|
388
|
-
arrayValue: this.years,
|
|
389
|
-
value: param.year,
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
|
|
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
|
-
}
|
|
400
|
-
|
|
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
|
-
}
|
|
408
|
-
|
|
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
|
-
});
|
|
415
|
-
}
|
|
416
|
-
|
|
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
|
-
}
|
|
425
|
-
|
|
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]);
|
|
430
|
-
|
|
431
|
-
let isUpDate = false;
|
|
432
|
-
let minDay = 1;
|
|
433
|
-
let maxDay = DatePickerHelper.getMaxDate(month, year);
|
|
434
|
-
|
|
435
|
-
if (this.maxDay && year === this.maxYear && this.maxMonth === month) {
|
|
436
|
-
maxDay = this.maxDay;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (this.minDay && year === this.minYear && this.minMonth === month) {
|
|
440
|
-
minDay = this.minDay;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
if (maxDay !== this.days?.length || minDay !== parseInt(this.days[0])) {
|
|
444
|
-
isUpDate = true;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
let index = dayIndex;
|
|
448
|
-
|
|
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());
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
this.renderUpdate({
|
|
460
|
-
day: index,
|
|
461
|
-
month: monthIndex,
|
|
462
|
-
year: yearIndex,
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
setStateMonth(dayIndex, monthIndex, yearIndex) {
|
|
467
|
-
const month = parseInt(this.months[monthIndex]);
|
|
468
|
-
const year = parseInt(this.years[yearIndex]);
|
|
469
|
-
|
|
470
|
-
let isUpDate = false;
|
|
471
|
-
let minMonth = 1;
|
|
472
|
-
let maxMonth = 12;
|
|
473
|
-
|
|
474
|
-
if (this.maxMonth && year === this.maxYear) {
|
|
475
|
-
maxMonth = this.maxMonth;
|
|
476
|
-
}
|
|
477
|
-
if (this.minMonth && year === this.minYear) {
|
|
478
|
-
minMonth = this.minMonth;
|
|
479
|
-
}
|
|
480
|
-
if (
|
|
481
|
-
maxMonth !== this.months?.length ||
|
|
482
|
-
minMonth !== parseInt(this.months[0])
|
|
483
|
-
) {
|
|
484
|
-
isUpDate = true;
|
|
485
|
-
}
|
|
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());
|
|
495
|
-
}
|
|
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
|
-
}
|
|
506
|
-
}
|
|
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
|
-
);
|
|
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
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
DatePicker.propTypes = {
|
|
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,
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
DatePicker.defaultProps = {
|
|
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,
|
|
768
|
-
};
|
|
769
|
-
|
|
770
|
-
export default DatePicker;
|