Skip to content

Commit 4f5548c

Browse files
Inbal-Tishadids1221
authored andcommitted
TimelineList - fix for RTL under RN73 (#2598)
1 parent 742fe74 commit 4f5548c

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

example/src/app.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,40 @@ LocaleConfig.locales['en'] = {
2929
monthNamesShort: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'],
3030
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
3131
dayNamesShort: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
32-
// numbers: ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'] // number localization example
32+
// numbers: ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'] // <--- number localization example
3333
};
34-
LocaleConfig.defaultLocale = 'en';
3534

36-
/*
3735
LocaleConfig.locales['fr'] = {
3836
monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
3937
monthNamesShort: ['Janv.','Févr.','Mars','Avril','Mai','Juin','Juil.','Août','Sept.','Oct.','Nov.','Déc.'],
4038
dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
4139
dayNamesShort: ['Dim.','Lun.','Mar.','Mer.','Jeu.','Ven.','Sam.'],
4240
today: 'Aujourd\'hui'
4341
};
44-
LocaleConfig.defaultLocale = 'fr';
45-
*/
42+
43+
LocaleConfig.locales['he'] = {
44+
formatAccessibilityLabel: "dddd d 'of' MMMM 'of' yyyy",
45+
monthNames: [
46+
'ינואר',
47+
'פברואר',
48+
'מרץ',
49+
'אפריל',
50+
'מאי',
51+
'יוני',
52+
'יולי',
53+
'אוגוסט',
54+
'ספטמבר',
55+
'אוקטובר',
56+
'נובמבר',
57+
'דצמבר'
58+
],
59+
monthNamesShort: ['ינו', 'פבר', 'מרץ', 'אפר', 'מאי', 'יונ', 'יול', 'אוג', 'ספט', 'אוק', 'נוב', 'דצמ'],
60+
dayNames: ['ראון', 'שני', 'שלישי', 'קביעי', 'חמישי', 'שישי', 'שבת'],
61+
dayNamesShort: ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'],
62+
};
63+
64+
LocaleConfig.defaultLocale = 'en';
65+
4666

4767
Navigation.events().registerAppLaunchedListener(() => {
4868
Navigation.setRoot({

src/infinite-list/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
7070
}
7171
)
7272
);
73-
const shouldUseAndroidRTLFix = useMemo(() => {
74-
return constants.isAndroidRTL && isHorizontal;
73+
74+
const shouldFixRTL = useMemo(() => {
75+
return isHorizontal && constants.isRTL && (constants.isRN73() || constants.isAndroid);
7576
}, []);
7677

7778
const listRef = useCombinedRefs(ref);
@@ -87,7 +88,7 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
8788
}
8889

8990
setTimeout(() => {
90-
const x = isHorizontal ? constants.isAndroidRTL ? Math.floor(data.length / 2) + 1 : Math.floor(data.length / 2) * pageWidth : 0;
91+
const x = isHorizontal ? shouldFixRTL ? Math.floor(data.length / 2) + 1 : Math.floor(data.length / 2) * pageWidth : 0;
9192
const y = isHorizontal ? 0 : positionIndex * pageHeight;
9293
// @ts-expect-error
9394
listRef.current?.scrollToOffset?.(x, y, false);
@@ -100,7 +101,7 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
100101

101102
const contentOffset = event.nativeEvent.contentOffset;
102103
const y = contentOffset.y;
103-
const x = shouldUseAndroidRTLFix ? (pageWidth * data.length - contentOffset.x) : contentOffset.x;
104+
const x = shouldFixRTL ? (pageWidth * data.length - contentOffset.x) : contentOffset.x;
104105
const newPageIndex = Math.round(isHorizontal ? x / pageWidth : y / pageHeight);
105106
if (pageIndex.current !== newPageIndex) {
106107
if (pageIndex.current !== undefined) {
@@ -175,7 +176,6 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
175176
// @ts-expect-error
176177
ref={listRef}
177178
isHorizontal={isHorizontal}
178-
disableRecycling={shouldUseAndroidRTLFix}
179179
rowRenderer={renderItem}
180180
dataProvider={dataProvider}
181181
layoutProvider={layoutProvider ?? _layoutProvider.current}

src/timeline-list/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ export interface TimelineListProps {
5353

5454
const TimelineList = (props: TimelineListProps) => {
5555
const {timelineProps, events, renderItem, showNowIndicator, scrollToFirst, scrollToNow, initialTime} = props;
56+
const shouldFixRTL = constants.isRTL && (constants.isRN73() || constants.isAndroid); // isHorizontal = true
5657
const {date, updateSource, setDate, numberOfDays = 1, timelineLeftInset} = useContext(Context);
5758
const listRef = useRef<any>();
5859
const prevDate = useRef(date);
5960
const [timelineOffset, setTimelineOffset] = useState();
6061

6162
const {pages, pagesRef, resetPages, resetPagesDebounce, scrollToPageDebounce, shouldResetPages, isOutOfRange} =
62-
useTimelinePages({date, listRef, numberOfDays});
63+
useTimelinePages({date, listRef, numberOfDays, shouldFixRTL});
6364

6465
const scrollToCurrentDate = useCallback((date: string) => {
6566
const datePageIndex = pagesRef.current.indexOf(date);
@@ -74,8 +75,7 @@ const TimelineList = (props: TimelineListProps) => {
7475
prevDate.current = date;
7576
}, [updateSource]);
7677

77-
const initialOffset = useMemo(() =>
78-
constants.isAndroidRTL ? constants.screenWidth * (PAGES_COUNT - INITIAL_PAGE - 1) : constants.screenWidth * INITIAL_PAGE, []);
78+
const initialOffset = useMemo(() => shouldFixRTL ? constants.screenWidth * (PAGES_COUNT - INITIAL_PAGE - 1) : constants.screenWidth * INITIAL_PAGE, []);
7979

8080
useEffect(() => {
8181
if (date !== prevDate.current) {
@@ -97,7 +97,7 @@ const TimelineList = (props: TimelineListProps) => {
9797

9898
const onPageChange = useCallback(
9999
throttle((pageIndex: number) => {
100-
const newDate = pages[constants.isAndroidRTL ? pageIndex - 1 : pageIndex];
100+
const newDate = pages[shouldFixRTL ? pageIndex - 1 : pageIndex];
101101
if (newDate !== prevDate.current) {
102102
setDate(newDate, UpdateSources.LIST_DRAG);
103103
}

src/timeline-list/useTimelinePages.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ interface UseTimelinePagesProps {
1515
date: string;
1616
listRef: RefObject<any>;
1717
numberOfDays: number;
18+
shouldFixRTL: boolean;
1819
}
1920

20-
const UseTimelinePages = ({date, listRef, numberOfDays}: UseTimelinePagesProps) => {
21+
const UseTimelinePages = ({date, listRef, numberOfDays, shouldFixRTL}: UseTimelinePagesProps) => {
2122
const pagesRef = useRef(
2223
times(PAGES_COUNT, i => {
2324
return generateDay(date, numberOfDays * (i - Math.floor(PAGES_COUNT / 2)));
@@ -48,7 +49,7 @@ const UseTimelinePages = ({date, listRef, numberOfDays}: UseTimelinePagesProps)
4849
}, []);
4950

5051
const scrollToPage = (pageIndex: number) => {
51-
listRef.current?.scrollToOffset(constants.isAndroidRTL ? ((PAGES_COUNT - 1 - pageIndex) * constants.screenWidth) : (pageIndex * constants.screenWidth), 0, false);
52+
listRef.current?.scrollToOffset(shouldFixRTL ? ((PAGES_COUNT - 1 - pageIndex) * constants.screenWidth) : (pageIndex * constants.screenWidth), 0, false);
5253
};
5354

5455
const resetPages = (date: string) => {

0 commit comments

Comments
 (0)