@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/CalendarPro.tsx +251 -340
- package/Day.tsx +113 -193
- package/LunarDateConverter.ts +14 -0
- package/Month.tsx +96 -93
- package/MonthList.tsx +199 -262
- package/TabHeader.tsx +3 -3
- package/Util.ts +27 -32
- package/index.tsx +266 -383
- package/package.json +1 -1
- package/types.ts +7 -6
package/index.tsx
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import 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,
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
92
|
+
// Initialize view on mount
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
tabSelected.current = id || 0;
|
|
65
95
|
if (mode === DOUBLE) {
|
|
66
96
|
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
cellHeader1.current &&
|
|
98
|
+
cellHeader2.current &&
|
|
99
|
+
calendarPicker.current
|
|
70
100
|
) {
|
|
71
|
-
const start =
|
|
72
|
-
const end =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
82
|
-
|
|
111
|
+
} else {
|
|
112
|
+
calendarPicker.current?.setDoubleDateAndTabIndex(selectedDate);
|
|
83
113
|
}
|
|
84
|
-
}
|
|
114
|
+
}, []);
|
|
85
115
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.tabSelected = idTab;
|
|
116
|
+
const onLayout = (e: LayoutChangeEvent) =>
|
|
117
|
+
setContainerWidth(e.nativeEvent.layout.width);
|
|
89
118
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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} =
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
190
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
211
|
-
|
|
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
|
-
|
|
194
|
+
cellHeaderSingle.current?.updateView(selectedDate, true);
|
|
195
|
+
onDateChange?.(selectedDate.toDate());
|
|
214
196
|
}
|
|
215
|
-
}
|
|
197
|
+
};
|
|
216
198
|
|
|
217
|
-
updateView
|
|
218
|
-
|
|
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
|
-
|
|
222
|
-
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
if (didMount.current) {
|
|
204
|
+
updateView();
|
|
223
205
|
} else {
|
|
224
|
-
|
|
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
|
-
|
|
235
|
-
this.selectedDate = date;
|
|
236
|
-
this.updateView();
|
|
237
|
-
};
|
|
210
|
+
const onDateChangeHandler = (date: moment.Moment) => setSelectedDate(date);
|
|
238
211
|
|
|
239
|
-
updateHeaderView = () => {
|
|
240
|
-
const {onDateChange, onCTAStateChange} =
|
|
241
|
-
const {isDoubleDateMode} = this.state;
|
|
212
|
+
const updateHeaderView = () => {
|
|
213
|
+
const {onDateChange, onCTAStateChange} = props;
|
|
242
214
|
if (isDoubleDateMode) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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=
|
|
324
|
-
{
|
|
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 = (
|
|
336
|
-
|
|
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={
|
|
347
|
-
onChangeTab={
|
|
348
|
-
label={headerFrom || 'depart'}
|
|
290
|
+
ref={cellHeader1}
|
|
291
|
+
onChangeTab={onChangeTab}
|
|
292
|
+
label={props.headerFrom || 'depart'}
|
|
349
293
|
activeTab
|
|
350
|
-
date={
|
|
294
|
+
date={doubleDate.current.first}
|
|
351
295
|
/>
|
|
352
296
|
<View style={{width: 4, height: '100%'}} />
|
|
353
297
|
<TabHeader
|
|
354
298
|
id={1}
|
|
355
|
-
ref={
|
|
356
|
-
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={
|
|
372
|
-
label={headerFrom || 'depart'}
|
|
315
|
+
ref={cellHeaderSingle}
|
|
316
|
+
label={props.headerFrom || 'depart'}
|
|
373
317
|
activeTab
|
|
374
|
-
date={
|
|
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
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
-
|
|
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};
|