@momo-kits/calendar 0.0.49-beta → 0.0.49-beta.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/calendar",
3
- "version": "0.0.49-beta",
3
+ "version": "0.0.49-beta.2",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "dependencies": {
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
- 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"}'
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/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) => {