Skip to content

Commit 78e98f0

Browse files
authored
ExpandableCalendar - fix transition bwt positions (open/close) (#2250)
* ExpandableCalendar - fix transition bwt positions (open/close) * revert deletion * fix indentation
1 parent caa0ab6 commit 78e98f0

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/expandableCalendar/index.tsx

Lines changed: 21 additions & 21 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);
@@ -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

0 commit comments

Comments
 (0)