From 3a8249ac1af2c7c9aa47a5a09fbafa6402c57a5c Mon Sep 17 00:00:00 2001 From: Niclas Collmer Date: Mon, 19 Aug 2024 12:23:08 +0200 Subject: [PATCH] add support for rtl --- src/expandableCalendar/WeekCalendar/new.tsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/expandableCalendar/WeekCalendar/new.tsx b/src/expandableCalendar/WeekCalendar/new.tsx index bc68b7073c..4eca097c03 100644 --- a/src/expandableCalendar/WeekCalendar/new.tsx +++ b/src/expandableCalendar/WeekCalendar/new.tsx @@ -1,5 +1,5 @@ import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; -import {View} from 'react-native'; +import {I18nManager, View} from 'react-native'; import XDate from 'xdate'; import InfiniteList from '../../infinite-list'; @@ -24,7 +24,17 @@ const NUMBER_OF_PAGES = 50; const DEFAULT_PAGE_HEIGHT = 48; const WeekCalendar = (props: WeekCalendarProps) => { - const {current, firstDay = 0, markedDates, allowShadow = true, hideDayNames, theme, calendarWidth, calendarHeight = DEFAULT_PAGE_HEIGHT, testID} = props; + const { + current, + firstDay = 0, + markedDates, + allowShadow = true, + hideDayNames, + theme, + calendarWidth, + calendarHeight = DEFAULT_PAGE_HEIGHT, + testID + } = props; const context = useContext(CalendarContext); const {date, updateSource} = context; const style = useRef(styleConstructor(theme)); @@ -45,8 +55,11 @@ const WeekCalendar = (props: WeekCalendarProps) => { useEffect(() => { if (updateSource !== UpdateSources.WEEK_SCROLL) { const pageIndex = items.findIndex(item => sameWeek(item, date, firstDay)); + const totalWidth = items.length * containerWidth; + const scrollOffset = totalWidth - (pageIndex + 1) * containerWidth; + const finalOffset = I18nManager.isRTL ? scrollOffset : pageIndex * containerWidth; // @ts-expect-error - list.current?.scrollToOffset?.(pageIndex * containerWidth, 0, false); + list.current?.scrollToOffset?.(finalOffset, 0, false); } }, [date]); @@ -105,7 +118,7 @@ const WeekCalendar = (props: WeekCalendarProps) => { > {!hideDayNames && ( - + )}