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

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,10 +1,4 @@
1
- import React, {
2
- useState,
3
- useRef,
4
- useEffect,
5
- useContext,
6
- createContext,
7
- } from 'react';
1
+ import React, {Component, createContext, RefObject} from 'react';
8
2
  import {Dimensions, LayoutChangeEvent, View} from 'react-native';
9
3
  import moment from 'moment';
10
4
  import {
@@ -17,251 +11,308 @@ import {
17
11
  } from '@momo-kits/foundation';
18
12
  import CalendarPro from './CalendarPro';
19
13
  import TabHeader from './TabHeader';
20
- import {CalendarProps, CalendarProRef} from './types';
14
+ import {CalendarProps, CalendarState} from './types';
21
15
  import styles from './styles';
22
16
 
23
17
  const DOUBLE = 'doubleDate';
24
18
 
25
19
  export const ContainerContext = createContext({width: 0, height: 0});
26
20
 
27
- const Calendar: React.FC<CalendarProps> = props => {
28
- const {translate, theme} = useContext(ApplicationContext);
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>;
29
30
 
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;
58
-
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
- );
72
-
73
- const doubleDate = useRef<{
74
- first: moment.Moment | null;
75
- second: moment.Moment | null;
76
- }>(
77
- initDoubleDate
31
+ constructor(props: CalendarProps) {
32
+ super(props);
33
+ this.doubleDate = props.doubleDate
78
34
  ? {
79
- first: initDoubleDate.first ? moment(initDoubleDate.first) : null,
80
- second: initDoubleDate.second ? moment(initDoubleDate.second) : null,
35
+ first: props.doubleDate.first ? moment(props.doubleDate.first) : null,
36
+ second: props.doubleDate.second
37
+ ? moment(props.doubleDate.second)
38
+ : null,
81
39
  }
82
- : {first: null, second: null}
83
- );
84
- const tabSelected = useRef<number>(id || 0);
40
+ : {};
41
+ this.tabSelected = 0;
42
+
43
+ this.selectedDate = props.selectedDate
44
+ ? moment(props.selectedDate)
45
+ : moment();
46
+
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
+ }
85
56
 
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);
57
+ componentDidMount() {
58
+ const {id} = this.props;
59
+ this.tabSelected = id || 0;
60
+ this.viewInit();
61
+ }
91
62
 
92
- // Initialize view on mount
93
- useEffect(() => {
94
- tabSelected.current = id || 0;
63
+ viewInit() {
64
+ const {mode} = this.props;
95
65
  if (mode === DOUBLE) {
96
66
  if (
97
- cellHeader1.current &&
98
- cellHeader2.current &&
99
- calendarPicker.current
67
+ this.cellHeader1.current &&
68
+ this.cellHeader2.current &&
69
+ this.calendarPicker.current
100
70
  ) {
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
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
109
79
  );
110
80
  }
111
- } else {
112
- calendarPicker.current?.setDoubleDateAndTabIndex(selectedDate);
81
+ } else if (this.calendarPicker.current) {
82
+ this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);
113
83
  }
114
- }, []);
84
+ }
115
85
 
116
- const onLayout = (e: LayoutChangeEvent) =>
117
- setContainerWidth(e.nativeEvent.layout.width);
86
+ onChangeTab = (idTab: number) => {
87
+ this.props.onChangeTab?.(idTab);
88
+ this.tabSelected = idTab;
118
89
 
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
- );
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();
129
95
  };
130
96
 
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
- };
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
+ }
151
106
 
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
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
+ }
173
+
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
166
188
  );
167
- onDateChange?.({ first: doubleDate.current.first!, second: null });
168
- onCTAStateChange?.(false);
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
+ }
169
200
  } else {
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);
182
- }
183
- };
201
+ this.doubleDate.first = this.selectedDate;
202
+ this.doubleDate.second = null;
184
203
 
185
- const processDoubleDate = () => {
186
- tabSelected.current === 0 ? processDateFirst() : processDateSecond();
187
- };
204
+ this.cellHeader1?.current?.updateView(this.selectedDate, false);
205
+ this.cellHeader2?.current?.updateView(null, false);
206
+ }
207
+ }
188
208
 
189
- const updateView = () => {
190
- const {onDateChange} = props;
191
- if (isDoubleDateMode) {
192
- processDoubleDate();
209
+ processDoubleDate() {
210
+ if (this.tabSelected === 0) {
211
+ this.processDateFirst();
193
212
  } else {
194
- cellHeaderSingle.current?.updateView(selectedDate, true);
195
- onDateChange?.(selectedDate.toDate());
213
+ this.processDateSecond();
196
214
  }
197
- };
215
+ }
198
216
 
199
- // skip running updateView on initial mount to preserve initial doubleDate props
200
- const didMount = useRef(false);
217
+ updateView() {
218
+ const {onDateChange} = this.props;
219
+ const {isDoubleDateMode} = this.state;
201
220
 
202
- useEffect(() => {
203
- if (didMount.current) {
204
- updateView();
221
+ if (isDoubleDateMode) {
222
+ this.processDoubleDate();
205
223
  } else {
206
- didMount.current = true;
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
+ }
207
231
  }
208
- }, [selectedDate]);
232
+ }
209
233
 
210
- const onDateChangeHandler = (date: moment.Moment) => setSelectedDate(date);
234
+ onDateChange = (date: moment.Moment) => {
235
+ this.selectedDate = date;
236
+ this.updateView();
237
+ };
211
238
 
212
- const updateHeaderView = () => {
213
- const {onDateChange, onCTAStateChange} = props;
239
+ updateHeaderView = () => {
240
+ const {onDateChange, onCTAStateChange} = this.props;
241
+ const {isDoubleDateMode} = this.state;
214
242
  if (isDoubleDateMode) {
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});
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
+ }
234
277
  } else {
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);
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
+ }
241
291
  }
242
- props.onDateChange?.(selectedDate.toDate());
243
292
  }
244
293
  };
245
294
 
246
- const toggleSelectionDateMode = () => {
247
- setIsDoubleDateMode(prev => {
248
- const next = !prev;
249
- props.onCallbackCalendar?.('switch', next);
250
- return next;
251
- });
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
+ );
252
307
  };
253
308
 
254
- const didMountMode = useRef(false);
255
- useEffect(() => {
256
- if (didMountMode.current) {
257
- updateHeaderView();
258
- } else {
259
- didMountMode.current = true;
309
+ renderSwitchReturnSelection = () => {
310
+ const {isDoubleDateMode} = this.state;
311
+ const {translate, theme} = this.context;
312
+ const { hideSwitchReturnSelection } = this.props;
313
+ if(hideSwitchReturnSelection){
314
+ return null
260
315
  }
261
- }, [isDoubleDateMode]);
262
-
263
- const renderSwitchReturnSelection = () => {
264
- if (props.hideSwitchReturnSelection) return null;
265
316
  return (
266
317
  <View style={styles.headerContainer}>
267
318
  <View
@@ -269,17 +320,22 @@ const Calendar: React.FC<CalendarProps> = props => {
269
320
  styles.viewSwitch,
270
321
  {backgroundColor: theme.colors.background.surface},
271
322
  ]}>
272
- <Text typography="label_default_medium">
273
- {props.titleHeader || translate?.('chooseRoundtrip')}
323
+ <Text typography={'label_default_medium'}>
324
+ {this.props?.titleHeader || translate('chooseRoundtrip')}
274
325
  </Text>
275
- <Switch value={isDoubleDateMode} onChange={toggleSelectionDateMode} />
326
+ <Switch
327
+ value={isDoubleDateMode}
328
+ onChange={this.toggleSelectionDateMode}
329
+ />
276
330
  </View>
277
331
  </View>
278
332
  );
279
333
  };
280
334
 
281
- const renderHeaderPanel = () =>
282
- isDoubleDateMode ? (
335
+ renderHeaderPanel = (theme: {colors: {background: {default: string}}}) => {
336
+ const {isDoubleDateMode} = this.state;
337
+ const {headerFrom, headerTo} = this.props;
338
+ return isDoubleDateMode ? (
283
339
  <View
284
340
  style={[
285
341
  styles.viewPanel,
@@ -287,20 +343,20 @@ const Calendar: React.FC<CalendarProps> = props => {
287
343
  ]}>
288
344
  <TabHeader
289
345
  id={0}
290
- ref={cellHeader1}
291
- onChangeTab={onChangeTab}
292
- label={props.headerFrom || 'depart'}
346
+ ref={this.cellHeader1}
347
+ onChangeTab={this.onChangeTab}
348
+ label={headerFrom || 'depart'}
293
349
  activeTab
294
- date={doubleDate.current.first}
350
+ date={this.doubleDate.first}
295
351
  />
296
352
  <View style={{width: 4, height: '100%'}} />
297
353
  <TabHeader
298
354
  id={1}
299
- ref={cellHeader2}
300
- onChangeTab={onChangeTab}
301
- label={props.headerTo || 'return'}
355
+ ref={this.cellHeader2}
356
+ onChangeTab={this.onChangeTab}
357
+ label={headerTo || 'return'}
302
358
  activeTab={false}
303
- date={doubleDate.current.second}
359
+ date=""
304
360
  />
305
361
  </View>
306
362
  ) : (
@@ -312,55 +368,116 @@ const Calendar: React.FC<CalendarProps> = props => {
312
368
  <TabHeader
313
369
  id={0}
314
370
  disabled
315
- ref={cellHeaderSingle}
316
- label={props.headerFrom || 'depart'}
371
+ ref={this.cellHeaderSingle}
372
+ label={headerFrom || 'depart'}
317
373
  activeTab
318
- date={selectedDate}
374
+ date={this.selectedDate}
319
375
  />
320
376
  </View>
321
377
  );
378
+ };
322
379
 
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()}
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
+
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
+ />
341
477
  </View>
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
- };
478
+ </ContainerContext.Provider>
479
+ );
480
+ }
481
+ }
365
482
 
366
483
  export {Calendar};