Skip to content

Commit 2faf3be

Browse files
authored
Merge pull request #494 from dohooo/develop
Develop
2 parents 2a08ad9 + f10a6e0 commit 2faf3be

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

.changeset/mighty-pianos-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-reanimated-carousel': patch
3+
---
4+
5+
Removed the reset logic when user change the defaultIndex prop. (We couldn't update the handlerOffset value when user change the defaultIndex. Because the carousel component already be a non-controlled component. So the subsequent changes of defaultIndex will be ignored.)

src/hooks/useCommonVariables.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react";
21
import type Animated from "react-native-reanimated";
32
import { useSharedValue, useAnimatedReaction } from "react-native-reanimated";
43

@@ -26,16 +25,14 @@ export function useCommonVariables(
2625
loop,
2726
} = props;
2827
const size = vertical ? height : width;
29-
const validLength = dataLength - 1;
3028
const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);
3129
const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);
3230
const handlerOffset = defaultScrollOffsetValue ?? _handlerOffset;
3331
const prevDataLength = useSharedValue(dataLength);
3432

35-
React.useEffect(() => {
36-
handlerOffset.value = defaultHandlerOffsetValue;
37-
}, [vertical, handlerOffset, defaultHandlerOffsetValue]);
38-
33+
/**
34+
* When data changes, we need to compute new index for handlerOffset
35+
*/
3936
useAnimatedReaction(() => {
4037
const previousLength = prevDataLength.value;
4138
const currentLength = dataLength;
@@ -67,7 +64,7 @@ export function useCommonVariables(
6764

6865
return {
6966
size,
70-
validLength,
67+
validLength: dataLength - 1,
7168
handlerOffset,
7269
};
7370
}

0 commit comments

Comments
 (0)