11import findIndex from 'lodash/findIndex' ;
22import PropTypes from 'prop-types' ;
33import XDate from 'xdate' ;
4-
54import React , { forwardRef , useCallback , useEffect , useImperativeHandle , useMemo , useRef , useState } from 'react' ;
65import { FlatList , FlatListProps , View , ViewStyle } from 'react-native' ;
7-
86import { extractCalendarProps , extractHeaderProps } from '../componentUpdater' ;
97import { parseDate , toMarkingFormat , xdateToData } from '../interface' ;
108import { page , sameDate , sameMonth } from '../dateutils' ;
@@ -112,7 +110,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
112110
113111 const [ currentMonth , setCurrentMonth ] = useState ( parseDate ( current ) ) ;
114112
115- const shouldUseAndroidRTLFix = useMemo ( ( ) => constants . isAndroidRTL && horizontal , [ horizontal ] ) ;
113+ const shouldFixRTL = useMemo ( ( ) => ! constants . isRN73 ( ) && constants . isAndroidRTL && horizontal , [ horizontal ] ) ;
116114 /**
117115 * we render a lot of months in the calendar list and we need to measure the header only once
118116 * so we use this ref to limit the header measurement to the first render
@@ -194,12 +192,12 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
194192 const scrollToMonth = useCallback ( ( date : XDate | string ) => {
195193 const scrollTo = parseDate ( date ) ;
196194 const diffMonths = Math . round ( initialDate ?. current ?. clone ( ) . setDate ( 1 ) . diffMonths ( scrollTo ?. clone ( ) . setDate ( 1 ) ) ) ;
197- const scrollAmount = calendarSize * ( shouldUseAndroidRTLFix ? pastScrollRange - diffMonths : pastScrollRange + diffMonths ) ;
195+ const scrollAmount = calendarSize * ( shouldFixRTL ? pastScrollRange - diffMonths : pastScrollRange + diffMonths ) ;
198196
199197 if ( scrollAmount !== 0 ) {
200198 list ?. current ?. scrollToOffset ( { offset : scrollAmount , animated : animateScroll } ) ;
201199 }
202- } , [ calendarSize , shouldUseAndroidRTLFix , pastScrollRange , animateScroll ] ) ;
200+ } , [ calendarSize , shouldFixRTL , pastScrollRange , animateScroll ] ) ;
203201
204202 const addMonth = useCallback ( ( count : number ) => {
205203 const day = currentMonth ?. clone ( ) . addMonths ( count , true ) ;
@@ -289,7 +287,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
289287
290288 const onViewableItemsChanged = useCallback ( ( { viewableItems} : any ) => {
291289 const newVisibleMonth = parseDate ( viewableItems [ 0 ] ?. item ) ;
292- if ( shouldUseAndroidRTLFix ) {
290+ if ( shouldFixRTL ) {
293291 const centerIndex = items . findIndex ( ( item ) => isEqual ( parseDate ( current ) , item ) ) ;
294292 const adjustedOffset = centerIndex - items . findIndex ( ( item ) => isEqual ( newVisibleMonth , item ) ) ;
295293 visibleMonth . current = items [ centerIndex + adjustedOffset ] ;
@@ -300,7 +298,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
300298 setCurrentMonth ( visibleMonth . current ) ;
301299 }
302300 }
303- } , [ items , shouldUseAndroidRTLFix , current ] ) ;
301+ } , [ items , shouldFixRTL , current ] ) ;
304302
305303 const viewabilityConfigCallbackPairs = useRef ( [
306304 {
@@ -313,7 +311,7 @@ const CalendarList = (props: CalendarListProps & ContextProp, ref: any) => {
313311 < View style = { style . current . flatListContainer } testID = { testID } >
314312 < FlatList
315313 ref = { list }
316- windowSize = { shouldUseAndroidRTLFix ? pastScrollRange + futureScrollRange + 1 : undefined }
314+ windowSize = { shouldFixRTL ? pastScrollRange + futureScrollRange + 1 : undefined }
317315 style = { listStyle }
318316 showsVerticalScrollIndicator = { showScrollIndicator }
319317 showsHorizontalScrollIndicator = { showScrollIndicator }
0 commit comments