@momo-kits/calendar 0.0.48-rc.2 → 0.0.48
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 +390 -0
- package/Day.tsx +220 -0
- package/HeaderControl.tsx +55 -0
- package/LunarDateConverter.ts +214 -0
- package/{src/LunarService.js → LunarService.ts} +85 -64
- package/Month.tsx +114 -0
- package/MonthList.tsx +282 -0
- package/TabHeader.tsx +90 -0
- package/Util.ts +293 -0
- package/holidayData.ts +125 -0
- package/index.tsx +479 -0
- package/package.json +18 -17
- package/publish.sh +17 -23
- package/styles.ts +127 -0
- package/types.ts +200 -0
- package/index.js +0 -4
- package/src/Calendar.js +0 -394
- package/src/CalendarPro.js +0 -363
- package/src/Day/index.js +0 -210
- package/src/Day/style.js +0 -129
- package/src/HeaderControl.js +0 -79
- package/src/LunarDateConverter.js +0 -191
- package/src/Month/index.js +0 -80
- package/src/Month/style.js +0 -0
- package/src/MonthList.js +0 -254
- package/src/TabHeader.js +0 -79
- package/src/Util.js +0 -225
- package/src/calendarPicker/Day.js +0 -154
- package/src/calendarPicker/Days.js +0 -203
- package/src/calendarPicker/HeaderControls.js +0 -158
- package/src/calendarPicker/WeekDaysLabels.js +0 -22
- package/src/calendarPicker/index.js +0 -125
- package/src/calendarPicker/styles.js +0 -184
- package/src/calendarPicker/util.js +0 -50
- package/src/holidayData.js +0 -127
package/src/CalendarPro.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
|
-
import React, { Component } from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
View,
|
|
7
|
-
Dimensions,
|
|
8
|
-
ScrollView,
|
|
9
|
-
TouchableWithoutFeedback,
|
|
10
|
-
StyleSheet
|
|
11
|
-
} from 'react-native';
|
|
12
|
-
import Moment from 'moment';
|
|
13
|
-
import {
|
|
14
|
-
Text, SwitchLanguage, LocalizedStrings, Colors, Image, IconSource
|
|
15
|
-
} from '@momo-kits/core';
|
|
16
|
-
import MonthList from './MonthList';
|
|
17
|
-
import HeaderControl from './HeaderControl';
|
|
18
|
-
import LunarDateConverter from './LunarDateConverter';
|
|
19
|
-
import Util from './Util';
|
|
20
|
-
|
|
21
|
-
const widthScreen = Dimensions.get('window').width;
|
|
22
|
-
|
|
23
|
-
export default class CalendarPro extends Component {
|
|
24
|
-
constructor(props) {
|
|
25
|
-
super(props);
|
|
26
|
-
this.today = Moment();
|
|
27
|
-
this.year = this.today.year();
|
|
28
|
-
this.getDateRange();
|
|
29
|
-
this.header = this.today.clone();
|
|
30
|
-
this.selectedDate = props.selectedDate;
|
|
31
|
-
this.state = {
|
|
32
|
-
startDate: props.startDate,
|
|
33
|
-
endDate: props.endDate,
|
|
34
|
-
showLunar: props.isShowLunar,
|
|
35
|
-
tabSelected: 0,
|
|
36
|
-
holidays: [],
|
|
37
|
-
ownUpdate: false,
|
|
38
|
-
};
|
|
39
|
-
this.converter = new LunarDateConverter();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
43
|
-
if (prevState.ownUpdate) {
|
|
44
|
-
return {
|
|
45
|
-
ownUpdate: false,
|
|
46
|
-
};
|
|
47
|
-
} if (nextProps.isShowLunar !== prevState.showLunar) {
|
|
48
|
-
return { showLunar: nextProps.isShowLunar };
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setDateRange = (dateRange, isScrollToStartDate) => {
|
|
54
|
-
if (dateRange && dateRange.startDate && dateRange.endDate) {
|
|
55
|
-
this.setState({ startDate: dateRange.startDate, endDate: dateRange.endDate }, () => {
|
|
56
|
-
const dateScroll = isScrollToStartDate ? dateRange.startDate : dateRange.endDate;
|
|
57
|
-
this.refs.MonthList.scrollToMonth(dateScroll);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
ownSetState(state) {
|
|
63
|
-
this.setState({ ...state, ownUpdate: true });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
loadLabel = (data, type) => {
|
|
67
|
-
const {
|
|
68
|
-
i18n,
|
|
69
|
-
customI18n
|
|
70
|
-
} = this.props;
|
|
71
|
-
if (~['w', 'weekday', 'text'].indexOf(type)) {
|
|
72
|
-
return (customI18n[type] || {})[data] || Util.I18N_MAP[i18n][type][data];
|
|
73
|
-
}
|
|
74
|
-
if (type === 'date') {
|
|
75
|
-
return data.format(customI18n[type] || Util.I18N_MAP[i18n][type]);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
getDateRange = () => {
|
|
80
|
-
const {
|
|
81
|
-
maxDate,
|
|
82
|
-
minDate,
|
|
83
|
-
format
|
|
84
|
-
} = this.props;
|
|
85
|
-
let max = Moment(maxDate, format);
|
|
86
|
-
let min = Moment(minDate, format);
|
|
87
|
-
const maxValid = max.isValid();
|
|
88
|
-
const minValid = min.isValid();
|
|
89
|
-
if (!maxValid && !minValid) {
|
|
90
|
-
max = Moment().add(12, 'months');
|
|
91
|
-
min = Moment();
|
|
92
|
-
}
|
|
93
|
-
if (!maxValid && minValid) {
|
|
94
|
-
max = min.add(12, 'months');
|
|
95
|
-
}
|
|
96
|
-
if (maxValid && !minValid) {
|
|
97
|
-
min = max.subtract(12, 'months');
|
|
98
|
-
}
|
|
99
|
-
if (min.isSameOrAfter(max)) return {};
|
|
100
|
-
this.minDate = min;
|
|
101
|
-
this.maxDate = max;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
onChoose = (day) => {
|
|
105
|
-
const {
|
|
106
|
-
startDate, tabSelected
|
|
107
|
-
} = this.state;
|
|
108
|
-
const { isDoubleDateMode, onDateChange } = this.props;
|
|
109
|
-
if (isDoubleDateMode) {
|
|
110
|
-
if (tabSelected === 1) {
|
|
111
|
-
if (startDate && day >= startDate) {
|
|
112
|
-
this.ownSetState({
|
|
113
|
-
endDate: day
|
|
114
|
-
});
|
|
115
|
-
} else if (startDate && day < startDate) {
|
|
116
|
-
this.ownSetState({
|
|
117
|
-
startDate: day,
|
|
118
|
-
endDate: null
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
this.ownSetState({
|
|
123
|
-
startDate: day
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
this.ownSetState({
|
|
128
|
-
startDate: day,
|
|
129
|
-
endDate: null,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
if (onDateChange) {
|
|
133
|
-
onDateChange(day);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
executeProcessAfterScrollCalendar = (date, key) => {
|
|
138
|
-
const holidays = Object.values(Util.getHolidaysInMonth(Moment(date)));
|
|
139
|
-
const {
|
|
140
|
-
showLunar
|
|
141
|
-
} = this.state;
|
|
142
|
-
if (this.refs && this.refs.HeaderControl) {
|
|
143
|
-
this.refs.HeaderControl.onUpdateInfo({ date });
|
|
144
|
-
this.header = date.clone().startOf('month');
|
|
145
|
-
}
|
|
146
|
-
let data = [];
|
|
147
|
-
if (!showLunar) {
|
|
148
|
-
data = holidays.filter((item) => !item.lunar || item.mixedLabel);
|
|
149
|
-
} else {
|
|
150
|
-
data = holidays;
|
|
151
|
-
}
|
|
152
|
-
this.ownSetState({ holidays, temp: data, headerKey: key });
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
onScrollCalendar = (data) => {
|
|
156
|
-
const { headerKey } = this.state;
|
|
157
|
-
if (data) {
|
|
158
|
-
if (data.key !== headerKey) {
|
|
159
|
-
this.executeProcessAfterScrollCalendar(data.date, data.key);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
setDoubleDateAndTabIndex = (firstDate, secondDate, tabSelected) => {
|
|
165
|
-
this.ownSetState({
|
|
166
|
-
startDate: firstDate ? Moment(firstDate) : null,
|
|
167
|
-
endDate: secondDate ? Moment(secondDate) : null,
|
|
168
|
-
tabSelected
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
toggleLunarDate = () => {
|
|
173
|
-
const { showLunar, holidays } = this.state;
|
|
174
|
-
const { onCallbackCalendar } = this.props;
|
|
175
|
-
let data = [];
|
|
176
|
-
const nextStateShowLunar = !showLunar;
|
|
177
|
-
if (!nextStateShowLunar) {
|
|
178
|
-
data = holidays.filter((item) => !item.lunar || item.mixedLabel);
|
|
179
|
-
} else {
|
|
180
|
-
data = holidays;
|
|
181
|
-
}
|
|
182
|
-
if (onCallbackCalendar) {
|
|
183
|
-
onCallbackCalendar('lunar', nextStateShowLunar);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
this.ownSetState({ showLunar: !showLunar, temp: data, ownUpdate: true });
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
onPressBackArrow = () => {
|
|
190
|
-
const previousDate = Moment(this.header).startOf('month').subtract(1, 'months');
|
|
191
|
-
if (this.refs && this.refs.HeaderControl && previousDate.isSameOrAfter(this.minDate, 'month')) {
|
|
192
|
-
this.header = previousDate;
|
|
193
|
-
this.refs.HeaderControl.onUpdateInfo({ date: previousDate });
|
|
194
|
-
this.refs.MonthList.scrollToMonth(previousDate);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
onPressNextArrow = () => {
|
|
199
|
-
const nextDate = Moment(this.header).startOf('month').add(1, 'months');
|
|
200
|
-
if (this.refs && this.refs.HeaderControl && nextDate.isSameOrBefore(this.maxDate, 'month')) {
|
|
201
|
-
this.header = nextDate;
|
|
202
|
-
this.refs.HeaderControl.onUpdateInfo({ date: nextDate });
|
|
203
|
-
this.refs.MonthList.scrollToMonth(nextDate);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
render() {
|
|
208
|
-
const {
|
|
209
|
-
startDate, endDate, showLunar, tabSelected, holidays, temp
|
|
210
|
-
} = this.state;
|
|
211
|
-
const {
|
|
212
|
-
i18n, isDoubleDateMode, priceList, labelFrom, labelTo, isHideLabel, isHideHoliday, isOffLunar
|
|
213
|
-
} = this.props;
|
|
214
|
-
let priceListFormat = priceList?.outbound;
|
|
215
|
-
if (isDoubleDateMode) {
|
|
216
|
-
priceListFormat = tabSelected === 0 ? priceList?.outbound : priceList?.inbound;
|
|
217
|
-
}
|
|
218
|
-
return (
|
|
219
|
-
<View style={styles.container}>
|
|
220
|
-
<View style={styles.viewDate}>
|
|
221
|
-
<HeaderControl
|
|
222
|
-
ref="HeaderControl"
|
|
223
|
-
// selectedDate={this.selectedDate}
|
|
224
|
-
onPressBackArrow={this.onPressBackArrow}
|
|
225
|
-
onPressNextArrow={this.onPressNextArrow}
|
|
226
|
-
/>
|
|
227
|
-
<View style={styles.viewDay}>
|
|
228
|
-
{[1, 2, 3, 4, 5, 6, 7].map((item) => (
|
|
229
|
-
<Text
|
|
230
|
-
style={[styles.textDay, { color: item === 6 || item === 7 ? Colors.red_05 : Colors.black_12 }]}
|
|
231
|
-
key={item}
|
|
232
|
-
>
|
|
233
|
-
{Util.mapWeeKDate(item)}
|
|
234
|
-
</Text>
|
|
235
|
-
)
|
|
236
|
-
)}
|
|
237
|
-
</View>
|
|
238
|
-
<MonthList
|
|
239
|
-
ref="MonthList"
|
|
240
|
-
today={this.today}
|
|
241
|
-
minDate={this.minDate}
|
|
242
|
-
maxDate={this.maxDate}
|
|
243
|
-
startDate={startDate}
|
|
244
|
-
endDate={endDate}
|
|
245
|
-
onChoose={this.onChoose}
|
|
246
|
-
i18n={i18n}
|
|
247
|
-
onScrollCalendar={this.onScrollCalendar}
|
|
248
|
-
isShowLunar={!isOffLunar && showLunar}
|
|
249
|
-
isDoubleDateMode={isDoubleDateMode}
|
|
250
|
-
tabSelected={tabSelected}
|
|
251
|
-
lunarConverter={this.converter}
|
|
252
|
-
holidays={holidays}
|
|
253
|
-
selectedDate={this.selectedDate}
|
|
254
|
-
priceList={priceListFormat}
|
|
255
|
-
labelFrom={labelFrom}
|
|
256
|
-
labelTo={labelTo}
|
|
257
|
-
isHideLabel={isHideLabel}
|
|
258
|
-
/>
|
|
259
|
-
</View>
|
|
260
|
-
{
|
|
261
|
-
!isOffLunar && (
|
|
262
|
-
<View style={styles.viewLunar}>
|
|
263
|
-
<TouchableWithoutFeedback onPress={this.toggleLunarDate}>
|
|
264
|
-
<Image source={showLunar ? IconSource.ic_checkbox_checked_24 : IconSource.ic_checkbox_unchecked_24} style={styles.iconSelected} />
|
|
265
|
-
</TouchableWithoutFeedback>
|
|
266
|
-
<Text.SubTitle
|
|
267
|
-
style={styles.txtLunar}
|
|
268
|
-
onPress={this.toggleLunarDate}
|
|
269
|
-
>
|
|
270
|
-
{SwitchLanguage.showLunar}
|
|
271
|
-
</Text.SubTitle>
|
|
272
|
-
</View>
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
{
|
|
277
|
-
!isHideHoliday && (
|
|
278
|
-
<ScrollView
|
|
279
|
-
contentContainerStyle={styles.contentScroll}
|
|
280
|
-
showsVerticalScrollIndicator={false}
|
|
281
|
-
enabledNestedScroll
|
|
282
|
-
>
|
|
283
|
-
{temp && temp.length > 0 && temp.map((item, idx) => {
|
|
284
|
-
const labelHoliday = showLunar ? (item.mixedLabel || item.label || '') : (item.label || '');
|
|
285
|
-
const labelHighlight = showLunar ? (item.highlight || '') : '';
|
|
286
|
-
const labelDate = LocalizedStrings.defaultLanguage === 'en' ? `${Util.mapMonthShorten(item.month)} ${item.day}` : `${item.day} tháng ${item.month}`;
|
|
287
|
-
return (
|
|
288
|
-
<View style={styles.row} key={idx.toString()}>
|
|
289
|
-
<Text.SubTitle style={styles.txtMonthLunar}>
|
|
290
|
-
{labelDate}
|
|
291
|
-
</Text.SubTitle>
|
|
292
|
-
<Text.SubTitle style={styles.subTextLunar}>
|
|
293
|
-
{`${labelHoliday} `}
|
|
294
|
-
{
|
|
295
|
-
labelHighlight ? <Text style={{ color: Colors.red_05 }}>{labelHighlight}</Text> : ''
|
|
296
|
-
}
|
|
297
|
-
</Text.SubTitle>
|
|
298
|
-
</View>
|
|
299
|
-
);
|
|
300
|
-
})}
|
|
301
|
-
</ScrollView>
|
|
302
|
-
)
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
</View>
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
CalendarPro.propTypes = {
|
|
311
|
-
i18n: PropTypes.string,
|
|
312
|
-
format: PropTypes.string,
|
|
313
|
-
customI18n: PropTypes.object,
|
|
314
|
-
isShowLunar: PropTypes.bool,
|
|
315
|
-
onCallbackCalendar: PropTypes.func,
|
|
316
|
-
minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
|
|
317
|
-
maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)])
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
CalendarPro.defaultProps = {
|
|
321
|
-
format: 'YYYY-MM-DD',
|
|
322
|
-
i18n: 'vi',
|
|
323
|
-
customI18n: {},
|
|
324
|
-
isShowLunar: true
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
const styles = StyleSheet.create({
|
|
328
|
-
row: { flexDirection: 'row' },
|
|
329
|
-
txtMonthLunar: { color: Colors.red_05, width: 80 },
|
|
330
|
-
subTextLunar: {
|
|
331
|
-
// fontSize: 12,
|
|
332
|
-
color: '#222222',
|
|
333
|
-
paddingLeft: 6,
|
|
334
|
-
flexShrink: 1
|
|
335
|
-
},
|
|
336
|
-
contentScroll: { paddingHorizontal: 12, paddingVertical: 10 },
|
|
337
|
-
iconSelected: { width: 24, height: 24, resizeMode: 'cover' },
|
|
338
|
-
txtLunar: {
|
|
339
|
-
paddingLeft: 6,
|
|
340
|
-
color: '#222222',
|
|
341
|
-
// fontSize: 12,
|
|
342
|
-
lineHeight: 14
|
|
343
|
-
},
|
|
344
|
-
viewLunar: {
|
|
345
|
-
flexDirection: 'row', alignItems: 'center', marginHorizontal: 12, paddingVertical: 12, borderBottomWidth: 1, borderStyle: 'solid', borderColor: '#c7c7cd'
|
|
346
|
-
},
|
|
347
|
-
viewDate: { paddingHorizontal: 12 },
|
|
348
|
-
textDay: {
|
|
349
|
-
// fontSize: 14,
|
|
350
|
-
lineHeight: 16,
|
|
351
|
-
width: (widthScreen - 38) / 7,
|
|
352
|
-
textAlign: 'center',
|
|
353
|
-
fontWeight: 'bold',
|
|
354
|
-
},
|
|
355
|
-
viewDay: {
|
|
356
|
-
flexDirection: 'row',
|
|
357
|
-
justifyContent: 'space-between',
|
|
358
|
-
paddingHorizontal: 7,
|
|
359
|
-
paddingTop: 15,
|
|
360
|
-
paddingBottom: 10,
|
|
361
|
-
},
|
|
362
|
-
container: { flex: 1, backgroundColor: 'white', marginTop: 20, },
|
|
363
|
-
});
|
package/src/Day/index.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import React, {Component} from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
import {View, TouchableHighlight, Text} from 'react-native';
|
|
5
|
-
import {Colors, SwitchLanguage} from '@momo-kits/core';
|
|
6
|
-
import style from './style';
|
|
7
|
-
|
|
8
|
-
class Day extends Component {
|
|
9
|
-
constructor(props) {
|
|
10
|
-
super(props);
|
|
11
|
-
this.statusCheck();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
chooseDay = () => {
|
|
15
|
-
const {onChoose, date} = this.props;
|
|
16
|
-
onChoose && onChoose(date);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
findHoliday = (date, holidays) => {
|
|
20
|
-
if (date && holidays && holidays.length > 0) {
|
|
21
|
-
const day = date.date();
|
|
22
|
-
const month = date.month() + 1;
|
|
23
|
-
return holidays.find(item => item.day === day && item.month === month);
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
checkHoliday = (date, holidays) => {
|
|
29
|
-
const holiday = this.findHoliday(date, holidays);
|
|
30
|
-
return {
|
|
31
|
-
solarHoliday: !!(holiday && !holiday.lunar),
|
|
32
|
-
lunarHoliday: !!(holiday && holiday.lunar),
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
statusCheck = props => {
|
|
37
|
-
const {
|
|
38
|
-
startDate,
|
|
39
|
-
endDate,
|
|
40
|
-
date = null,
|
|
41
|
-
minDate,
|
|
42
|
-
maxDate,
|
|
43
|
-
empty,
|
|
44
|
-
index,
|
|
45
|
-
isShowLunar,
|
|
46
|
-
tabSelected,
|
|
47
|
-
isDoubleDateMode,
|
|
48
|
-
lunarDate,
|
|
49
|
-
isSolarHoliday,
|
|
50
|
-
isLunarHoliday,
|
|
51
|
-
price,
|
|
52
|
-
} = props || this.props;
|
|
53
|
-
this.isValid =
|
|
54
|
-
date &&
|
|
55
|
-
(date >= minDate || date.isSame(minDate, 'day')) &&
|
|
56
|
-
(date <= maxDate || date.isSame(maxDate, 'day'));
|
|
57
|
-
this.isMid =
|
|
58
|
-
(isDoubleDateMode && date > startDate && date < endDate) ||
|
|
59
|
-
(!date && empty >= startDate && empty <= endDate);
|
|
60
|
-
this.isStart = date && date.isSame(startDate, 'd');
|
|
61
|
-
this.isStartPart = this.isStart && endDate;
|
|
62
|
-
this.isEnd = isDoubleDateMode && date && date.isSame(endDate, 'day');
|
|
63
|
-
this.isFocus = this.isMid || this.isStart || this.isEnd;
|
|
64
|
-
this.isWeekEnd = index === 6 || index === 5;
|
|
65
|
-
this.showLunar = isShowLunar;
|
|
66
|
-
this.lunarDate = lunarDate;
|
|
67
|
-
this.isDoubleDateMode = isDoubleDateMode;
|
|
68
|
-
this.isLunarHoliday = isLunarHoliday;
|
|
69
|
-
this.isLunarDayStart = this.lunarDate && this.lunarDate.lunarDay === 1;
|
|
70
|
-
this.isSolarHoliday = isSolarHoliday;
|
|
71
|
-
this.isInScope = isDoubleDateMode
|
|
72
|
-
? tabSelected === 0 ||
|
|
73
|
-
(tabSelected === 1 &&
|
|
74
|
-
startDate &&
|
|
75
|
-
date &&
|
|
76
|
-
date.isSameOrAfter(startDate, 'day'))
|
|
77
|
-
: true;
|
|
78
|
-
return this.isFocus || this.diffPrice;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
shouldComponentUpdate(nextProps) {
|
|
82
|
-
const {
|
|
83
|
-
isDoubleDateMode,
|
|
84
|
-
isShowLunar,
|
|
85
|
-
tabSelected,
|
|
86
|
-
isSolarHoliday,
|
|
87
|
-
isLunarHoliday,
|
|
88
|
-
price,
|
|
89
|
-
isBestPrice,
|
|
90
|
-
startDate,
|
|
91
|
-
endDate,
|
|
92
|
-
} = this.props;
|
|
93
|
-
const prevStatus = this.isFocus;
|
|
94
|
-
const selectionModeChange = isDoubleDateMode !== nextProps.isDoubleDateMode;
|
|
95
|
-
const lunarChange = isShowLunar !== nextProps.isShowLunar;
|
|
96
|
-
const nextStatus = this.statusCheck(nextProps);
|
|
97
|
-
const tabChange = tabSelected !== nextProps.tabSelected;
|
|
98
|
-
const solarHoliday = isSolarHoliday !== nextProps.isSolarHoliday;
|
|
99
|
-
const lunarHoliday = isLunarHoliday !== nextProps.isLunarHoliday;
|
|
100
|
-
const diffPrice =
|
|
101
|
-
price !== nextProps.price && isBestPrice !== nextProps.isBestPrice;
|
|
102
|
-
const startDateChange =
|
|
103
|
-
startDate && !startDate?.isSame?.(nextProps.startDate, 'day');
|
|
104
|
-
const endDateChange =
|
|
105
|
-
endDate && !endDate?.isSame?.(nextProps.endDate, 'day');
|
|
106
|
-
return !!(
|
|
107
|
-
prevStatus !== nextStatus ||
|
|
108
|
-
selectionModeChange ||
|
|
109
|
-
lunarChange ||
|
|
110
|
-
tabChange ||
|
|
111
|
-
solarHoliday ||
|
|
112
|
-
lunarHoliday ||
|
|
113
|
-
diffPrice ||
|
|
114
|
-
startDateChange ||
|
|
115
|
-
endDateChange
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
render() {
|
|
120
|
-
const {
|
|
121
|
-
date,
|
|
122
|
-
empty,
|
|
123
|
-
isDoubleDateMode,
|
|
124
|
-
price,
|
|
125
|
-
isBestPrice,
|
|
126
|
-
isShowPrice,
|
|
127
|
-
labelFrom,
|
|
128
|
-
labelTo,
|
|
129
|
-
isHideLabel,
|
|
130
|
-
} = this.props;
|
|
131
|
-
const text = date ? date.date() : '';
|
|
132
|
-
return (
|
|
133
|
-
<View style={style.dayContainer}>
|
|
134
|
-
<View
|
|
135
|
-
style={[
|
|
136
|
-
this.isMid && !empty && style.mid,
|
|
137
|
-
this.isStartPart && style.dayStartContainer,
|
|
138
|
-
this.isEnd && style.dayEndContainer,
|
|
139
|
-
]}>
|
|
140
|
-
{this.isValid && this.isInScope ? (
|
|
141
|
-
<TouchableHighlight
|
|
142
|
-
style={[style.day, (this.isStart || this.isEnd) && style.focused]}
|
|
143
|
-
underlayColor="rgba(255, 255, 255, 0.35)"
|
|
144
|
-
onPress={this.chooseDay}>
|
|
145
|
-
<>
|
|
146
|
-
<Text
|
|
147
|
-
style={[
|
|
148
|
-
style.dayText,
|
|
149
|
-
this.isWeekEnd && style.weekendDay,
|
|
150
|
-
this.isSolarHoliday && style.weekendDay,
|
|
151
|
-
(this.isStart || this.isEnd) && style.focusedText,
|
|
152
|
-
]}>
|
|
153
|
-
{text}
|
|
154
|
-
</Text>
|
|
155
|
-
{this.lunarDate && this.showLunar && (
|
|
156
|
-
<Text
|
|
157
|
-
style={[
|
|
158
|
-
style.lunarDayText,
|
|
159
|
-
(this.isLunarHoliday || this.isLunarDayStart) &&
|
|
160
|
-
style.weekendDay,
|
|
161
|
-
(this.isStart || this.isEnd) && style.focusedText,
|
|
162
|
-
]}>
|
|
163
|
-
{this.lunarDate.lunarDay === 1
|
|
164
|
-
? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
|
|
165
|
-
: this.lunarDate.lunarDay}
|
|
166
|
-
</Text>
|
|
167
|
-
)}
|
|
168
|
-
</>
|
|
169
|
-
</TouchableHighlight>
|
|
170
|
-
) : (
|
|
171
|
-
<View style={[style.day]}>
|
|
172
|
-
<Text style={[style.dayText, style.dayTextDisabled]}>{text}</Text>
|
|
173
|
-
{this.lunarDate && this.showLunar && text ? (
|
|
174
|
-
<Text style={[style.lunarDayText, style.dayTextDisabled]}>
|
|
175
|
-
{this.lunarDate.lunarDay === 1
|
|
176
|
-
? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}`
|
|
177
|
-
: this.lunarDate.lunarDay}
|
|
178
|
-
</Text>
|
|
179
|
-
) : (
|
|
180
|
-
<View />
|
|
181
|
-
)}
|
|
182
|
-
</View>
|
|
183
|
-
)}
|
|
184
|
-
</View>
|
|
185
|
-
|
|
186
|
-
{isDoubleDateMode && this.isStart && !isHideLabel && (
|
|
187
|
-
<View style={style.txtGo}>
|
|
188
|
-
<Text style={{fontSize: 8, color: 'white'}}>
|
|
189
|
-
{labelFrom || SwitchLanguage.departing}
|
|
190
|
-
</Text>
|
|
191
|
-
</View>
|
|
192
|
-
)}
|
|
193
|
-
{isDoubleDateMode && this.isEnd && !isHideLabel && (
|
|
194
|
-
<View style={style.txtBack}>
|
|
195
|
-
<Text style={{fontSize: 8, color: 'white'}}>
|
|
196
|
-
{labelTo || SwitchLanguage.returning}
|
|
197
|
-
</Text>
|
|
198
|
-
</View>
|
|
199
|
-
)}
|
|
200
|
-
{this.isValid && this.isInScope && !!price && (
|
|
201
|
-
<Text style={[style.price, isBestPrice && {color: Colors.pink_05_b}]}>
|
|
202
|
-
{price}
|
|
203
|
-
</Text>
|
|
204
|
-
)}
|
|
205
|
-
</View>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export default Day;
|
package/src/Day/style.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Dimensions } from 'react-native';
|
|
2
|
-
import { Colors } from '@momo-kits/core';
|
|
3
|
-
|
|
4
|
-
const dayWidth = (Dimensions.get('window').width - 38) / 7;
|
|
5
|
-
const SCREEN_WIDTH = Dimensions.get('window').width;
|
|
6
|
-
const SCREEN_DPI_WIDTH = (SCREEN_WIDTH * Dimensions.get('window').scale);
|
|
7
|
-
const IPHONE_4_5_WIDTH = 640;
|
|
8
|
-
const dayTextSize = SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 13 : 15;
|
|
9
|
-
const lunarTextSize = SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 8 : 10;
|
|
10
|
-
const priceTextSize = SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 8 : 10;
|
|
11
|
-
const lineHeightDayText = 1.3 * dayTextSize;
|
|
12
|
-
const lineHeightLunarText = 1.3 * lunarTextSize;
|
|
13
|
-
const lineHeightPriceText = 1.3 * priceTextSize;
|
|
14
|
-
const containerDayHeight = lineHeightDayText + lineHeightLunarText + lineHeightPriceText + 10;
|
|
15
|
-
const heightDefault = lineHeightDayText + lineHeightLunarText;
|
|
16
|
-
export default {
|
|
17
|
-
dayContainer: {
|
|
18
|
-
width: dayWidth,
|
|
19
|
-
borderRadius: 4,
|
|
20
|
-
alignItems: 'center',
|
|
21
|
-
height: containerDayHeight,
|
|
22
|
-
},
|
|
23
|
-
day: {
|
|
24
|
-
width: dayWidth,
|
|
25
|
-
paddingVertical: 5,
|
|
26
|
-
overflow: 'hidden',
|
|
27
|
-
justifyContent: 'center',
|
|
28
|
-
alignItems: 'center',
|
|
29
|
-
borderRadius: 4,
|
|
30
|
-
height: heightDefault + 5
|
|
31
|
-
},
|
|
32
|
-
dayText: {
|
|
33
|
-
fontSize: dayTextSize,
|
|
34
|
-
textAlign: 'center',
|
|
35
|
-
fontWeight: 'bold',
|
|
36
|
-
color: '#222222'
|
|
37
|
-
},
|
|
38
|
-
lunarDayText: {
|
|
39
|
-
width: dayWidth,
|
|
40
|
-
textAlign: 'right',
|
|
41
|
-
fontSize: SCREEN_DPI_WIDTH === IPHONE_4_5_WIDTH ? 8 : 10,
|
|
42
|
-
paddingRight: 5,
|
|
43
|
-
color: '#222222'
|
|
44
|
-
},
|
|
45
|
-
todayText: {
|
|
46
|
-
color: 'blue'
|
|
47
|
-
},
|
|
48
|
-
weekendDay: {
|
|
49
|
-
color: '#e82956'
|
|
50
|
-
},
|
|
51
|
-
dayTextDisabled: {
|
|
52
|
-
opacity: 0.2
|
|
53
|
-
},
|
|
54
|
-
focused: {
|
|
55
|
-
backgroundColor: Colors.pink_05_b
|
|
56
|
-
},
|
|
57
|
-
focusedText: {
|
|
58
|
-
color: 'white'
|
|
59
|
-
},
|
|
60
|
-
dayStartContainer: {
|
|
61
|
-
borderTopLeftRadius: 4,
|
|
62
|
-
borderBottomLeftRadius: 4,
|
|
63
|
-
backgroundColor: Colors.pink_09,
|
|
64
|
-
// height: heightDefault
|
|
65
|
-
},
|
|
66
|
-
dayEndContainer: {
|
|
67
|
-
borderTopRightRadius: 4,
|
|
68
|
-
borderBottomRightRadius: 4,
|
|
69
|
-
backgroundColor: Colors.pink_09,
|
|
70
|
-
// height: heightDefault
|
|
71
|
-
},
|
|
72
|
-
mid: {
|
|
73
|
-
backgroundColor: Colors.pink_09,
|
|
74
|
-
// height: heightDefault
|
|
75
|
-
},
|
|
76
|
-
departLabel: {
|
|
77
|
-
position: 'absolute',
|
|
78
|
-
backgroundColor: 'yellow',
|
|
79
|
-
width: 20,
|
|
80
|
-
height: 20,
|
|
81
|
-
borderRadius: 10,
|
|
82
|
-
justifyContent: 'center',
|
|
83
|
-
alignItems: 'center'
|
|
84
|
-
},
|
|
85
|
-
returnLabel: {
|
|
86
|
-
position: 'absolute',
|
|
87
|
-
backgroundColor: 'yellow',
|
|
88
|
-
width: 20,
|
|
89
|
-
height: 20,
|
|
90
|
-
borderRadius: 10,
|
|
91
|
-
justifyContent: 'center',
|
|
92
|
-
alignItems: 'center',
|
|
93
|
-
top: 0,
|
|
94
|
-
right: 0
|
|
95
|
-
},
|
|
96
|
-
containerDayHeight,
|
|
97
|
-
txtBack: {
|
|
98
|
-
position: 'absolute',
|
|
99
|
-
backgroundColor: '#ffbb1e',
|
|
100
|
-
borderRadius: 100,
|
|
101
|
-
top: -2,
|
|
102
|
-
right: -2,
|
|
103
|
-
zIndex: 999,
|
|
104
|
-
padding: 2,
|
|
105
|
-
width: 15,
|
|
106
|
-
height: 15,
|
|
107
|
-
justifyContent: 'center',
|
|
108
|
-
alignItems: 'center'
|
|
109
|
-
},
|
|
110
|
-
txtGo: {
|
|
111
|
-
position: 'absolute',
|
|
112
|
-
backgroundColor: '#ffbb1e',
|
|
113
|
-
top: -2,
|
|
114
|
-
left: -2,
|
|
115
|
-
borderRadius: 100,
|
|
116
|
-
padding: 2,
|
|
117
|
-
zIndex: 999,
|
|
118
|
-
width: 15,
|
|
119
|
-
height: 15,
|
|
120
|
-
justifyContent: 'center',
|
|
121
|
-
alignItems: 'center'
|
|
122
|
-
},
|
|
123
|
-
price: {
|
|
124
|
-
fontSize: priceTextSize,
|
|
125
|
-
lineHeight: lineHeightPriceText,
|
|
126
|
-
color: '#8d919d'
|
|
127
|
-
},
|
|
128
|
-
lineHeightPriceText
|
|
129
|
-
};
|