-
-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gesture error when applying pagination #665
Comments
Hey @bil-lekid! I'm here to help you with any bugs, questions, or contributions while you wait for a human maintainer. Let's get to the bottom of this together! To resolve the "NativeViewGestureHandler must be used as a descendant of GestureHandlerRootView" error when using pagination with the Here's how you can modify your code to include the import * as React from "react";
import { View } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { useSharedValue } from "react-native-reanimated";
import Carousel, {
ICarouselInstance,
Pagination,
} from "react-native-reanimated-carousel";
import { SBItem } from "../../components/SBItem";
import SButton from "../../components/SButton";
import { ElementsText, window } from "../../constants";
const PAGE_WIDTH = window.width;
const colors = [
"#26292E",
"#899F9C",
"#B3C680",
"#5C6265",
"#F5D399",
"#F1F1F1",
];
function Index() {
const [isVertical, setIsVertical] = React.useState(false);
const [autoPlay, setAutoPlay] = React.useState(false);
const [pagingEnabled, setPagingEnabled] = React.useState<boolean>(true);
const [snapEnabled, setSnapEnabled] = React.useState<boolean>(true);
const progress = useSharedValue<number>(0);
const baseOptions = isVertical
? ({
vertical: true,
width: PAGE_WIDTH * 0.86,
height: PAGE_WIDTH * 0.6,
} as const)
: ({
vertical: false,
width: PAGE_WIDTH,
height: PAGE_WIDTH * 0.6,
} as const);
const ref = React.useRef<ICarouselInstance>(null);
const onPressPagination = (index: number) => {
ref.current?.scrollTo({
count: index - progress.value,
animated: true,
});
};
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<View
style={{
alignItems: "center",
}}
>
<Carousel
ref={ref}
{...baseOptions}
style={{
width: PAGE_WIDTH,
}}
loop
pagingEnabled={pagingEnabled}
snapEnabled={snapEnabled}
autoPlay={autoPlay}
autoPlayInterval={1500}
onProgressChange={progress}
mode="parallax"
modeConfig={{
parallaxScrollingScale: 0.9,
parallaxScrollingOffset: 50,
}}
data={colors}
renderItem={({ index }) => <SBItem index={index} />}
/>
<Pagination.Basic
progress={progress}
data={colors}
dotStyle={{ backgroundColor: "rgba(0,0,0,0.2)" }}
containerStyle={{ gap: 5, marginBottom: 10 }}
onPress={onPressPagination}
/>
<Pagination.Basic<{ color: string }>
progress={progress}
data={colors.map((color) => ({ color }))}
dotStyle={{
width: 25,
height: 4,
backgroundColor: "rgba(0,0,0,0.2)",
}}
activeDotStyle={{
overflow: "hidden",
}}
containerStyle={[
isVertical
? {
position: "absolute",
width: 25,
right: 5,
top: 40,
}
: undefined,
{
gap: 10,
marginBottom: 10,
},
]}
horizontal={!isVertical}
onPress={onPressPagination}
/>
<Pagination.Basic<{ color: string }>
progress={progress}
data={colors.map((color) => ({ color }))}
size={20}
dotStyle={{
borderRadius: 100,
backgroundColor: "rgba(0,0,0,0.2)",
}}
activeDotStyle={{
borderRadius: 100,
overflow: "hidden",
}}
containerStyle={[
isVertical
? {
position: "absolute",
width: 20,
right: 5,
top: 40,
}
: undefined,
{
gap: 5,
marginBottom: 10,
},
]}
horizontal={!isVertical}
onPress={onPressPagination}
/>
<Pagination.Basic<{ color: string }>
progress={progress}
data={colors.map((color) => ({ color }))}
size={20}
dotStyle={{
borderRadius: 100,
backgroundColor: "rgba(0,0,0,0.2)",
}}
activeDotStyle={{
borderRadius: 100,
overflow: "hidden",
}}
containerStyle={[
isVertical
? {
position: "absolute",
width: 20,
right: 5,
top: 40,
}
: undefined,
]}
horizontal={!isVertical}
renderItem={(item) => (
<View
style={{
backgroundColor: item.color,
flex: 1,
}}
/>
)}
onPress={onPressPagination}
/>
<SButton
onPress={() => setAutoPlay(!autoPlay)}
>{`${ElementsText.AUTOPLAY}:${autoPlay}`}</SButton>
<SButton
onPress={() => {
setIsVertical(!isVertical);
}}
>
{isVertical ? "Set horizontal" : "Set Vertical"}
</SButton>
<SButton
onPress={() => {
setPagingEnabled(!pagingEnabled);
}}
>
{`pagingEnabled:${pagingEnabled}`}
</SButton>
<SButton
onPress={() => {
setSnapEnabled(!snapEnabled);
}}
>
{`snapEnabled:${snapEnabled}`}
</SButton>
</View>
</GestureHandlerRootView>
);
}
export default Index; Make sure that the |
This bug seems to be fixed for me in I think it may have been fixed with v4.0.0-canary.15. The error also went away for me in The docs for |
Describe the bug
I copied the parallax horizontal code. It doesn't work but when I removed the pagination the carousel works. And I want to use the pagination
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Both Carousel and Pagination working
Screenshots
If applicable, add screenshots to help explain your problem.
Versions (please complete the following information):
"expo": "~51.0.28",
"react": "18.2.0",
"react-native": "0.74.5",
"react-native-gesture-handler": "~2.16.1",
"react-native-reanimated": "~3.10.1",
"react-native-reanimated-carousel": "4.0.0-alpha.12",
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: