Skip to content

Commit 3d4387b

Browse files
authored
Merge pull request #1856 from wix/fix/ExpandableCalendar_scroll_open
ExpandableCalendar - fix scrolling open calendar
2 parents 2a0039b + b96a043 commit 3d4387b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/calendar/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {View, ViewStyle, StyleProp} from 'react-native';
66
// @ts-expect-error
77
import GestureRecognizer, {swipeDirections} from 'react-native-swipe-gestures';
88

9+
import constants from '../commons/constants';
910
import {page, isGTE, isLTE, sameMonth} from '../dateutils';
1011
import {xdateToData, parseDate, toMarkingFormat} from '../interface';
1112
import {getState} from '../day-state-manager';
@@ -156,10 +157,10 @@ const Calendar = (props: CalendarProps) => {
156157
case SWIPE_DOWN:
157158
break;
158159
case SWIPE_LEFT:
159-
onSwipeLeft();
160+
constants.isRTL ? onSwipeRight() : onSwipeLeft();
160161
break;
161162
case SWIPE_RIGHT:
162-
onSwipeRight();
163+
constants.isRTL ? onSwipeLeft() : onSwipeRight();
163164
break;
164165
}
165166
}, [onSwipeLeft, onSwipeRight]);

src/expandableCalendar/index.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
186186

187187
const [position, setPosition] = useState(initialPosition || Positions.CLOSED);
188188
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false);
189-
const isOpen = position === Positions.OPEN;
189+
const isOpen = useMemo(() => {
190+
return position === Positions.OPEN;
191+
}, [position]);
190192

191193
/** Components' refs */
192194

@@ -294,6 +296,7 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
294296
const firstDayOfWeek = (next ? 7 : -7) - dayOfTheWeek + firstDay;
295297
d.addDays(firstDayOfWeek);
296298
}
299+
297300
setDate?.(toMarkingFormat(d), updateSources.PAGE_SCROLL);
298301
}
299302
};
@@ -365,16 +368,12 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
365368

366369
onCalendarToggled?.(_isOpen);
367370

368-
_setPosition(_height.current === closedHeight);
371+
setPosition(() => _height.current === closedHeight ? Positions.CLOSED : Positions.OPEN);
369372
closeHeader(_isOpen);
370373
resetWeekCalendarOpacity(_isOpen);
371374
}
372375
};
373376

374-
const _setPosition = (isClosed: boolean) => {
375-
setPosition(isClosed ? Positions.CLOSED : Positions.OPEN);
376-
};
377-
378377
const resetWeekCalendarOpacity = (isOpen: boolean) => {
379378
_weekCalendarStyles.style.opacity = isOpen ? 0 : 1;
380379
updateNativeStyles();
@@ -455,7 +454,7 @@ const ExpandableCalendar = (props: ExpandableCalendarProps) => {
455454
},
456455
100,
457456
{trailing: true, leading: false}
458-
), [date]);
457+
), [date, scrollPage]);
459458

460459
/** Renders */
461460

0 commit comments

Comments
 (0)