Skip to content

Commit c015873

Browse files
committed
fix: fixed an issue where the enable props couldn't set to false
fix #482
1 parent 978b59f commit c015873

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

.changeset/yellow-bottles-itch.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+
Fixed an issue where the enable props couldn't set to false.

example/app/src/pages/normal/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ function Index() {
3535
<Carousel
3636
{...baseOptions}
3737
loop
38+
enabled // Default is true, just for demo
3839
ref={ref}
3940
testID={"xxx"}
4041
style={{ width: "100%" }}
4142
autoPlay={isAutoPlay}
4243
autoPlayInterval={isFast ? 100 : 2000}
4344
data={data}
44-
onConfigurePanGesture={g => g.enabled(true)} // default is true, just for demo
45+
onConfigurePanGesture={g => g.enabled(true)} // Default is true, just for demo
4546
pagingEnabled={isPagingEnabled}
4647
onSnapToItem={index => console.log("current index:", index)}
4748
renderItem={({ index }) => <SBItem key={index} index={index} />}

src/components/ScrollViewGesture.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Animated, {
1818
} from "react-native-reanimated";
1919

2020
import { Easing } from "../constants";
21+
import { useUpdateGestureConfig } from "../hooks/useUpdateGestureConfig";
2122
import { CTX } from "../store";
2223
import type { WithTimingAnimation } from "../types";
2324
import { dealWithAnimation } from "../utils/deal-with-animation";
@@ -377,10 +378,11 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => {
377378
onGestureFinish,
378379
onConfigurePanGesture,
379380
]);
380-
const GestureContainer = enabled ? GestureDetector : React.Fragment;
381+
382+
useUpdateGestureConfig(gesture, { enabled });
381383

382384
return (
383-
<GestureContainer gesture={gesture}>
385+
<GestureDetector gesture={gesture}>
384386
<Animated.View
385387
ref={containerRef}
386388
testID={testID}
@@ -390,7 +392,7 @@ const IScrollViewGesture: React.FC<PropsWithChildren<Props>> = (props) => {
390392
>
391393
{props.children}
392394
</Animated.View>
393-
</GestureContainer>
395+
</GestureDetector>
394396
);
395397
};
396398

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useEffect } from "react";
2+
import type { PanGesture } from "react-native-gesture-handler";
3+
4+
export const useUpdateGestureConfig = (gesture: PanGesture, config: {
5+
enabled?: boolean
6+
}) => {
7+
const { enabled } = config;
8+
9+
useEffect(() => {
10+
if (typeof enabled !== "undefined")
11+
gesture.enabled(enabled);
12+
}, [enabled, gesture]);
13+
};

0 commit comments

Comments
 (0)