Skip to content

Commit 97c627b

Browse files
committed
Merge branch 'alpha-1.0.5' of https://github.com/dohooo/react-native-reanimated-carousel into alpha-1.0.5
2 parents b5df38f + 3c6dbb2 commit 97c627b

File tree

2 files changed

+68
-59
lines changed

2 files changed

+68
-59
lines changed

example/src/App.tsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const data: ImageSourcePropType[] = [
2727
export default function App() {
2828
const progressValue = useSharedValue<number>(0);
2929
const r = React.useRef<ICarouselInstance | null>(null);
30+
3031
return (
3132
<View
3233
style={{
@@ -56,6 +57,26 @@ export default function App() {
5657
)}
5758
/>
5859
</View>
60+
<View
61+
style={{
62+
marginTop: 24,
63+
flexDirection: 'row',
64+
justifyContent: 'space-evenly',
65+
}}
66+
>
67+
<Button
68+
title="Prev"
69+
onPress={() => {
70+
r.current?.prev();
71+
}}
72+
/>
73+
<Button
74+
title="Next"
75+
onPress={() => {
76+
r.current?.next();
77+
}}
78+
/>
79+
</View>
5980
<View style={{ height: 240 }}>
6081
<Carousel<ImageSourcePropType>
6182
onProgressChange={(_, absoluteProgress) => {
@@ -98,16 +119,6 @@ export default function App() {
98119
})}
99120
</View>
100121
)}
101-
<View
102-
style={{
103-
marginTop: 24,
104-
flexDirection: 'row',
105-
justifyContent: 'space-evenly',
106-
}}
107-
>
108-
<Button title="Prev" onPress={() => r.current?.prev()} />
109-
<Button title="Next" onPress={() => r.current?.next()} />
110-
</View>
111122
</View>
112123
</View>
113124
);

src/Carousel.tsx

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -368,48 +368,52 @@ function Carousel<T extends unknown = any>(
368368
[getCurrentIndex, goToIndex, next, prev]
369369
);
370370

371-
const Layouts = React.useMemo<React.FC<{ index: number }>>(() => {
372-
switch (mode) {
373-
case 'parallax':
374-
return ({ index: i, children }) => (
375-
<ParallaxLayout
376-
parallaxScrollingOffset={parallaxScrollingOffset}
377-
parallaxScrollingScale={parallaxScrollingScale}
378-
computedAnimResult={computedAnimResult}
379-
width={width}
380-
handlerOffsetX={offsetX}
381-
index={i}
382-
key={i}
383-
loop={loop}
384-
>
385-
{children}
386-
</ParallaxLayout>
387-
);
388-
default:
389-
return ({ index: i, children }) => (
390-
<CarouselItem
391-
computedAnimResult={computedAnimResult}
392-
width={width}
393-
height={height}
394-
handlerOffsetX={offsetX}
395-
index={i}
396-
key={i}
397-
loop={loop}
398-
>
399-
{children}
400-
</CarouselItem>
401-
);
402-
}
403-
}, [
404-
loop,
405-
mode,
406-
computedAnimResult,
407-
height,
408-
offsetX,
409-
parallaxScrollingOffset,
410-
parallaxScrollingScale,
411-
width,
412-
]);
371+
const renderLayout = React.useCallback(
372+
(item: T, i: number) => {
373+
switch (mode) {
374+
case 'parallax':
375+
return (
376+
<ParallaxLayout
377+
parallaxScrollingOffset={parallaxScrollingOffset}
378+
parallaxScrollingScale={parallaxScrollingScale}
379+
computedAnimResult={computedAnimResult}
380+
width={width}
381+
handlerOffsetX={offsetX}
382+
index={i}
383+
key={i}
384+
loop={loop}
385+
>
386+
{renderItem(item, i)}
387+
</ParallaxLayout>
388+
);
389+
default:
390+
return (
391+
<CarouselItem
392+
computedAnimResult={computedAnimResult}
393+
width={width}
394+
height={height}
395+
handlerOffsetX={offsetX}
396+
index={i}
397+
key={i}
398+
loop={loop}
399+
>
400+
{renderItem(item, i)}
401+
</CarouselItem>
402+
);
403+
}
404+
},
405+
[
406+
loop,
407+
mode,
408+
computedAnimResult,
409+
height,
410+
offsetX,
411+
parallaxScrollingOffset,
412+
parallaxScrollingScale,
413+
width,
414+
renderItem,
415+
]
416+
);
413417

414418
return (
415419
<PanGestureHandler
@@ -426,13 +430,7 @@ function Carousel<T extends unknown = any>(
426430
position: 'relative',
427431
}}
428432
>
429-
{data.map((item, i) => {
430-
return (
431-
<Layouts index={i} key={i}>
432-
{renderItem(item, i)}
433-
</Layouts>
434-
);
435-
})}
433+
{data.map(renderLayout)}
436434
</Animated.View>
437435
</PanGestureHandler>
438436
);

0 commit comments

Comments
 (0)