@momo-kits/calendar 0.0.52-beta → 0.0.52-beta.1

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/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
- "name": "@momo-kits/calendar",
3
- "version": "0.0.52-beta",
4
- "private": false,
5
- "main": "index.js",
6
- "dependencies": {
7
- "@momo-kits/date-picker": "latest"
8
- },
9
- "peerDependencies": {
10
- "react": "16.9.0",
11
- "react-native": ">=0.55",
12
- "prop-types": "^15.7.2",
13
- "moment": "^2.24.0",
14
- "@momo-kits/core": ">=0.0.5-beta"
15
- },
16
- "devDependencies": {},
17
- "license": "MoMo"
2
+ "name": "@momo-kits/calendar",
3
+ "version": "0.0.52-beta.1",
4
+ "private": false,
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "@momo-kits/date-picker": "latest",
8
+ "moment": "^2.24.0",
9
+ "@momo-platform/versions": "4.0.2"
10
+ },
11
+ "peerDependencies": {
12
+ "react": "16.9.0",
13
+ "react-native": ">=0.55",
14
+ "prop-types": "^15.7.2",
15
+ "@momo-kits/core": ">=0.0.5-beta"
16
+ },
17
+ "devDependencies": {},
18
+ "license": "MoMo"
18
19
  }
package/publish.sh CHANGED
@@ -21,9 +21,9 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
21
21
  #npm login
22
22
  #publish dist to npm
23
23
  cd dist
24
- npm publish --access=public
24
+ npm publish --tag beta --access=public
25
25
  cd ..
26
26
  rm -rf dist
27
27
 
28
28
 
29
- # -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'
29
+ #curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/calendar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/calendar"}'
package/src/Calendar.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import PropTypes from 'prop-types';
2
- import React, { Component, } from 'react';
3
- import {
4
- View, Switch, ScrollView, Platform, StyleSheet
5
- } from 'react-native';
2
+ import React, { Component } from 'react';
3
+ import { View, Switch, ScrollView, Platform, StyleSheet } from 'react-native';
6
4
  import moment from 'moment';
7
5
  import { Text, SwitchLanguage } from '@momo-kits/core';
8
6
  import CalendarPro from './CalendarPro';
@@ -13,15 +11,23 @@ const DOUBLE = 'doubleDate';
13
11
  class Calendar extends Component {
14
12
  constructor(props) {
15
13
  super(props);
16
- this.doubleDate = props.doubleDate ? {
17
- first: props.doubleDate.first ? moment(props.doubleDate.first) : null,
18
- second: props.doubleDate.second ? moment(props.doubleDate.second) : null
19
- } : {};
14
+ this.doubleDate = props.doubleDate
15
+ ? {
16
+ first: props.doubleDate.first
17
+ ? moment(props.doubleDate.first)
18
+ : null,
19
+ second: props.doubleDate.second
20
+ ? moment(props.doubleDate.second)
21
+ : null,
22
+ }
23
+ : {};
20
24
  this.tabSelected = 0;
21
- this.selectedDate = props.selectedDate ? moment(props.selectedDate) : moment();
25
+ this.selectedDate = props.selectedDate
26
+ ? moment(props.selectedDate)
27
+ : moment();
22
28
 
23
29
  this.state = {
24
- isDoubleDateMode: props.mode === DOUBLE
30
+ isDoubleDateMode: props.mode === DOUBLE,
25
31
  };
26
32
  this.calendarPicker = React.createRef();
27
33
  this.cellHeader1 = React.createRef();
@@ -38,19 +44,41 @@ class Calendar extends Component {
38
44
  viewInit() {
39
45
  const { mode } = this.props;
40
46
  if (mode === DOUBLE) {
41
- if (this.cellHeader1.current && this.cellHeader2.current && this.calendarPicker.current) {
42
- const start = this.doubleDate.first ? this.doubleDate.first : null;
43
- const end = this.doubleDate.second ? this.doubleDate.second : null;
44
- this.cellHeader1.current.updateView(start, this.tabSelected === 0);
45
- this.cellHeader2.current.updateView(end, this.tabSelected === 1);
46
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
47
+ if (
48
+ this.cellHeader1.current &&
49
+ this.cellHeader2.current &&
50
+ this.calendarPicker.current
51
+ ) {
52
+ const start = this.doubleDate.first
53
+ ? this.doubleDate.first
54
+ : null;
55
+ const end = this.doubleDate.second
56
+ ? this.doubleDate.second
57
+ : null;
58
+ this.cellHeader1.current.updateView(
59
+ start,
60
+ this.tabSelected === 0,
61
+ );
62
+ this.cellHeader2.current.updateView(
63
+ end,
64
+ this.tabSelected === 1,
65
+ );
66
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
67
+ this.doubleDate.first,
68
+ this.doubleDate.second,
69
+ this.tabSelected,
70
+ );
47
71
  }
48
72
  } else if (this.calendarPicker.current) {
49
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate);
73
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
74
+ this.selectedDate,
75
+ );
50
76
  }
51
77
  }
52
78
 
53
79
  onChangeTab = (idTab) => {
80
+ this.props.onChangeTab && this.props.onChangeTab(idTab);
81
+
54
82
  this.tabSelected = idTab;
55
83
  if (this.cellHeader1.current && this.cellHeader2.current) {
56
84
  this.cellHeader1.current.setActiveTab(idTab === 0);
@@ -61,19 +89,38 @@ class Calendar extends Component {
61
89
 
62
90
  updateViewFlowPicker() {
63
91
  if (this.calendarPicker.current) {
64
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
92
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
93
+ this.doubleDate.first,
94
+ this.doubleDate.second,
95
+ this.tabSelected,
96
+ );
65
97
  }
66
98
  }
67
99
 
68
100
  processDateFirst() {
69
101
  const { onDateChange, onCTAStateChange } = this.props;
70
- if (this.cellHeader1.current && this.cellHeader2.current && this.calendarPicker.current) {
71
- if (this.doubleDate.first && this.doubleDate.second && this.selectedDate <= this.doubleDate.second) {
102
+ if (
103
+ this.cellHeader1.current &&
104
+ this.cellHeader2.current &&
105
+ this.calendarPicker.current
106
+ ) {
107
+ if (
108
+ this.doubleDate.first &&
109
+ this.doubleDate.second &&
110
+ this.selectedDate <= this.doubleDate.second
111
+ ) {
72
112
  this.doubleDate.first = this.selectedDate;
73
113
  this.tabSelected = 1;
74
- this.cellHeader1.current.updateView(this.selectedDate, this.tabSelected === 0);
114
+ this.cellHeader1.current.updateView(
115
+ this.selectedDate,
116
+ this.tabSelected === 0,
117
+ );
75
118
  this.cellHeader2.current.setActiveTab(this.tabSelected === 1);
76
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
119
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
120
+ this.doubleDate.first,
121
+ this.doubleDate.second,
122
+ this.tabSelected,
123
+ );
77
124
  if (onDateChange) {
78
125
  // const cloned = {
79
126
  // first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
@@ -82,8 +129,12 @@ class Calendar extends Component {
82
129
  // this.doubleDate.second ? new Date(this.doubleDate.second.year(), this.doubleDate.second.month(), this.doubleDate.second.date()) : null
83
130
  // };
84
131
  onDateChange({
85
- first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
86
- second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
132
+ first: this.doubleDate.first
133
+ ? this.doubleDate.first.toDate()
134
+ : null,
135
+ second: this.doubleDate.second
136
+ ? this.doubleDate.second.toDate()
137
+ : null,
87
138
  });
88
139
  }
89
140
  } else {
@@ -92,11 +143,19 @@ class Calendar extends Component {
92
143
  this.cellHeader1.current.updateView(this.selectedDate, false);
93
144
  this.cellHeader2.current.updateView(null, true);
94
145
  this.tabSelected = 1;
95
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
146
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
147
+ this.doubleDate.first,
148
+ this.doubleDate.second,
149
+ this.tabSelected,
150
+ );
96
151
  if (onDateChange) {
97
152
  onDateChange({
98
- first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
99
- second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
153
+ first: this.doubleDate.first
154
+ ? this.doubleDate.first.toDate()
155
+ : null,
156
+ second: this.doubleDate.second
157
+ ? this.doubleDate.second.toDate()
158
+ : null,
100
159
  });
101
160
  // const cloned = {
102
161
  // first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
@@ -107,7 +166,7 @@ class Calendar extends Component {
107
166
  }
108
167
  }
109
168
  if (onCTAStateChange) {
110
- onCTAStateChange(!!(this.doubleDate.second));
169
+ onCTAStateChange(!!this.doubleDate.second);
111
170
  }
112
171
  }
113
172
 
@@ -118,14 +177,22 @@ class Calendar extends Component {
118
177
  this.cellHeader1.current.setActiveTab(true);
119
178
  this.doubleDate.second = this.selectedDate;
120
179
  this.tabSelected = 0;
121
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.doubleDate.first, this.doubleDate.second, this.tabSelected);
180
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
181
+ this.doubleDate.first,
182
+ this.doubleDate.second,
183
+ this.tabSelected,
184
+ );
122
185
  if (onCTAStateChange) {
123
- onCTAStateChange(!!(this.doubleDate.second));
186
+ onCTAStateChange(!!this.doubleDate.second);
124
187
  }
125
188
  if (onDateChange) {
126
189
  onDateChange({
127
- first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
128
- second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
190
+ first: this.doubleDate.first
191
+ ? this.doubleDate.first.toDate()
192
+ : null,
193
+ second: this.doubleDate.second
194
+ ? this.doubleDate.second.toDate()
195
+ : null,
129
196
  });
130
197
  // const cloned = {
131
198
  // first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
@@ -152,7 +219,10 @@ class Calendar extends Component {
152
219
  this.processDoubleDate();
153
220
  } else {
154
221
  if (this.cellHeaderSingle.current) {
155
- this.cellHeaderSingle.current.updateView(this.selectedDate, true);
222
+ this.cellHeaderSingle.current.updateView(
223
+ this.selectedDate,
224
+ true,
225
+ );
156
226
  }
157
227
  if (onDateChange) {
158
228
  const date = new Date(this.selectedDate.toDate());
@@ -164,7 +234,7 @@ class Calendar extends Component {
164
234
  onDateChange = (date) => {
165
235
  this.selectedDate = date;
166
236
  this.updateView();
167
- }
237
+ };
168
238
 
169
239
  updateHeaderView = () => {
170
240
  const { onDateChange, onCTAStateChange } = this.props;
@@ -173,7 +243,11 @@ class Calendar extends Component {
173
243
  if (this.cellHeader1.current && this.cellHeader2.current) {
174
244
  this.cellHeader1.current.updateView(this.selectedDate, true);
175
245
  this.cellHeader2.current.updateView(null, false);
176
- this.calendarPicker.current.setDoubleDateAndTabIndex(this.selectedDate, null, this.tabSelected);
246
+ this.calendarPicker.current.setDoubleDateAndTabIndex(
247
+ this.selectedDate,
248
+ null,
249
+ this.tabSelected,
250
+ );
177
251
  this.doubleDate.first = moment(this.selectedDate);
178
252
  this.doubleDate.second = null;
179
253
  this.tabSelected = 0;
@@ -183,8 +257,12 @@ class Calendar extends Component {
183
257
  }
184
258
  if (onDateChange) {
185
259
  onDateChange({
186
- first: this.doubleDate.first ? this.doubleDate.first.toDate() : null,
187
- second: this.doubleDate.second ? this.doubleDate.second.toDate() : null
260
+ first: this.doubleDate.first
261
+ ? this.doubleDate.first.toDate()
262
+ : null,
263
+ second: this.doubleDate.second
264
+ ? this.doubleDate.second.toDate()
265
+ : null,
188
266
  });
189
267
  // const cloned = {
190
268
  // first: this.doubleDate.first ? new Date(this.doubleDate.first.year(), this.doubleDate.first.month(), this.doubleDate.first.date()) : null,
@@ -199,10 +277,16 @@ class Calendar extends Component {
199
277
  }
200
278
  if (this.cellHeaderSingle.current) {
201
279
  if (this.doubleDate.first) {
202
- this.cellHeaderSingle.current.updateView(this.doubleDate.first, true);
280
+ this.cellHeaderSingle.current.updateView(
281
+ this.doubleDate.first,
282
+ true,
283
+ );
203
284
  this.selectedDate = this.doubleDate.first;
204
285
  } else {
205
- this.cellHeaderSingle.current.updateView(this.selectedDate, true);
286
+ this.cellHeaderSingle.current.updateView(
287
+ this.selectedDate,
288
+ true,
289
+ );
206
290
  }
207
291
 
208
292
  if (onDateChange) {
@@ -216,13 +300,19 @@ class Calendar extends Component {
216
300
 
217
301
  toggleSelectionDateMode = () => {
218
302
  const { onCallbackCalendar } = this.props;
219
- this.setState((preState) => ({ isDoubleDateMode: !preState.isDoubleDateMode }), () => {
220
- const { isDoubleDateMode } = this.state;
221
- this.updateHeaderView();
222
- if (onCallbackCalendar && typeof onCallbackCalendar === 'function') {
223
- onCallbackCalendar('switch', isDoubleDateMode);
224
- }
225
- });
303
+ this.setState(
304
+ (preState) => ({ isDoubleDateMode: !preState.isDoubleDateMode }),
305
+ () => {
306
+ const { isDoubleDateMode } = this.state;
307
+ this.updateHeaderView();
308
+ if (
309
+ onCallbackCalendar &&
310
+ typeof onCallbackCalendar === 'function'
311
+ ) {
312
+ onCallbackCalendar('switch', isDoubleDateMode);
313
+ }
314
+ },
315
+ );
226
316
  };
227
317
 
228
318
  renderSwitchReturnSelection = () => {
@@ -237,7 +327,11 @@ class Calendar extends Component {
237
327
  onValueChange={this.toggleSelectionDateMode}
238
328
  thumbColor={isDoubleDateMode ? '#78ca32' : 'white'}
239
329
  trackColor={{ false: '#e5e7ec', true: '#e5e7ec' }}
240
- style={[Platform.OS === 'ios' && { transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }] }]}
330
+ style={[
331
+ Platform.OS === 'ios' && {
332
+ transform: [{ scaleX: 0.8 }, { scaleY: 0.8 }],
333
+ },
334
+ ]}
241
335
  />
242
336
  </View>
243
337
  );
@@ -246,7 +340,7 @@ class Calendar extends Component {
246
340
  renderHeaderPanel = () => {
247
341
  const { isDoubleDateMode } = this.state;
248
342
  const { headerFrom, headerTo } = this.props;
249
- return (isDoubleDateMode ? (
343
+ return isDoubleDateMode ? (
250
344
  <View style={styles.viewPanel}>
251
345
  <TabHeader
252
346
  id={0}
@@ -277,26 +371,52 @@ class Calendar extends Component {
277
371
  date={this.selectedDate}
278
372
  />
279
373
  </View>
280
- ));
374
+ );
281
375
  };
282
376
 
283
377
  setDateRange = (dateRange, isScrollToStartDate) => {
284
378
  const { mode, doubleDate = {} } = this.props;
285
379
  if (mode === 'doubleDate') {
286
- this.cellHeader1.current.updateView(dateRange.startDate, this.tabSelected === 0);
287
- this.cellHeader2.current.updateView(dateRange.endDate, this.tabSelected === 1);
288
- this.calendarPicker?.current?.setDateRange(dateRange, isScrollToStartDate);
289
- this.doubleDate = doubleDate ? {
290
- first: dateRange.startDate ? moment(dateRange.startDate) : null,
291
- second: dateRange.endDate ? moment(dateRange.endDate) : null
292
- } : {};
380
+ this.cellHeader1.current.updateView(
381
+ dateRange.startDate,
382
+ this.tabSelected === 0,
383
+ );
384
+ this.cellHeader2.current.updateView(
385
+ dateRange.endDate,
386
+ this.tabSelected === 1,
387
+ );
388
+ this.calendarPicker?.current?.setDateRange(
389
+ dateRange,
390
+ isScrollToStartDate,
391
+ );
392
+ this.doubleDate = doubleDate
393
+ ? {
394
+ first: dateRange.startDate
395
+ ? moment(dateRange.startDate)
396
+ : null,
397
+ second: dateRange.endDate
398
+ ? moment(dateRange.endDate)
399
+ : null,
400
+ }
401
+ : {};
293
402
  }
294
- }
403
+ };
295
404
 
296
405
  render() {
297
406
  const {
298
- isOffLunar, isHideHoliday, isHiddenSwitch, isShowLunar, onCallbackCalendar, priceList, labelFrom, labelTo, isHideLabel, minDate, maxDate, doubleDate,
299
- isHideHeaderPanel
407
+ isOffLunar,
408
+ isHideHoliday,
409
+ isHiddenSwitch,
410
+ isShowLunar,
411
+ onCallbackCalendar,
412
+ priceList,
413
+ labelFrom,
414
+ labelTo,
415
+ isHideLabel,
416
+ minDate,
417
+ maxDate,
418
+ doubleDate,
419
+ isHideHeaderPanel,
300
420
  } = this.props;
301
421
  const { isDoubleDateMode } = this.state;
302
422
  return (
@@ -331,7 +451,7 @@ export default Calendar;
331
451
  Calendar.propTypes = {
332
452
  doubleDate: PropTypes.shape({
333
453
  first: PropTypes.any,
334
- second: PropTypes.any
454
+ second: PropTypes.any,
335
455
  }),
336
456
  id: PropTypes.any,
337
457
  isHiddenSwitch: PropTypes.bool,
@@ -348,13 +468,19 @@ Calendar.propTypes = {
348
468
  headerTo: PropTypes.string,
349
469
  isHideLabel: PropTypes.bool,
350
470
  isHideHoliday: PropTypes.bool,
351
- minDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
352
- maxDate: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)])
471
+ minDate: PropTypes.oneOfType([
472
+ PropTypes.string,
473
+ PropTypes.instanceOf(Date),
474
+ ]),
475
+ maxDate: PropTypes.oneOfType([
476
+ PropTypes.string,
477
+ PropTypes.instanceOf(Date),
478
+ ]),
353
479
  };
354
480
 
355
481
  Calendar.defaultProps = {
356
482
  mode: 'single',
357
- isHiddenSwitch: false
483
+ isHiddenSwitch: false,
358
484
  };
359
485
 
360
486
  const styles = StyleSheet.create({
@@ -364,7 +490,7 @@ const styles = StyleSheet.create({
364
490
  justifyContent: 'center',
365
491
  alignItems: 'center',
366
492
  backgroundColor: 'white',
367
- borderRadius: 8
493
+ borderRadius: 8,
368
494
  },
369
495
  viewPanel: {
370
496
  height: 50,
@@ -375,12 +501,12 @@ const styles = StyleSheet.create({
375
501
  flexDirection: 'row',
376
502
  backgroundColor: '#eeeeef',
377
503
  justifyContent: 'space-around',
378
- borderRadius: 8
504
+ borderRadius: 8,
379
505
  },
380
506
  textSwitch: {
381
507
  // fontSize: 10,
382
508
  fontWeight: 'bold',
383
- color: '#222222'
509
+ color: '#222222',
384
510
  },
385
511
  viewSwitch: {
386
512
  flexDirection: 'row',
@@ -389,6 +515,6 @@ const styles = StyleSheet.create({
389
515
  alignItems: 'center',
390
516
  backgroundColor: '#f2f3f5',
391
517
  paddingVertical: 9,
392
- height: 42
518
+ height: 42,
393
519
  },
394
520
  });
package/src/Day/index.js CHANGED
@@ -1,193 +1,210 @@
1
- import React, { Component } from 'react';
1
+ import React, {Component} from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- import {
5
- View,
6
- TouchableHighlight,
7
- Text
8
- } from 'react-native';
9
- import { Colors, SwitchLanguage } from '@momo-kits/core';
4
+ import {View, TouchableHighlight, Text} from 'react-native';
5
+ import {Colors, SwitchLanguage} from '@momo-kits/core';
10
6
  import style from './style';
11
7
 
12
8
  class Day extends Component {
13
- constructor(props) {
14
- super(props);
15
- this.statusCheck();
16
- }
9
+ constructor(props) {
10
+ super(props);
11
+ this.statusCheck();
12
+ }
17
13
 
18
- chooseDay = () => {
19
- const { onChoose, date } = this.props;
20
- onChoose && onChoose(date);
21
- };
14
+ chooseDay = () => {
15
+ const {onChoose, date} = this.props;
16
+ onChoose && onChoose(date);
17
+ };
22
18
 
23
- findHoliday = (date, holidays) => {
24
- if (date && holidays && holidays.length > 0) {
25
- const day = date.date();
26
- const month = date.month() + 1;
27
- return holidays.find((item) => item.day === day && item.month === month);
28
- }
29
- return null;
30
- };
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
+ };
31
27
 
32
- checkHoliday = (date, holidays) => {
33
- const holiday = this.findHoliday(date, holidays);
34
- return {
35
- solarHoliday: !!(holiday && !holiday.lunar),
36
- lunarHoliday: !!(holiday && holiday.lunar)
37
- };
28
+ checkHoliday = (date, holidays) => {
29
+ const holiday = this.findHoliday(date, holidays);
30
+ return {
31
+ solarHoliday: !!(holiday && !holiday.lunar),
32
+ lunarHoliday: !!(holiday && holiday.lunar),
38
33
  };
34
+ };
39
35
 
40
- statusCheck = (props) => {
41
- const {
42
- startDate,
43
- endDate,
44
- date = null,
45
- minDate,
46
- maxDate,
47
- empty,
48
- index,
49
- isShowLunar,
50
- tabSelected,
51
- isDoubleDateMode,
52
- lunarDate,
53
- isSolarHoliday,
54
- isLunarHoliday,
55
- price
56
- } = props || this.props;
57
- this.isValid = date && (date >= minDate || date.isSame(minDate, 'day')) && (date <= maxDate || date.isSame(maxDate, 'day'));
58
- this.isMid = 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 ? (tabSelected === 0 || (tabSelected === 1 && startDate && date && date.isSameOrAfter(startDate, 'day'))) : true;
72
- return this.isFocus || this.diffPrice;
73
- };
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
+ };
74
80
 
75
- shouldComponentUpdate(nextProps) {
76
- const {
77
- isDoubleDateMode, isShowLunar, tabSelected, isSolarHoliday,
78
- isLunarHoliday,
79
- price,
80
- isBestPrice,
81
- startDate,
82
- endDate
83
- } = this.props;
84
- const prevStatus = this.isFocus;
85
- const selectionModeChange = isDoubleDateMode !== nextProps.isDoubleDateMode;
86
- const lunarChange = isShowLunar !== nextProps.isShowLunar;
87
- const nextStatus = this.statusCheck(nextProps);
88
- const tabChange = tabSelected !== nextProps.tabSelected;
89
- const solarHoliday = isSolarHoliday !== nextProps.isSolarHoliday;
90
- const lunarHoliday = isLunarHoliday !== nextProps.isLunarHoliday;
91
- const diffPrice = price !== nextProps.price && isBestPrice !== nextProps.isBestPrice;
92
- const startDateChange = startDate && !startDate?.isSame?.(nextProps.startDate, 'day');
93
- const endDateChange = endDate && !endDate?.isSame?.(nextProps.endDate, 'day');
94
- return !!(prevStatus !== nextStatus || selectionModeChange || lunarChange || tabChange || solarHoliday || lunarHoliday || diffPrice || startDateChange || endDateChange);
95
- }
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
+ }
96
118
 
97
- render() {
98
- const {
99
- date, empty, isDoubleDateMode, price, isBestPrice, isShowPrice, labelFrom, labelTo, isHideLabel
100
- } = this.props;
101
- const text = date ? date.date() : '';
102
- return (
103
- <View style={style.dayContainer}>
104
- <View style={[
105
- this.isMid && !empty && style.mid,
106
- this.isStartPart && style.dayStartContainer,
107
- this.isEnd && style.dayEndContainer
108
-
109
- ]}
110
- >
111
- {this.isValid && this.isInScope
112
- ? (
113
- <TouchableHighlight
114
- style={[
115
- style.day,
116
- (this.isStart || this.isEnd) && style.focused
117
- ]}
118
- underlayColor="rgba(255, 255, 255, 0.35)"
119
- onPress={this.chooseDay}
120
- >
121
- <>
122
- <Text style={[
123
- style.dayText,
124
- this.isWeekEnd && style.weekendDay,
125
- this.isSolarHoliday && style.weekendDay,
126
- (this.isStart || this.isEnd) && style.focusedText,
127
- ]}
128
- >
129
- {text}
130
- </Text>
131
- {
132
- this.lunarDate && this.showLunar && (
133
- <Text style={[
134
- style.lunarDayText,
135
- (this.isLunarHoliday || this.isLunarDayStart) && style.weekendDay,
136
- (this.isStart || this.isEnd) && style.focusedText,
137
- ]}
138
- >
139
- {this.lunarDate.lunarDay === 1 ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}` : this.lunarDate.lunarDay}
140
- </Text>
141
- )
142
- }
143
- </>
144
- </TouchableHighlight>
145
- )
146
- : (
147
- <View style={[style.day]}>
148
- <Text style={[
149
- style.dayText,
150
- style.dayTextDisabled,
151
- ]}
152
- >
153
- {text}
154
- </Text>
155
- {
156
- this.lunarDate && this.showLunar && text ? (
157
- <Text style={[
158
- style.lunarDayText,
159
- style.dayTextDisabled,
160
- ]}
161
- >
162
- {this.lunarDate.lunarDay === 1 ? `${this.lunarDate.lunarDay}/${this.lunarDate.lunarMonth}` : this.lunarDate.lunarDay}
163
- </Text>
164
- ) : <View />
165
- }
166
- </View>
167
- )}
168
- </View>
169
-
170
- {(isDoubleDateMode && this.isStart && !isHideLabel) && (
171
- <View style={style.txtGo}>
172
- <Text style={{ fontSize: 8, color: 'white' }}>
173
- {labelFrom || SwitchLanguage.departing}
174
- </Text>
175
- </View>
176
- )}
177
- {(isDoubleDateMode && this.isEnd && !isHideLabel) && (
178
- <View style={style.txtBack}>
179
- <Text style={{ fontSize: 8, color: 'white' }}>
180
- {labelTo || SwitchLanguage.returning}
181
- </Text>
182
- </View>
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>
183
167
  )}
184
- {this.isValid
185
- && this.isInScope
186
- && !!(price)
187
- && <Text style={[style.price, isBestPrice && { color: Colors.pink_05_b }]}>{price}</Text>}
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
+ )}
188
182
  </View>
189
- );
190
- }
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
+ }
191
208
  }
192
209
 
193
210
  export default Day;
package/src/MonthList.js CHANGED
@@ -8,10 +8,12 @@ import {
8
8
  import moment from 'moment';
9
9
  import Month from './Month';
10
10
  import style from './Day/style';
11
- import { convertSolar2Lunar } from './LunarService';
11
+ import LunarDateConverter from './LunarDateConverter';
12
12
 
13
13
  const ITEM_WIDTH = Dimensions.get('window').width - 24;
14
14
  const MAX_RENDER_PER_BATCH = Platform.OS === 'android' ? 1 : 12;
15
+
16
+ const converter = new LunarDateConverter();
15
17
  export default class MonthList extends Component {
16
18
  constructor(props) {
17
19
  super(props);
@@ -76,12 +78,11 @@ export default class MonthList extends Component {
76
78
  };
77
79
 
78
80
  convertLunarToSolar(date) {
79
- return date && convertSolar2Lunar ? convertSolar2Lunar(
80
- date.date(),
81
- date.month() + 1,
82
- date.year(),
83
- 7
84
- ) : {};
81
+ return date ? converter.SolarToLunar({
82
+ solarDay: date.date(),
83
+ solarMonth: date.month() + 1,
84
+ solarYear: date.year()
85
+ }) : {};
85
86
  }
86
87
 
87
88
  findHoliday = (date) => {