Skip to content

Commit 9546d22

Browse files
committed
Merge branch 'master' of github.com:wix/react-native-calendars into release
2 parents bb2cafd + 93d6423 commit 9546d22

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

src/calendar-list/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
137137
});
138138
}, [items]);
139139

140+
const getDateIndex = useCallback((date: string) => {
141+
return findIndex(items, function(item) {
142+
return item.toString() === date.toString();
143+
});
144+
}, [items]);
145+
140146
useEffect(() => {
141147
if (current) {
142148
scrollToMonth(new XDate(current));
@@ -188,7 +194,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
188194

189195
const addMonth = useCallback((count: number) => {
190196
const day = currentMonth?.clone().addMonths(count, true);
191-
if (sameMonth(day, currentMonth)) {
197+
if (sameMonth(day, currentMonth) || getDateIndex(day) === -1) {
192198
return;
193199
}
194200
scrollToMonth(day);
@@ -280,7 +286,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
280286
onViewableItemsChanged
281287
},
282288
]);
283-
289+
284290
return (
285291
<View style={style.current.flatListContainer} testID={testID}>
286292
<FlatList

src/expandableCalendar/Context/Provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const CalendarProvider = (props: CalendarContextProviderProps) => {
120120

121121
return (
122122
<CalendarContext.Provider value={contextValue}>
123-
<View style={wrapperStyle}>{children}</View>
123+
<View style={wrapperStyle} key={numberOfDays}>{children}</View>
124124
{showTodayButton && renderTodayButton()}
125125
</CalendarContext.Provider>
126126
);

src/expandableCalendar/agendaList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const AgendaList = (props: AgendaListProps) => {
176176
list?.current.scrollToLocation({
177177
animated: true,
178178
sectionIndex: sectionIndex,
179-
itemIndex: 0,
179+
itemIndex: 1,
180180
viewPosition: 0, // position at the top
181181
viewOffset: (constants.isAndroid ? sectionHeight.current : 0) + viewOffset
182182
});

src/expandableCalendar/index.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
154154
return false;
155155
};
156156

157+
useEffect(() => {
158+
// date was changed from AgendaList, arrows or scroll
159+
scrollToDate(date);
160+
}, [date]);
161+
157162
/** Number of weeks */
158163

159164
const getNumberOfWeeksInMonth = (month: string) => {
@@ -163,9 +168,9 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
163168
const numberOfWeeks = useRef(getNumberOfWeeksInMonth(date));
164169

165170
/** Position */
171+
166172
const [position, setPosition] = useState(numberOfDays ? Positions.CLOSED : initialPosition);
167173
const isOpen = position === Positions.OPEN;
168-
169174
const getOpenHeight = () => {
170175
if (!horizontal) {
171176
return Math.max(constants.screenHeight, constants.screenWidth);
@@ -174,17 +179,16 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
174179
};
175180
const openHeight = useRef(getOpenHeight());
176181
const closedHeight = useMemo(() => CLOSED_HEIGHT + (hideKnob || Number(numberOfDays) > 1 ? 0 : KNOB_CONTAINER_HEIGHT), [numberOfDays, hideKnob]);
177-
178182
const startHeight = useMemo(() => isOpen ? openHeight.current : closedHeight, [closedHeight, isOpen]);
179183
const _height = useRef(startHeight);
180184
const deltaY = useMemo(() => new Animated.Value(startHeight), [startHeight]);
185+
const headerDeltaY = useRef(new Animated.Value(isOpen ? -HEADER_HEIGHT : 0));
181186

182187
useEffect(() => {
183188
_height.current = startHeight;
184189
deltaY.setValue(startHeight);
185190
}, [startHeight]);
186191

187-
const headerDeltaY = useRef(new Animated.Value(isOpen ? -HEADER_HEIGHT : 0));
188192

189193
useEffect(() => {
190194
if (numberOfDays) {
@@ -249,7 +253,17 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
249253
return {height: deltaY};
250254
}, [deltaY]);
251255

252-
/** Effects */
256+
const numberOfDaysHeaderStyle = useMemo(() => {
257+
if (numberOfDays && numberOfDays > 1) {
258+
return {paddingHorizontal: 0};
259+
}
260+
}, [numberOfDays]);
261+
262+
const _headerStyle = useMemo(() => {
263+
return [numberOfDaysHeaderStyle, props.headerStyle];
264+
}, [props.headerStyle, numberOfDaysHeaderStyle]);
265+
266+
/** AccessibilityInfo */
253267

254268
useEffect(() => {
255269
if (AccessibilityInfo) {
@@ -262,11 +276,6 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
262276
}
263277
}, []);
264278

265-
useEffect(() => {
266-
// date was changed from AgendaList, arrows or scroll
267-
scrollToDate(date);
268-
}, [date]);
269-
270279
const handleScreenReaderStatus = (screenReaderEnabled: any) => {
271280
setScreenReaderEnabled(screenReaderEnabled);
272281
};
@@ -303,7 +312,6 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
303312
const firstDayOfWeek = (next ? 7 : -7) - dayOfTheWeek + firstDay;
304313
d.addDays(firstDayOfWeek);
305314
}
306-
307315
}
308316

309317
setDate?.(toMarkingFormat(d), UpdateSources.PAGE_SCROLL);
@@ -328,8 +336,8 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
328336
};
329337

330338
const handlePanResponderMove = (_: GestureResponderEvent, gestureState: PanResponderGestureState) => {
331-
// limit min height to closed height
332-
_wrapperStyles.current.style.height = Math.max(closedHeight, _height.current + gestureState.dy);
339+
// limit min height to closed height and max to open height
340+
_wrapperStyles.current.style.height = Math.min(Math.max(closedHeight, _height.current + gestureState.dy), openHeight.current);
333341

334342
if (!horizontal) {
335343
// vertical CalenderList header
@@ -338,6 +346,8 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
338346
// horizontal Week view
339347
if (!isOpen) {
340348
_weekCalendarStyles.style.opacity = Math.min(1, Math.max(1 - gestureState.dy / 100, 0));
349+
} else if (gestureState.dy < 0) {
350+
_weekCalendarStyles.style.opacity = Math.max(0, Math.min(Math.abs(gestureState.dy / 200), 1));
341351
}
342352
}
343353

@@ -358,7 +368,7 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
358368
onPanResponderMove: handlePanResponderMove,
359369
onPanResponderRelease: handlePanResponderEnd,
360370
onPanResponderTerminate: handlePanResponderEnd
361-
}) : PanResponder.create({}), [numberOfDays]);
371+
}) : PanResponder.create({}), [numberOfDays, position]);
362372

363373
/** Animated */
364374

@@ -554,16 +564,6 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
554564
);
555565
};
556566

557-
const numberOfDaysHeaderStyle = useMemo(() => {
558-
if (numberOfDays && numberOfDays > 1) {
559-
return {paddingHorizontal: 0};
560-
}
561-
}, [numberOfDays]);
562-
563-
const _headerStyle = useMemo(() => {
564-
return [numberOfDaysHeaderStyle, props.headerStyle];
565-
}, [props.headerStyle, numberOfDaysHeaderStyle]);
566-
567567
const renderCalendarList = () => {
568568
return (
569569
<CalendarList

src/timeline-list/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ const TimelineList = (props: TimelineListProps) => {
162162
scrollViewProps={{
163163
onMomentumScrollEnd
164164
}}
165-
key={numberOfDays}
166165
/>
167166
);
168167
};

0 commit comments

Comments
 (0)