@momo-kits/calendar 0.0.32-beta → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +4 -1
- package/package.json +8 -13
- package/publish.sh +2 -2
- package/src/Calendar.js +394 -1
- package/src/CalendarPro.js +363 -1
- package/src/Day/index.js +210 -1
- package/src/Day/style.js +129 -1
- package/src/HeaderControl.js +79 -1
- package/src/LunarDateConverter.js +191 -1
- package/src/LunarService.js +185 -1
- package/src/Month/index.js +80 -1
- package/src/MonthList.js +253 -1
- package/src/TabHeader.js +79 -1
- package/src/Util.js +225 -1
- package/src/calendarPicker/Day.js +154 -0
- package/src/calendarPicker/Days.js +203 -0
- package/src/calendarPicker/HeaderControls.js +158 -0
- package/src/calendarPicker/WeekDaysLabels.js +22 -0
- package/src/calendarPicker/index.js +125 -0
- package/src/calendarPicker/styles.js +184 -0
- package/src/calendarPicker/util.js +50 -0
- package/src/holidayData.js +127 -1
- package/babel.config.js +0 -1
package/src/Month/index.js
CHANGED
|
@@ -1 +1,80 @@
|
|
|
1
|
-
|
|
1
|
+
import React, { PureComponent } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
View
|
|
5
|
+
} from 'react-native';
|
|
6
|
+
import moment from 'moment';
|
|
7
|
+
import Day from '../Day';
|
|
8
|
+
|
|
9
|
+
export default class Month extends PureComponent {
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super(props);
|
|
12
|
+
const { dateList } = props;
|
|
13
|
+
this.rowArray = new Array(dateList.length / 7).fill('');
|
|
14
|
+
this.temp = this.rowArray.map((item, i) => dateList.slice(i * 7, i * 7 + 7));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
findHoliday = (date) => {
|
|
18
|
+
const { holidays } = this.props;
|
|
19
|
+
if (date && holidays && holidays.length > 0) {
|
|
20
|
+
const day = date.date();
|
|
21
|
+
const month = date.month() + 1;
|
|
22
|
+
return holidays.find((item) => item.day === day && item.month === month);
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
checkHoliday = (date) => {
|
|
28
|
+
const holiday = this.findHoliday(date);
|
|
29
|
+
return {
|
|
30
|
+
isSolarHoliday: !!(holiday && !holiday.lunar),
|
|
31
|
+
isLunarHoliday: !!(holiday && holiday.lunar)
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
renderDayRow = (dayList, index) => (
|
|
36
|
+
<View
|
|
37
|
+
style={{
|
|
38
|
+
flexDirection: 'row',
|
|
39
|
+
justifyContent: 'space-between'
|
|
40
|
+
}}
|
|
41
|
+
key={`row${index}`}
|
|
42
|
+
>
|
|
43
|
+
{dayList.map((item, i) => {
|
|
44
|
+
const keyDay = moment(item.date).format('YYYY-MM-DD');
|
|
45
|
+
const priceInfo = this.props?.priceListDate?.[keyDay];
|
|
46
|
+
return (
|
|
47
|
+
<Day
|
|
48
|
+
{...this.props}
|
|
49
|
+
{...this.checkHoliday(item.date)}
|
|
50
|
+
date={item.date}
|
|
51
|
+
lunarDate={item.lunarDate}
|
|
52
|
+
empty={item.empty}
|
|
53
|
+
key={`day${i.toString()}`}
|
|
54
|
+
index={i}
|
|
55
|
+
price={priceInfo?.priceAsString}
|
|
56
|
+
isBestPrice={priceInfo?.isBestPrice}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
)}
|
|
61
|
+
</View>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
render() {
|
|
65
|
+
const {
|
|
66
|
+
month
|
|
67
|
+
} = this.props;
|
|
68
|
+
if (month) {
|
|
69
|
+
return (
|
|
70
|
+
<View>
|
|
71
|
+
<View style={{ paddingHorizontal: 7, paddingVertical: 5 }}>
|
|
72
|
+
{this.temp.map((item, i) => this.renderDayRow(item, i)
|
|
73
|
+
)}
|
|
74
|
+
</View>
|
|
75
|
+
</View>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return (<View />);
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/MonthList.js
CHANGED
|
@@ -1 +1,253 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable react/no-did-update-set-state */
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
FlatList,
|
|
5
|
+
Dimensions,
|
|
6
|
+
Platform
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import moment from 'moment';
|
|
9
|
+
import Month from './Month';
|
|
10
|
+
import style from './Day/style';
|
|
11
|
+
import { convertSolar2Lunar } from './LunarService';
|
|
12
|
+
|
|
13
|
+
const ITEM_WIDTH = Dimensions.get('window').width - 24;
|
|
14
|
+
const MAX_RENDER_PER_BATCH = Platform.OS === 'android' ? 1 : 12;
|
|
15
|
+
export default class MonthList extends Component {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
// this.state = {
|
|
19
|
+
// // data: [],
|
|
20
|
+
// isDoubleDateMode: props.isDoubleDateMode
|
|
21
|
+
// };
|
|
22
|
+
this.currentDate = moment();
|
|
23
|
+
this.data = this.getMonthList();
|
|
24
|
+
this.currentScrollIndex = this.getIndexOfMonth(moment(props.selectedDate), this.data);
|
|
25
|
+
this.list = React.createRef();
|
|
26
|
+
this.heightStyle = {};
|
|
27
|
+
this.holidays = props.holidays;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// componentDidUpdate(prevProps) {
|
|
31
|
+
// const { isDoubleDateMode } = this.props;
|
|
32
|
+
// if (isDoubleDateMode !== prevProps.isDoubleDateMode) {
|
|
33
|
+
// this.setState({
|
|
34
|
+
// // data: this.getMonthList(this.props),
|
|
35
|
+
// isDoubleDateMode
|
|
36
|
+
// });
|
|
37
|
+
// }
|
|
38
|
+
// }
|
|
39
|
+
|
|
40
|
+
renderMonth = ({ item, index }) => {
|
|
41
|
+
const { isDoubleDateMode, priceList } = this.props;
|
|
42
|
+
const keyMonth = moment(item.date)?.format('YYYY-MM');
|
|
43
|
+
const priceListDate = priceList?.[keyMonth]?.day;
|
|
44
|
+
return (
|
|
45
|
+
<Month
|
|
46
|
+
{...this.props}
|
|
47
|
+
key={index}
|
|
48
|
+
month={item.date || {}}
|
|
49
|
+
dateList={item.dateList || []}
|
|
50
|
+
priceListDate={priceListDate}
|
|
51
|
+
isDoubleDateMode={isDoubleDateMode}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
checkRange = (date, start, end) => {
|
|
57
|
+
if (!date || !start) return false;
|
|
58
|
+
if (!end) return date.year() === start.year() && date.month() === start.month();
|
|
59
|
+
if (date.year() < start.year() || (date.year() === start.year() && date.month() < start.month())) return false;
|
|
60
|
+
return !(date.year() > end.year() || (date.year() === end.year() && date.month() > end.month()));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
shouldUpdate = (month, props) => {
|
|
64
|
+
if (!props) return false;
|
|
65
|
+
const {
|
|
66
|
+
startDate,
|
|
67
|
+
endDate
|
|
68
|
+
} = props;
|
|
69
|
+
const { startDate: curStartDate, endDate: curEndDate } = this.props;
|
|
70
|
+
const {
|
|
71
|
+
date
|
|
72
|
+
} = month;
|
|
73
|
+
const next = this.checkRange(date, startDate, endDate);
|
|
74
|
+
const prev = this.checkRange(date, curStartDate, curEndDate);
|
|
75
|
+
return !!(prev || next);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
convertLunarToSolar(date) {
|
|
79
|
+
return date && convertSolar2Lunar ? convertSolar2Lunar(
|
|
80
|
+
date.date(),
|
|
81
|
+
date.month() + 1,
|
|
82
|
+
date.year(),
|
|
83
|
+
7
|
|
84
|
+
) : {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
findHoliday = (date) => {
|
|
88
|
+
const { holidays } = this.props;
|
|
89
|
+
if (date && holidays && holidays.length > 0) {
|
|
90
|
+
const day = date.date();
|
|
91
|
+
const month = date.month() + 1;
|
|
92
|
+
return holidays.find((item) => item.day === day && item.month === month);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
checkHoliday = (date, holidays) => {
|
|
98
|
+
const holiday = this.findHoliday(date, holidays);
|
|
99
|
+
return {
|
|
100
|
+
isSolarHoliday: !!(holiday && !holiday.lunar),
|
|
101
|
+
isLunarHoliday: !!(holiday && holiday.lunar)
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
getDayList = (date) => {
|
|
106
|
+
let dayList;
|
|
107
|
+
const month = date.month();
|
|
108
|
+
let weekday = date.isoWeekday();
|
|
109
|
+
if (weekday === 1) {
|
|
110
|
+
dayList = [];
|
|
111
|
+
} else {
|
|
112
|
+
dayList = new Array(weekday - 1).fill({
|
|
113
|
+
empty: moment(date).subtract(1, 'h'),
|
|
114
|
+
lunarDate: this.convertLunarToSolar(date),
|
|
115
|
+
...this.checkHoliday(date)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
while (date.month() === month) {
|
|
119
|
+
const cloned = moment(date);
|
|
120
|
+
dayList.push({
|
|
121
|
+
date: cloned,
|
|
122
|
+
lunarDate: this.convertLunarToSolar(cloned),
|
|
123
|
+
...this.checkHoliday(date)
|
|
124
|
+
});
|
|
125
|
+
date.add(1, 'days');
|
|
126
|
+
}
|
|
127
|
+
date.subtract(1, 'days');
|
|
128
|
+
weekday = date.isoWeekday();
|
|
129
|
+
if (weekday === 1) {
|
|
130
|
+
return dayList.concat(new Array(6).fill({
|
|
131
|
+
empty: moment(date).hour(1),
|
|
132
|
+
lunarDate: this.convertLunarToSolar(date)
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
return dayList.concat(new Array(Math.abs(7 - weekday)).fill({
|
|
136
|
+
empty: moment(date).hour(1),
|
|
137
|
+
lunarDate: this.convertLunarToSolar(date)
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
getMonthList = (props) => {
|
|
142
|
+
const minDate = moment((props || this.props).minDate).date(1);
|
|
143
|
+
const maxDate = moment((props || this.props).maxDate);
|
|
144
|
+
const monthList = [];
|
|
145
|
+
if (!maxDate || !minDate) return monthList;
|
|
146
|
+
while (maxDate > minDate || (
|
|
147
|
+
maxDate.year() === minDate.year()
|
|
148
|
+
&& maxDate.month() === minDate.month()
|
|
149
|
+
)) {
|
|
150
|
+
const d = moment(minDate);
|
|
151
|
+
const month = {
|
|
152
|
+
date: d,
|
|
153
|
+
dateList: this.getDayList(d)
|
|
154
|
+
};
|
|
155
|
+
month.shouldUpdate = this.shouldUpdate(month, props);
|
|
156
|
+
monthList.push(month);
|
|
157
|
+
minDate.add(1, 'month');
|
|
158
|
+
}
|
|
159
|
+
return monthList;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
getIndexOfMonth = (month, data) => data.findIndex((item) => item.date.isSame(month, 'month'));
|
|
163
|
+
|
|
164
|
+
// componentDidMount() {
|
|
165
|
+
// const {
|
|
166
|
+
// selectedDate
|
|
167
|
+
// } = this.props;
|
|
168
|
+
// const data = this.getMonthList();
|
|
169
|
+
// this.currentScrollIndex = this.getIndexOfMonth(moment(selectedDate), data);
|
|
170
|
+
// this.setState({ data });
|
|
171
|
+
// }
|
|
172
|
+
// componentDidMount() {
|
|
173
|
+
// if (this.list.current) {
|
|
174
|
+
// this.scrollToMonth(moment(this.props.selectedDate));
|
|
175
|
+
// }
|
|
176
|
+
// }
|
|
177
|
+
|
|
178
|
+
// componentWillUnmount() {
|
|
179
|
+
// const { isDoubleDateMode } = this.props;
|
|
180
|
+
// this.setState({
|
|
181
|
+
// // data: [],
|
|
182
|
+
// isDoubleDateMode
|
|
183
|
+
// });
|
|
184
|
+
// }
|
|
185
|
+
|
|
186
|
+
getCurrentVisibleMonth = (info) => {
|
|
187
|
+
const { changed } = info;
|
|
188
|
+
const { onScrollCalendar } = this.props;
|
|
189
|
+
if (changed && changed.length > 0) {
|
|
190
|
+
const { item, key, index } = changed[0];
|
|
191
|
+
if (onScrollCalendar && item && this.currentKey !== key) {
|
|
192
|
+
this.currentKey = key;
|
|
193
|
+
try {
|
|
194
|
+
this.heightStyle = this.data && this.data[index] && this.data[index].dateList
|
|
195
|
+
? {
|
|
196
|
+
height: (style.containerDayHeight * this.data[index].dateList.length / 7) + 10
|
|
197
|
+
}
|
|
198
|
+
: {};
|
|
199
|
+
} catch (e) {
|
|
200
|
+
this.heightStyle = {};
|
|
201
|
+
}
|
|
202
|
+
if (onScrollCalendar) {
|
|
203
|
+
onScrollCalendar({ date: item.date, key, currentIndex: index });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
keyExtractor = (item) => `${item.date.month() + 1}/${item.date.year()}`;
|
|
210
|
+
|
|
211
|
+
scrollToMonth = (month) => {
|
|
212
|
+
const index = this.getIndexOfMonth(month, this.data);
|
|
213
|
+
if (this.list.current && index !== -1) {
|
|
214
|
+
this.list.current.scrollToIndex({
|
|
215
|
+
index,
|
|
216
|
+
animated: true
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
getItemLayout = (data, index) => (
|
|
222
|
+
{ length: ITEM_WIDTH, offset: ITEM_WIDTH * index, index }
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
render() {
|
|
226
|
+
const { priceList } = this.props;
|
|
227
|
+
return (
|
|
228
|
+
<FlatList
|
|
229
|
+
extraData={priceList}
|
|
230
|
+
style={this.heightStyle}
|
|
231
|
+
horizontal
|
|
232
|
+
pagingEnabled
|
|
233
|
+
ref={this.list}
|
|
234
|
+
data={this.data}
|
|
235
|
+
renderItem={this.renderMonth}
|
|
236
|
+
showsHorizontalScrollIndicator={false}
|
|
237
|
+
keyExtractor={this.keyExtractor}
|
|
238
|
+
onViewableItemsChanged={this.getCurrentVisibleMonth}
|
|
239
|
+
onScrollToIndexFailed={() => {}}
|
|
240
|
+
removeClippedSubviews
|
|
241
|
+
initialNumToRender={1}
|
|
242
|
+
maxToRenderPerBatch={MAX_RENDER_PER_BATCH}
|
|
243
|
+
windowSize={3}
|
|
244
|
+
contentContainerStyle={{ paddingTop: 5 }}
|
|
245
|
+
initialScrollIndex={this.currentScrollIndex}
|
|
246
|
+
getItemLayout={this.getItemLayout}
|
|
247
|
+
viewabilityConfig={{
|
|
248
|
+
itemVisiblePercentThreshold: 50
|
|
249
|
+
}}
|
|
250
|
+
/>
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
package/src/TabHeader.js
CHANGED
|
@@ -1 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TouchableWithoutFeedback, View, Text } from 'react-native';
|
|
3
|
+
import Moment from 'moment';
|
|
4
|
+
import Util from './Util';
|
|
5
|
+
|
|
6
|
+
export default class TabHeader extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.state = {
|
|
10
|
+
active: props.activeTab
|
|
11
|
+
};
|
|
12
|
+
this.label = props.label;
|
|
13
|
+
this.defaultDate = props.date ? Moment(props.date) : '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
onChangeTab = () => {
|
|
17
|
+
const { onChangeTab, id } = this.props;
|
|
18
|
+
if (onChangeTab) {
|
|
19
|
+
onChangeTab(id);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
updateView = (date, activeTab) => {
|
|
24
|
+
this.setState({
|
|
25
|
+
date: date ? Moment(date) : '',
|
|
26
|
+
active: activeTab
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
setActiveTab = (active) => {
|
|
31
|
+
this.setState({ active });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
const { label, disabled } = this.props;
|
|
36
|
+
const { date, active } = this.state;
|
|
37
|
+
const formattedDateFromState = date ? date.format('DD/MM/YYYY') : '';
|
|
38
|
+
const formattedDateFromDefault = this.defaultDate ? this.defaultDate.format('DD/MM/YYYY') : '';
|
|
39
|
+
const dayOfWeekFromState = date ? `${Util.WEEKDAYSFROMMOMENT[date.day()]} -` : '';
|
|
40
|
+
const dayOfWeekFromDefault = this.defaultDate ? `${Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()]} -` : '';
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<TouchableWithoutFeedback disabled={disabled} onPress={this.onChangeTab}>
|
|
44
|
+
<View style={{
|
|
45
|
+
flex: 1,
|
|
46
|
+
justifyContent: 'center',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
backgroundColor: active ? 'white' : '#eeeeef',
|
|
49
|
+
borderRadius: 8
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<Text style={{
|
|
53
|
+
fontSize: 12,
|
|
54
|
+
// lineHeight: 14,
|
|
55
|
+
color: active ? '#222222' : '#8d919d',
|
|
56
|
+
fontWeight: 'bold'
|
|
57
|
+
}}
|
|
58
|
+
>
|
|
59
|
+
{label}
|
|
60
|
+
|
|
61
|
+
</Text>
|
|
62
|
+
<Text style={{
|
|
63
|
+
marginTop: 3,
|
|
64
|
+
fontSize: 12,
|
|
65
|
+
// lineHeight: 14,
|
|
66
|
+
color: '#8d919d'
|
|
67
|
+
}}
|
|
68
|
+
>
|
|
69
|
+
<Text style={{ color: active ? '#b0006d' : '#8d919d', fontWeight: 'bold' }}>
|
|
70
|
+
{`${dayOfWeekFromState || dayOfWeekFromDefault || '--'} `}
|
|
71
|
+
|
|
72
|
+
</Text>
|
|
73
|
+
{formattedDateFromState || formattedDateFromDefault || '--/--/----'}
|
|
74
|
+
</Text>
|
|
75
|
+
</View>
|
|
76
|
+
</TouchableWithoutFeedback>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|