@momo-kits/calendar 0.121.0-rc.3 → 0.121.0-rc.5

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/index.tsx CHANGED
@@ -1,4 +1,10 @@
1
- import React, {Component, createContext, RefObject} from 'react';
1
+ import React, {
2
+ useState,
3
+ useRef,
4
+ useEffect,
5
+ useContext,
6
+ createContext,
7
+ } from 'react';
2
8
  import {Dimensions, LayoutChangeEvent, View} from 'react-native';
3
9
  import moment from 'moment';
4
10
  import {
@@ -11,308 +17,251 @@ import {
11
17
  } from '@momo-kits/foundation';
12
18
  import CalendarPro from './CalendarPro';
13
19
  import TabHeader from './TabHeader';
14
- import {CalendarProps, CalendarState} from './types';
20
+ import {CalendarProps, CalendarProRef} from './types';
15
21
  import styles from './styles';
16
22
 
17
23
  const DOUBLE = 'doubleDate';
18
24
 
19
25
  export const ContainerContext = createContext({width: 0, height: 0});
20
26
 
21
- class Calendar extends Component<CalendarProps, CalendarState> {
22
- static contextType = ApplicationContext;
23
- doubleDate: any;
24
- tabSelected;
25
- selectedDate: moment.Moment;
26
- calendarPicker: RefObject<CalendarPro>;
27
- cellHeader1: RefObject<TabHeader>;
28
- cellHeader2: RefObject<TabHeader>;
29
- cellHeaderSingle: RefObject<TabHeader>;
27
+ const Calendar: React.FC<CalendarProps> = props => {
28
+ const {translate, theme} = useContext(ApplicationContext);
30
29
 
31
- constructor(props: CalendarProps) {
32
- super(props);
33
- this.doubleDate = props.doubleDate
34
- ? {
35
- first: props.doubleDate.first ? moment(props.doubleDate.first) : null,
36
- second: props.doubleDate.second
37
- ? moment(props.doubleDate.second)
38
- : null,
39
- }
40
- : {};
41
- this.tabSelected = 0;
30
+ // derive defaults for date bounds
31
+ const currentDate = new Date();
32
+ const minDateDefault = new Date(currentDate);
33
+ const maxDateDefault = new Date(currentDate);
34
+ minDateDefault.setFullYear(minDateDefault.getFullYear() - 1);
35
+ maxDateDefault.setFullYear(maxDateDefault.getFullYear() + 1);
36
+
37
+ // destructure all Calendar props
38
+ const {
39
+ mode,
40
+ id,
41
+ doubleDate: initDoubleDate,
42
+ selectedDate: initialSelectedDate,
43
+ onChangeTab: onChangeTabProp,
44
+ onCallbackCalendar,
45
+ isOffLunar,
46
+ isHideHoliday,
47
+ isShowLunar,
48
+ priceList,
49
+ labelFrom,
50
+ labelTo,
51
+ isHideLabel,
52
+ minDate = minDateDefault,
53
+ maxDate = maxDateDefault,
54
+ style,
55
+ disabledDays = [],
56
+ hideHeaderTab = false,
57
+ } = props;
42
58
 
43
- this.selectedDate = props.selectedDate
44
- ? moment(props.selectedDate)
45
- : moment();
59
+ const [containerWidth, setContainerWidth] = useState<number>(
60
+ Dimensions.get('window').width
61
+ );
62
+ const [isDoubleDateMode, setIsDoubleDateMode] = useState<boolean>(
63
+ mode === DOUBLE
64
+ );
65
+ const [selectedDate, setSelectedDate] = useState<moment.Moment>(
66
+ initialSelectedDate
67
+ ? moment(initialSelectedDate)
68
+ : mode === DOUBLE && initDoubleDate && initDoubleDate.first
69
+ ? moment(initDoubleDate.first)
70
+ : moment()
71
+ );
46
72
 
47
- this.state = {
48
- isDoubleDateMode: props.mode === DOUBLE,
49
- containerWidth: Dimensions.get('window').width,
50
- };
51
- this.calendarPicker = React.createRef<CalendarPro>();
52
- this.cellHeader1 = React.createRef<TabHeader>();
53
- this.cellHeader2 = React.createRef<TabHeader>();
54
- this.cellHeaderSingle = React.createRef<TabHeader>();
55
- }
73
+ const doubleDate = useRef<{
74
+ first: moment.Moment | null;
75
+ second: moment.Moment | null;
76
+ }>(
77
+ initDoubleDate
78
+ ? {
79
+ first: initDoubleDate.first ? moment(initDoubleDate.first) : null,
80
+ second: initDoubleDate.second ? moment(initDoubleDate.second) : null,
81
+ }
82
+ : {first: null, second: null}
83
+ );
84
+ const tabSelected = useRef<number>(id || 0);
56
85
 
57
- componentDidMount() {
58
- const {id} = this.props;
59
- this.tabSelected = id || 0;
60
- this.viewInit();
61
- }
86
+ const calendarPicker = useRef<CalendarProRef>(null);
87
+ // hold refs to TabHeader instances
88
+ const cellHeader1 = useRef<TabHeader>(null);
89
+ const cellHeader2 = useRef<TabHeader>(null);
90
+ const cellHeaderSingle = useRef<TabHeader>(null);
62
91
 
63
- viewInit() {
64
- const {mode} = this.props;
92
+ // Initialize view on mount
93
+ useEffect(() => {
94
+ tabSelected.current = id || 0;
65
95
  if (mode === DOUBLE) {
66
96
  if (
67
- this.cellHeader1.current &&
68
- this.cellHeader2.current &&
69
- this.calendarPicker.current
97
+ cellHeader1.current &&
98
+ cellHeader2.current &&
99
+ calendarPicker.current
70
100
  ) {
71
- const start = this.doubleDate.first ? this.doubleDate.first : null;
72
- const end = this.doubleDate.second ? this.doubleDate.second : null;
73
- this.cellHeader1.current.updateView(start, this.tabSelected === 0);
74
- this.cellHeader2.current.updateView(end, this.tabSelected === 1);
75
- this.calendarPicker.current.setDoubleDateAndTabIndex(
76
- this.doubleDate.first,
77
- this.doubleDate.second,
78
- this.tabSelected
101
+ const start = doubleDate.current.first;
102
+ const end = doubleDate.current.second;
103
+ cellHeader1.current.updateView(start, tabSelected.current === 0);
104
+ cellHeader2.current.updateView(end, tabSelected.current === 1);
105
+ calendarPicker.current.setDoubleDateAndTabIndex(
106
+ doubleDate.current.first,
107
+ doubleDate.current.second,
108
+ tabSelected.current
79
109
  );
80
110
  }
81
- } else if (this.calendarPicker.current) {
82
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);
111
+ } else {
112
+ calendarPicker.current?.setDoubleDateAndTabIndex(selectedDate);
83
113
  }
84
- }
114
+ }, []);
85
115
 
86
- onChangeTab = (idTab: number) => {
87
- this.props.onChangeTab?.(idTab);
88
- this.tabSelected = idTab;
116
+ const onLayout = (e: LayoutChangeEvent) =>
117
+ setContainerWidth(e.nativeEvent.layout.width);
89
118
 
90
- if (this.cellHeader1.current && this.cellHeader2.current) {
91
- this.cellHeader1.current.setActiveTab(idTab === 0);
92
- this.cellHeader2.current.setActiveTab(idTab === 1);
93
- }
94
- this.updateViewFlowPicker();
119
+ const onChangeTab = (id: number) => {
120
+ onChangeTabProp?.(id);
121
+ tabSelected.current = id;
122
+ cellHeader1.current?.setActiveTab(id === 0);
123
+ cellHeader2.current?.setActiveTab(id === 1);
124
+ calendarPicker.current?.setDoubleDateAndTabIndex(
125
+ doubleDate.current.first,
126
+ doubleDate.current.second,
127
+ tabSelected.current
128
+ );
95
129
  };
96
130
 
97
- updateViewFlowPicker() {
98
- if (this.calendarPicker.current) {
99
- this.calendarPicker.current.setDoubleDateAndTabIndex(
100
- this.doubleDate.first,
101
- this.doubleDate.second,
102
- this.tabSelected
103
- );
104
- }
105
- }
106
-
107
- processDateFirst() {
108
- const {onDateChange, onCTAStateChange} = this.props;
109
- if (
110
- this.cellHeader1.current &&
111
- this.cellHeader2.current &&
112
- this.calendarPicker.current
113
- ) {
114
- if (
115
- this.doubleDate.first &&
116
- this.doubleDate.second &&
117
- this.selectedDate <= this.doubleDate.first
118
- ) {
119
- this.doubleDate.first = this.selectedDate;
120
- this.doubleDate.second = null;
121
- this.tabSelected = 1;
122
- this.cellHeader1.current.updateView(
123
- this.selectedDate,
124
- this.tabSelected === 0
125
- );
126
- this.cellHeader2.current.updateView(
127
- this.doubleDate.second,
128
- this.tabSelected === 1
129
- );
130
- this.cellHeader2.current.setActiveTab(this.tabSelected === 1);
131
- this.calendarPicker.current.setDoubleDateAndTabIndex(
132
- this.doubleDate.first,
133
- this.doubleDate.second,
134
- this.tabSelected
135
- );
136
- if (onDateChange) {
137
- onDateChange({
138
- first: this.doubleDate.first
139
- ? this.doubleDate.first.toDate()
140
- : null,
141
- second: this.doubleDate.second
142
- ? this.doubleDate.second.toDate()
143
- : null,
144
- });
145
- }
146
- } else {
147
- this.doubleDate.first = this.selectedDate;
148
- this.doubleDate.second = null;
149
- this.cellHeader1.current.updateView(this.selectedDate, false);
150
- this.cellHeader2.current.updateView(null, true);
151
- this.tabSelected = 1;
152
- this.calendarPicker.current.setDoubleDateAndTabIndex(
153
- this.doubleDate.first,
154
- this.doubleDate.second,
155
- this.tabSelected
156
- );
157
- if (onDateChange) {
158
- onDateChange({
159
- first: this.doubleDate.first
160
- ? this.doubleDate.first.toDate()
161
- : null,
162
- second: this.doubleDate.second
163
- ? this.doubleDate.second.toDate()
164
- : null,
165
- });
166
- }
167
- }
168
- }
169
- if (onCTAStateChange) {
170
- onCTAStateChange(!!this.doubleDate.second);
171
- }
172
- }
131
+ const processDateFirst = () => {
132
+ const {onDateChange, onCTAStateChange} = props;
133
+ if (!cellHeader1.current || !cellHeader2.current || !calendarPicker.current) return;
134
+ // set first date and reset second
135
+ doubleDate.current.first = selectedDate;
136
+ doubleDate.current.second = null;
137
+ tabSelected.current = 1;
138
+ // update headers
139
+ cellHeader1.current.updateView(selectedDate, false);
140
+ cellHeader2.current.updateView(null, true);
141
+ // update calendar
142
+ calendarPicker.current.setDoubleDateAndTabIndex(
143
+ doubleDate.current.first,
144
+ doubleDate.current.second,
145
+ tabSelected.current
146
+ );
147
+ // notify parent
148
+ onDateChange?.({ first: doubleDate.current.first!, second: null });
149
+ onCTAStateChange?.(false);
150
+ };
173
151
 
174
- processDateSecond() {
175
- const {onDateChange, onCTAStateChange} = this.props;
176
- if (
177
- this.cellHeader2.current &&
178
- this.selectedDate >= this.doubleDate.first
179
- ) {
180
- this.doubleDate.second = this.selectedDate;
181
- this.cellHeader2.current.updateView(this.selectedDate, false);
182
- this.cellHeader1?.current?.setActiveTab(true);
183
- this.tabSelected = 0;
184
- this.calendarPicker?.current?.setDoubleDateAndTabIndex(
185
- this.doubleDate.first,
186
- this.doubleDate.second,
187
- this.tabSelected
152
+ const processDateSecond = () => {
153
+ const {onDateChange, onCTAStateChange} = props;
154
+ if (!cellHeader1.current || !cellHeader2.current || !calendarPicker.current) return;
155
+ // if selectedDate is before first, treat as new first date
156
+ if (selectedDate.isBefore(doubleDate.current.first!, 'day')) {
157
+ doubleDate.current.first = selectedDate;
158
+ doubleDate.current.second = null;
159
+ tabSelected.current = 1;
160
+ cellHeader1.current.updateView(selectedDate, false);
161
+ cellHeader2.current.updateView(null, false);
162
+ calendarPicker.current.setDoubleDateAndTabIndex(
163
+ doubleDate.current.first,
164
+ doubleDate.current.second,
165
+ tabSelected.current
188
166
  );
189
- if (onCTAStateChange) {
190
- onCTAStateChange(!!this.doubleDate.second);
191
- }
192
- if (onDateChange) {
193
- onDateChange({
194
- first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
195
- second: this.doubleDate.second
196
- ? this.doubleDate.second.toDate()
197
- : null,
198
- });
199
- }
167
+ onDateChange?.({ first: doubleDate.current.first!, second: null });
168
+ onCTAStateChange?.(false);
200
169
  } else {
201
- this.doubleDate.first = this.selectedDate;
202
- this.doubleDate.second = null;
203
-
204
- this.cellHeader1?.current?.updateView(this.selectedDate, false);
205
- this.cellHeader2?.current?.updateView(null, false);
170
+ // valid second date
171
+ doubleDate.current.second = selectedDate;
172
+ tabSelected.current = 0;
173
+ cellHeader2.current.updateView(selectedDate, false);
174
+ cellHeader1.current.setActiveTab(true);
175
+ calendarPicker.current.setDoubleDateAndTabIndex(
176
+ doubleDate.current.first,
177
+ doubleDate.current.second,
178
+ tabSelected.current
179
+ );
180
+ onDateChange?.({ first: doubleDate.current.first!, second: doubleDate.current.second! });
181
+ onCTAStateChange?.(true);
206
182
  }
207
- }
183
+ };
208
184
 
209
- processDoubleDate() {
210
- if (this.tabSelected === 0) {
211
- this.processDateFirst();
185
+ const processDoubleDate = () => {
186
+ tabSelected.current === 0 ? processDateFirst() : processDateSecond();
187
+ };
188
+
189
+ const updateView = () => {
190
+ const {onDateChange} = props;
191
+ if (isDoubleDateMode) {
192
+ processDoubleDate();
212
193
  } else {
213
- this.processDateSecond();
194
+ cellHeaderSingle.current?.updateView(selectedDate, true);
195
+ onDateChange?.(selectedDate.toDate());
214
196
  }
215
- }
197
+ };
216
198
 
217
- updateView() {
218
- const {onDateChange} = this.props;
219
- const {isDoubleDateMode} = this.state;
199
+ // skip running updateView on initial mount to preserve initial doubleDate props
200
+ const didMount = useRef(false);
220
201
 
221
- if (isDoubleDateMode) {
222
- this.processDoubleDate();
202
+ useEffect(() => {
203
+ if (didMount.current) {
204
+ updateView();
223
205
  } else {
224
- if (this.cellHeaderSingle.current) {
225
- this.cellHeaderSingle.current.updateView(this.selectedDate, true);
226
- }
227
- if (onDateChange) {
228
- const date = new Date(this.selectedDate.toDate());
229
- onDateChange(date);
230
- }
206
+ didMount.current = true;
231
207
  }
232
- }
208
+ }, [selectedDate]);
233
209
 
234
- onDateChange = (date: moment.Moment) => {
235
- this.selectedDate = date;
236
- this.updateView();
237
- };
210
+ const onDateChangeHandler = (date: moment.Moment) => setSelectedDate(date);
238
211
 
239
- updateHeaderView = () => {
240
- const {onDateChange, onCTAStateChange} = this.props;
241
- const {isDoubleDateMode} = this.state;
212
+ const updateHeaderView = () => {
213
+ const {onDateChange, onCTAStateChange} = props;
242
214
  if (isDoubleDateMode) {
243
- if (this.cellHeader1.current && this.cellHeader2.current) {
244
- this.cellHeader1.current.updateView(this.selectedDate, true);
245
- this.cellHeader2.current.updateView(null, false);
246
- this.calendarPicker.current?.setDoubleDateAndTabIndex(
247
- this.selectedDate,
248
- null,
249
- this.tabSelected
250
- );
251
- this.doubleDate.first = moment(this.selectedDate);
252
- this.doubleDate.second = null;
253
-
254
- this.tabSelected = 1;
255
- this.cellHeader2.current?.setActiveTab(true);
256
- this.cellHeader1.current?.setActiveTab(false);
257
- this.calendarPicker?.current?.setDoubleDateAndTabIndex(
258
- this.doubleDate.first,
259
- this.doubleDate.second,
260
- this.tabSelected
261
- );
262
-
263
- if (onCTAStateChange) {
264
- onCTAStateChange(false);
265
- }
266
- if (onDateChange) {
267
- onDateChange({
268
- first: this.doubleDate.first
269
- ? this.doubleDate.first.toDate()
270
- : null,
271
- second: this.doubleDate.second
272
- ? this.doubleDate.second.toDate()
273
- : null,
274
- });
275
- }
276
- }
215
+ cellHeader1.current?.updateView(selectedDate, true);
216
+ cellHeader2.current?.updateView(null, false);
217
+ calendarPicker.current?.setDoubleDateAndTabIndex(
218
+ selectedDate,
219
+ null,
220
+ tabSelected.current
221
+ );
222
+ doubleDate.current.first = moment(selectedDate);
223
+ doubleDate.current.second = null;
224
+ tabSelected.current = 1;
225
+ cellHeader2.current?.setActiveTab(true);
226
+ cellHeader1.current?.setActiveTab(false);
227
+ calendarPicker.current?.setDoubleDateAndTabIndex(
228
+ doubleDate.current.first,
229
+ doubleDate.current.second,
230
+ tabSelected.current
231
+ );
232
+ onCTAStateChange?.(false);
233
+ onDateChange?.({first: doubleDate.current.first!, second: null});
277
234
  } else {
278
- if (onCTAStateChange) {
279
- onCTAStateChange(true);
280
- }
281
- if (this.cellHeaderSingle.current) {
282
- if (this.doubleDate.first) {
283
- this.cellHeaderSingle.current.updateView(this.doubleDate.first, true);
284
- this.selectedDate = this.doubleDate.first;
285
- } else {
286
- this.cellHeaderSingle.current.updateView(this.selectedDate, true);
287
- }
288
- if (onDateChange) {
289
- onDateChange(this.selectedDate.toDate());
290
- }
235
+ props.onCTAStateChange?.(true);
236
+ if (doubleDate.current.first) {
237
+ cellHeaderSingle.current?.updateView(doubleDate.current.first, true);
238
+ setSelectedDate(doubleDate.current.first);
239
+ } else {
240
+ cellHeaderSingle.current?.updateView(selectedDate, true);
291
241
  }
242
+ props.onDateChange?.(selectedDate.toDate());
292
243
  }
293
244
  };
294
245
 
295
- toggleSelectionDateMode = () => {
296
- const {onCallbackCalendar} = this.props;
297
- this.setState(
298
- preState => ({isDoubleDateMode: !preState.isDoubleDateMode}),
299
- () => {
300
- const {isDoubleDateMode} = this.state;
301
- this.updateHeaderView();
302
- if (onCallbackCalendar && typeof onCallbackCalendar === 'function') {
303
- onCallbackCalendar('switch', isDoubleDateMode);
304
- }
305
- }
306
- );
246
+ const toggleSelectionDateMode = () => {
247
+ setIsDoubleDateMode(prev => {
248
+ const next = !prev;
249
+ props.onCallbackCalendar?.('switch', next);
250
+ return next;
251
+ });
307
252
  };
308
253
 
309
- renderSwitchReturnSelection = () => {
310
- const {isDoubleDateMode} = this.state;
311
- const {translate, theme} = this.context;
312
- const { hideSwitchReturnSelection } = this.props;
313
- if(hideSwitchReturnSelection){
314
- return null
254
+ const didMountMode = useRef(false);
255
+ useEffect(() => {
256
+ if (didMountMode.current) {
257
+ updateHeaderView();
258
+ } else {
259
+ didMountMode.current = true;
315
260
  }
261
+ }, [isDoubleDateMode]);
262
+
263
+ const renderSwitchReturnSelection = () => {
264
+ if (props.hideSwitchReturnSelection) return null;
316
265
  return (
317
266
  <View style={styles.headerContainer}>
318
267
  <View
@@ -320,22 +269,17 @@ class Calendar extends Component<CalendarProps, CalendarState> {
320
269
  styles.viewSwitch,
321
270
  {backgroundColor: theme.colors.background.surface},
322
271
  ]}>
323
- <Text typography={'label_default_medium'}>
324
- {this.props?.titleHeader || translate('chooseRoundtrip')}
272
+ <Text typography="label_default_medium">
273
+ {props.titleHeader || translate?.('chooseRoundtrip')}
325
274
  </Text>
326
- <Switch
327
- value={isDoubleDateMode}
328
- onChange={this.toggleSelectionDateMode}
329
- />
275
+ <Switch value={isDoubleDateMode} onChange={toggleSelectionDateMode} />
330
276
  </View>
331
277
  </View>
332
278
  );
333
279
  };
334
280
 
335
- renderHeaderPanel = (theme: {colors: {background: {default: string}}}) => {
336
- const {isDoubleDateMode} = this.state;
337
- const {headerFrom, headerTo} = this.props;
338
- return isDoubleDateMode ? (
281
+ const renderHeaderPanel = () =>
282
+ isDoubleDateMode ? (
339
283
  <View
340
284
  style={[
341
285
  styles.viewPanel,
@@ -343,20 +287,20 @@ class Calendar extends Component<CalendarProps, CalendarState> {
343
287
  ]}>
344
288
  <TabHeader
345
289
  id={0}
346
- ref={this.cellHeader1}
347
- onChangeTab={this.onChangeTab}
348
- label={headerFrom || 'depart'}
290
+ ref={cellHeader1}
291
+ onChangeTab={onChangeTab}
292
+ label={props.headerFrom || 'depart'}
349
293
  activeTab
350
- date={this.doubleDate.first}
294
+ date={doubleDate.current.first}
351
295
  />
352
296
  <View style={{width: 4, height: '100%'}} />
353
297
  <TabHeader
354
298
  id={1}
355
- ref={this.cellHeader2}
356
- onChangeTab={this.onChangeTab}
357
- label={headerTo || 'return'}
299
+ ref={cellHeader2}
300
+ onChangeTab={onChangeTab}
301
+ label={props.headerTo || 'return'}
358
302
  activeTab={false}
359
- date=""
303
+ date={doubleDate.current.second}
360
304
  />
361
305
  </View>
362
306
  ) : (
@@ -368,116 +312,55 @@ class Calendar extends Component<CalendarProps, CalendarState> {
368
312
  <TabHeader
369
313
  id={0}
370
314
  disabled
371
- ref={this.cellHeaderSingle}
372
- label={headerFrom || 'depart'}
315
+ ref={cellHeaderSingle}
316
+ label={props.headerFrom || 'depart'}
373
317
  activeTab
374
- date={this.selectedDate}
318
+ date={selectedDate}
375
319
  />
376
320
  </View>
377
321
  );
378
- };
379
-
380
- setDateRange = (
381
- dateRange: {
382
- startDate: moment.Moment | undefined;
383
- endDate: moment.Moment | undefined;
384
- },
385
- isScrollToStartDate: any
386
- ) => {
387
- const {mode, doubleDate = {}} = this.props;
388
- if (mode === 'doubleDate') {
389
- this.cellHeader1?.current?.updateView(
390
- dateRange.startDate,
391
- this.tabSelected === 0
392
- );
393
- this.cellHeader2?.current?.updateView(
394
- dateRange.endDate,
395
- this.tabSelected === 1
396
- );
397
- this.calendarPicker?.current?.setDateRange(
398
- dateRange,
399
- isScrollToStartDate
400
- );
401
- this.doubleDate = doubleDate
402
- ? {
403
- first: dateRange.startDate ? moment(dateRange.startDate) : null,
404
- second: dateRange.endDate ? moment(dateRange.endDate) : null,
405
- }
406
- : {};
407
- }
408
- };
409
-
410
- onLayout = (e: LayoutChangeEvent) => {
411
- this.setState({containerWidth: e.nativeEvent.layout.width});
412
- };
413
-
414
- render() {
415
- const currentDate = new Date();
416
- const minDateDefault = new Date(currentDate);
417
- const maxDateDefault = new Date(currentDate);
418
- minDateDefault.setFullYear(minDateDefault.getFullYear() - 1);
419
- maxDateDefault.setFullYear(maxDateDefault.getFullYear() + 1);
420
322
 
421
- const {
422
- isOffLunar,
423
- isHideHoliday,
424
- isShowLunar,
425
- onCallbackCalendar,
426
- priceList,
427
- labelFrom,
428
- labelTo,
429
- isHideLabel,
430
- minDate = minDateDefault,
431
- maxDate = maxDateDefault,
432
- doubleDate,
433
- style,
434
- disabledDays = [],
435
- hideHeaderTab = false,
436
- } = this.props;
437
- const {isDoubleDateMode, containerWidth} = this.state;
438
- const {theme} = this.context;
439
- return (
440
- <ContainerContext.Provider
441
- value={{
442
- width: containerWidth,
443
- height: priceList ? scaleSize(48) : scaleSize(34),
444
- }}>
445
- <View onLayout={this.onLayout} style={[style, styles.scrollView]}>
446
- <View
447
- style={[
448
- {
449
- backgroundColor: theme.colors.background.surface,
450
- borderRadius: Radius.XS,
451
- marginBottom: Spacing.S,
452
- },
453
- hideHeaderTab && styles.invisible,
454
- ]}>
455
- {this.renderSwitchReturnSelection()}
456
- {this.renderHeaderPanel(theme)}
457
- </View>
458
- <CalendarPro
459
- priceList={priceList}
460
- ref={this.calendarPicker}
461
- startDate={doubleDate?.first}
462
- endDate={doubleDate?.second}
463
- onDateChange={this.onDateChange}
464
- isDoubleDateMode={isDoubleDateMode}
465
- selectedDate={this.selectedDate}
466
- isShowLunar={isShowLunar}
467
- onCallbackCalendar={onCallbackCalendar}
468
- labelFrom={labelFrom}
469
- labelTo={labelTo}
470
- isHideLabel={isHideLabel}
471
- minDate={minDate}
472
- maxDate={maxDate}
473
- isHideHoliday={isHideHoliday}
474
- isOffLunar={isOffLunar}
475
- disabledDays={disabledDays}
476
- />
323
+ return (
324
+ <ContainerContext.Provider
325
+ value={{
326
+ width: containerWidth,
327
+ height: priceList ? scaleSize(48) : scaleSize(34),
328
+ }}>
329
+ <View onLayout={onLayout} style={[style, styles.scrollView]}>
330
+ <View
331
+ style={[
332
+ {
333
+ backgroundColor: theme.colors.background.surface,
334
+ borderRadius: Radius.XS,
335
+ marginBottom: Spacing.S,
336
+ },
337
+ hideHeaderTab && styles.invisible,
338
+ ]}>
339
+ {renderSwitchReturnSelection()}
340
+ {renderHeaderPanel()}
477
341
  </View>
478
- </ContainerContext.Provider>
479
- );
480
- }
481
- }
342
+ <CalendarPro
343
+ priceList={priceList}
344
+ ref={calendarPicker}
345
+ startDate={doubleDate.current.first!}
346
+ endDate={doubleDate.current.second!}
347
+ onDateChange={onDateChangeHandler}
348
+ isDoubleDateMode={isDoubleDateMode}
349
+ selectedDate={selectedDate}
350
+ isShowLunar={isShowLunar}
351
+ onCallbackCalendar={onCallbackCalendar}
352
+ labelFrom={labelFrom}
353
+ labelTo={labelTo}
354
+ isHideLabel={isHideLabel}
355
+ minDate={minDate}
356
+ maxDate={maxDate}
357
+ isHideHoliday={isHideHoliday}
358
+ isOffLunar={isOffLunar}
359
+ disabledDays={disabledDays}
360
+ />
361
+ </View>
362
+ </ContainerContext.Provider>
363
+ );
364
+ };
482
365
 
483
366
  export {Calendar};