@momo-kits/calendar 0.167.1-beta.11 → 0.167.1-beta.14

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 CHANGED
@@ -200,9 +200,8 @@ const CalendarPro = forwardRef<CalendarProRef, CalendarProProps>(
200
200
 
201
201
  // Determine price list format
202
202
  let priceListFormat = priceList?.outbound;
203
- if (isDoubleDateMode) {
204
- priceListFormat =
205
- tabSelected === 0 ? priceList?.outbound : priceList?.inbound;
203
+ if (isDoubleDateMode && tabSelected !== 0) {
204
+ priceListFormat = priceList?.inbound;
206
205
  }
207
206
 
208
207
  return (
@@ -274,9 +273,7 @@ const CalendarPro = forwardRef<CalendarProRef, CalendarProProps>(
274
273
  const labelDate = `${item.day > 9 ? item.day : `0${item.day}`}/${
275
274
  item.month > 9 ? item.month : `0${item.month}`
276
275
  }`;
277
- const labelHoliday = showLunar
278
- ? item.mixedLabel || item.label
279
- : item.label;
276
+ const labelHoliday = (showLunar && item.mixedLabel) || item.label;
280
277
  const labelHighlight = showLunar ? item.highlight || '' : '';
281
278
  return (
282
279
  <View style={styles.row} key={idx.toString()}>
package/Day.tsx CHANGED
@@ -63,9 +63,8 @@ const Day: React.FC<DayProps> = props => {
63
63
  const isWeekEnd = index === 6 || index === 5;
64
64
  const showLunar = isShowLunar;
65
65
 
66
- const isInScope = isDoubleDateMode
67
- ? tabSelected === 0 || date.isSameOrAfter(startDate, 'day')
68
- : true;
66
+ const isEndTab = isDoubleDateMode && tabSelected !== 0;
67
+ const isInScope = !isEndTab || date.isSameOrAfter(startDate, 'day');
69
68
 
70
69
  const chooseDay = () => {
71
70
  onChoose && onChoose(date);
@@ -95,6 +94,9 @@ const Day: React.FC<DayProps> = props => {
95
94
  lunarTextColor = theme.colors.text.disable;
96
95
  }
97
96
 
97
+ const { lunarDay, lunarMonth } = lunarDate ?? {};
98
+ const lunarLabel = lunarDay === 1 ? `${lunarDay}/${lunarMonth}` : lunarDay;
99
+
98
100
  return (
99
101
  <View style={[styles.dayContainer, { width: itemWidth }]}>
100
102
  <View
@@ -131,9 +133,7 @@ const Day: React.FC<DayProps> = props => {
131
133
  fontFamily: lunarFontFamily,
132
134
  }}
133
135
  >
134
- {lunarDate.lunarDay === 1
135
- ? `${lunarDate.lunarDay}/${lunarDate.lunarMonth}`
136
- : lunarDate.lunarDay}
136
+ {lunarLabel}
137
137
  </RNText>
138
138
  )}
139
139
  <Text typography="body_default_regular" color={textColor}>
package/Month.tsx CHANGED
@@ -78,13 +78,10 @@ const Month: React.FC<MonthProps> = ({
78
78
  {dayList.map((item, i) => {
79
79
  const {isEmpty, date: dateMoment, lunarDate} = item;
80
80
  // compute key for price/disabled only if not empty
81
- const keyDay = !isEmpty && dateMoment
82
- ? dateMoment.format('YYYY-MM-DD')
83
- : '';
81
+ const hasDate = !isEmpty && dateMoment;
82
+ const keyDay = hasDate ? dateMoment.format('YYYY-MM-DD') : '';
84
83
  const priceInfo = keyDay ? priceListDate?.[keyDay] : undefined;
85
- const isDisabled = keyDay
86
- ? disabledSet.has(keyDay)
87
- : false;
84
+ const isDisabled = keyDay ? disabledSet.has(keyDay) : false;
88
85
 
89
86
  return (
90
87
  <Day
package/MonthList.tsx CHANGED
@@ -6,11 +6,17 @@ import React, {
6
6
  useCallback,
7
7
  useContext,
8
8
  useEffect,
9
+ useLayoutEffect,
9
10
  useMemo,
10
11
  useRef,
11
12
  useState,
12
13
  } from 'react';
13
- import { FlatList, Platform } from 'react-native';
14
+ import {
15
+ FlatList,
16
+ NativeScrollEvent,
17
+ NativeSyntheticEvent,
18
+ Platform,
19
+ } from 'react-native';
14
20
  import { ContainerContext } from './index';
15
21
  import LunarDateConverter from './LunarDateConverter';
16
22
  import Month from './Month';
@@ -102,6 +108,32 @@ const MonthList = forwardRef<MonthListRef, MonthListProps>((props, ref) => {
102
108
  [selectedDate, getIndexOfMonth],
103
109
  );
104
110
 
111
+ // paging keeps the old pixel offset when the width changes (fold, unfold,
112
+ // rotation), so remember the offset and move back onto the same month
113
+ const scrollOffset = useRef(Math.max(currentScrollIndex, 0) * size.width);
114
+ const pageWidth = useRef(size.width);
115
+
116
+ useLayoutEffect(() => {
117
+ const previousWidth = pageWidth.current;
118
+ pageWidth.current = size.width;
119
+ if (previousWidth === size.width || previousWidth <= 0) {
120
+ return;
121
+ }
122
+ const page = Math.round(scrollOffset.current / previousWidth);
123
+ scrollOffset.current = page * size.width;
124
+ listRef.current?.scrollToOffset({
125
+ offset: scrollOffset.current,
126
+ animated: false,
127
+ });
128
+ }, [size.width]);
129
+
130
+ const onScroll = useCallback(
131
+ (e: NativeSyntheticEvent<NativeScrollEvent>) => {
132
+ scrollOffset.current = e.nativeEvent.contentOffset.x;
133
+ },
134
+ [],
135
+ );
136
+
105
137
  const scrollToMonth = useCallback(
106
138
  (month: Moment) => {
107
139
  const idx = getIndexOfMonth(month);
@@ -211,6 +243,7 @@ const MonthList = forwardRef<MonthListRef, MonthListProps>((props, ref) => {
211
243
  showsHorizontalScrollIndicator={false}
212
244
  keyExtractor={keyExtractor}
213
245
  onScrollToIndexFailed={() => {}}
246
+ onScroll={onScroll}
214
247
  scrollEnabled
215
248
  initialNumToRender={3}
216
249
  maxToRenderPerBatch={MAX_RENDER_PER_BATCH}
package/TabHeader.tsx CHANGED
@@ -49,17 +49,15 @@ export default class TabHeader extends React.Component<
49
49
  const {label, disabled} = this.props;
50
50
  const {date, active} = this.state;
51
51
  const {theme, translate} = this.context;
52
+ const defaultDate = this.defaultDate;
53
+ const weekday = (day: Moment.Moment) =>
54
+ translate?.(Util.WEEKDAYSFROMMOMENT[day.day()]);
55
+ const isHighlighted = active && !disabled;
52
56
 
53
57
  const formattedDateFromState = date ? date.format('DD/MM/YYYY') : '';
54
- const formattedDateFromDefault = this.defaultDate
55
- ? this.defaultDate.format('DD/MM/YYYY')
56
- : '';
57
- const dayOfWeekFromState = date
58
- ? `${translate?.(Util.WEEKDAYSFROMMOMENT[date.day()])}, `
59
- : '';
60
- const dayOfWeekFromDefault = this.defaultDate
61
- ? `${translate?.(Util.WEEKDAYSFROMMOMENT[this.defaultDate.day()])},`
62
- : '';
58
+ const formattedDateFromDefault = defaultDate?.format('DD/MM/YYYY') ?? '';
59
+ const dayOfWeekFromState = date ? `${weekday(date)}, ` : '';
60
+ const dayOfWeekFromDefault = defaultDate ? `${weekday(defaultDate)},` : '';
63
61
 
64
62
  return (
65
63
  <TouchableWithoutFeedback disabled={disabled} onPress={this.onChangeTab}>
@@ -70,10 +68,9 @@ export default class TabHeader extends React.Component<
70
68
  padding: Spacing.S,
71
69
  borderRadius: Radius.S,
72
70
  },
73
- active &&
74
- !disabled && {
75
- backgroundColor: theme.colors.background.surface,
76
- },
71
+ isHighlighted && {
72
+ backgroundColor: theme.colors.background.surface,
73
+ },
77
74
  ]}>
78
75
  <Text
79
76
  typography={'description_default_regular'}
package/Util.ts CHANGED
@@ -68,9 +68,7 @@ const groupHolidaysByDate = (
68
68
  holidays.forEach(item => {
69
69
  const {day, month, lunar, label} = item;
70
70
  const key = formatDDMM(day, month);
71
- let holidaysObj = groupedHolidays[key]
72
- ? {...groupedHolidays[key]}
73
- : {...item};
71
+ let holidaysObj = { ...(groupedHolidays[key] || item) };
74
72
  if (groupedHolidays[key]) {
75
73
  if (holidaysObj.lunar && !lunar) {
76
74
  holidaysObj = {
@@ -199,10 +197,9 @@ const Utils = {
199
197
  const minLunarDate = converter.SolarToLunar(Solar(startDate));
200
198
  const maxLunarDate = converter.SolarToLunar(Solar(endDate));
201
199
  const holidays: any[] = [];
202
- const currentYear =
203
- minLunarDate.lunarYear !== maxLunarDate.lunarYear
204
- ? [minLunarDate.lunarYear, maxLunarDate.lunarYear]
205
- : minLunarDate.lunarYear;
200
+ const minYear = minLunarDate.lunarYear;
201
+ const maxYear = maxLunarDate.lunarYear;
202
+ const currentYear = minYear !== maxYear ? [minYear, maxYear] : minYear;
206
203
 
207
204
  // Handle Solar holidays
208
205
  // @ts-ignore
package/index.tsx CHANGED
@@ -66,25 +66,21 @@ const Calendar: React.FC<CalendarProps> = props => {
66
66
  const [isDoubleDateMode, setIsDoubleDateMode] = useState<boolean>(
67
67
  mode === DOUBLE,
68
68
  );
69
+ let initialDate = initialSelectedDate;
70
+ if (!initialDate && mode === DOUBLE) {
71
+ initialDate = initDoubleDate?.first;
72
+ }
69
73
  const [selectedDate, setSelectedDate] = useState<moment.Moment>(
70
- initialSelectedDate
71
- ? moment(initialSelectedDate)
72
- : mode === DOUBLE && initDoubleDate && initDoubleDate.first
73
- ? moment(initDoubleDate.first)
74
- : moment(),
74
+ initialDate ? moment(initialDate) : moment(),
75
75
  );
76
76
 
77
77
  const doubleDate = useRef<{
78
78
  first: moment.Moment | null;
79
79
  second: moment.Moment | null;
80
- }>(
81
- initDoubleDate
82
- ? {
83
- first: initDoubleDate.first ? moment(initDoubleDate.first) : null,
84
- second: initDoubleDate.second ? moment(initDoubleDate.second) : null,
85
- }
86
- : { first: null, second: null },
87
- );
80
+ }>({
81
+ first: initDoubleDate?.first ? moment(initDoubleDate.first) : null,
82
+ second: initDoubleDate?.second ? moment(initDoubleDate.second) : null,
83
+ });
88
84
  const tabSelected = useRef<number>(id || 0);
89
85
 
90
86
  const calendarPicker = useRef<CalendarProRef>(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/calendar",
3
- "version": "0.167.1-beta.11",
3
+ "version": "0.167.1-beta.14",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {