Skip to content

Commit b5df38f

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 c67206f + f56d792 commit b5df38f

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

example/src/App.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* eslint-disable react-native/no-inline-styles */
22
import * as React from 'react';
3-
import { Dimensions, Image, ImageSourcePropType, View } from 'react-native';
3+
import {
4+
Button,
5+
Dimensions,
6+
Image,
7+
ImageSourcePropType,
8+
View,
9+
} from 'react-native';
410
import Carousel from '../../src/index';
511
import type { ICarouselInstance } from '../../src/Carousel';
612
import Animated, {
@@ -10,7 +16,7 @@ import Animated, {
1016
useSharedValue,
1117
} from 'react-native-reanimated';
1218

13-
const { width } = Dimensions.get('window');
19+
const window = Dimensions.get('window');
1420

1521
const data: ImageSourcePropType[] = [
1622
require('../assets/carousel-0.jpg'),
@@ -30,11 +36,11 @@ export default function App() {
3036
paddingTop: 100,
3137
}}
3238
>
33-
<View style={{ height: 300 }}>
39+
<View style={{ height: 240 }}>
3440
<Carousel<ImageSourcePropType>
3541
defaultIndex={1}
3642
ref={r}
37-
width={width}
43+
width={window.width}
3844
data={data}
3945
parallaxScrollingScale={0.8}
4046
renderItem={(source) => (
@@ -50,13 +56,13 @@ export default function App() {
5056
)}
5157
/>
5258
</View>
53-
<View style={{ height: 300 }}>
59+
<View style={{ height: 240 }}>
5460
<Carousel<ImageSourcePropType>
5561
onProgressChange={(_, absoluteProgress) => {
5662
progressValue.value = absoluteProgress;
5763
}}
5864
mode="parallax"
59-
width={width}
65+
width={window.width}
6066
data={data}
6167
parallaxScrollingScale={0.8}
6268
renderItem={(source) => (
@@ -92,6 +98,16 @@ export default function App() {
9298
})}
9399
</View>
94100
)}
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>
95111
</View>
96112
</View>
97113
);

src/hooks/useCarouselController.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ export function useCarouselController(opts: IOpts): ICarouselController {
5454

5555
onScrollBegin?.();
5656

57+
const currentPage = Math.round(handlerOffsetX.value / width);
58+
5759
handlerOffsetX.value = withTiming(
58-
handlerOffsetX.value - width,
60+
(currentPage - 1) * width,
5961
defaultTimingConfig,
6062
(isFinished: boolean) => {
6163
if (isFinished) {
@@ -79,8 +81,10 @@ export function useCarouselController(opts: IOpts): ICarouselController {
7981

8082
onScrollBegin?.();
8183

84+
const currentPage = Math.round(handlerOffsetX.value / width);
85+
8286
handlerOffsetX.value = withTiming(
83-
handlerOffsetX.value + width,
87+
(currentPage + 1) * width,
8488
defaultTimingConfig,
8589
(isFinished: boolean) => {
8690
if (isFinished) {

0 commit comments

Comments
 (0)