@@ -3,7 +3,7 @@ import { StyleSheet } from "react-native";
33import { GestureHandlerRootView } from "react-native-gesture-handler" ;
44import { runOnJS , useDerivedValue } from "react-native-reanimated" ;
55
6- import { BaseLayout } from "./BaseLayout " ;
6+ import { ItemRenderer } from "./ItemRenderer " ;
77import { ScrollViewGesture } from "./ScrollViewGesture" ;
88
99import { useAutoPlay } from "../hooks/useAutoPlay" ;
@@ -13,7 +13,6 @@ import { useInitProps } from "../hooks/useInitProps";
1313import { useLayoutConfig } from "../hooks/useLayoutConfig" ;
1414import { useOnProgressChange } from "../hooks/useOnProgressChange" ;
1515import { usePropsErrorBoundary } from "../hooks/usePropsErrorBoundary" ;
16- import { useVisibleRanges } from "../hooks/useVisibleRanges" ;
1716import { CTX } from "../store" ;
1817import type { ICarouselInstance , TCarouselProps } from "../types" ;
1918import { computedRealIndexWithAutoFillData } from "../utils/computed-with-auto-fill-data" ;
@@ -30,8 +29,6 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
3029 data,
3130 // Length of fill data
3231 dataLength,
33- // Raw data that has not been processed
34- rawData,
3532 // Length of raw data
3633 rawDataLength,
3734 mode,
@@ -155,55 +152,8 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
155152 [ getCurrentIndex , next , prev , scrollTo ] ,
156153 ) ;
157154
158- const visibleRanges = useVisibleRanges ( {
159- total : dataLength ,
160- viewSize : size ,
161- translation : handlerOffset ,
162- windowSize,
163- loop,
164- } ) ;
165-
166155 const layoutConfig = useLayoutConfig ( { ...props , size } ) ;
167156
168- const renderLayout = React . useCallback (
169- ( item : any , i : number ) => {
170- const realIndex = computedRealIndexWithAutoFillData ( {
171- index : i ,
172- dataLength : rawDataLength ,
173- loop,
174- autoFillData,
175- } ) ;
176-
177- return (
178- < BaseLayout
179- key = { i }
180- index = { i }
181- handlerOffset = { offsetX }
182- visibleRanges = { visibleRanges }
183- animationStyle = { customAnimation || layoutConfig }
184- >
185- { ( { animationValue } ) =>
186- renderItem ( {
187- item,
188- index : realIndex ,
189- animationValue,
190- } )
191- }
192- </ BaseLayout >
193- ) ;
194- } ,
195- [
196- loop ,
197- rawData ,
198- offsetX ,
199- visibleRanges ,
200- autoFillData ,
201- renderItem ,
202- layoutConfig ,
203- customAnimation ,
204- ] ,
205- ) ;
206-
207157 return (
208158 < GestureHandlerRootView >
209159 < CTX . Provider value = { { props, common : commonVariables } } >
@@ -228,7 +178,20 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
228178 onTouchBegin = { scrollViewGestureOnTouchBegin }
229179 onTouchEnd = { scrollViewGestureOnTouchEnd }
230180 >
231- { data . map ( renderLayout ) }
181+ < ItemRenderer
182+ data = { data }
183+ dataLength = { dataLength }
184+ rawDataLength = { rawDataLength }
185+ loop = { loop }
186+ size = { size }
187+ windowSize = { windowSize }
188+ autoFillData = { autoFillData }
189+ offsetX = { offsetX }
190+ handlerOffset = { handlerOffset }
191+ layoutConfig = { layoutConfig }
192+ renderItem = { renderItem }
193+ customAnimation = { customAnimation }
194+ />
232195 </ ScrollViewGesture >
233196 </ CTX . Provider >
234197 </ GestureHandlerRootView >
0 commit comments