-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
Pagination Examlpe For Javascript instead of TypeScript #755
Comments
Hey, @shubhamkackar0203! I'm here to help you with your issue. Let's take a look at the problem together. The example you provided is written in TypeScript, but it can be easily adapted for JavaScript. Here's how you can modify it:
Here's the JavaScript version of the code: import React, { useRef } from "react";
import { Dimensions, Text, View } from "react-native";
import { useSharedValue } from "react-native-reanimated";
import Carousel, { Pagination } from "react-native-reanimated-carousel";
const data = [...new Array(6).keys()];
const width = Dimensions.get("window").width;
function App() {
const ref = useRef(null);
const progress = useSharedValue(0);
const onPressPagination = (index) => {
ref.current?.scrollTo({
count: index - progress.value,
animated: true,
});
};
return (
<View style={{ flex: 1 }}>
<Carousel
ref={ref}
width={width}
height={width / 2}
data={data}
onProgressChange={progress}
renderItem={({ index }) => (
<View
style={{
flex: 1,
borderWidth: 1,
justifyContent: "center",
}}
>
<Text style={{ textAlign: "center", fontSize: 30 }}>{index}</Text>
</View>
)}
/>
<Pagination.Basic
progress={progress}
data={data}
dotStyle={{ backgroundColor: "rgba(0,0,0,0.2)", borderRadius: 50 }}
containerStyle={{ gap: 5, marginTop: 10 }}
onPress={onPressPagination}
/>
</View>
);
}
export default App; This should work for JavaScript. Make sure you have the correct versions of the dependencies installed, as mentioned in similar threads [1][2]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
`View id="carousel-component" dataSet={{ kind: 'utils', name: 'pagination' }} style={{ gap: 10 }}>
I have imported all the required modules for that and still got an error: I am using below versions" |
i want to show the pagination component for my Carousel. The official document has the following code
import * as React from "react";
import { Dimensions, Text, View } from "react-native";
import { useSharedValue } from "react-native-reanimated";
import Carousel, {
ICarouselInstance,
Pagination,
} from "react-native-reanimated-carousel";
const data = [...new Array(6).keys()];
const width = Dimensions.get("window").width;
function App() {
const ref = React.useRef(null);
const progress = useSharedValue(0);
const onPressPagination = (index: number) => {
ref.current?.scrollTo({
/**
* Calculate the difference between the current index and the target index
* to ensure that the carousel scrolls to the nearest index
*/
count: index - progress.value,
animated: true,
});
};
return (
<View style={{ flex: 1 }}>
<Carousel
ref={ref}
width={width}
height={width / 2}
data={data}
onProgressChange={progress}
renderItem={({ index }) => (
<View
style={{
flex: 1,
borderWidth: 1,
justifyContent: "center",
}}
>
<Text style={{ textAlign: "center", fontSize: 30 }}>{index}
)}
/>
);
}
export default App;
However, Pagination,Basic is not working for JS. Can someone help me with this
The text was updated successfully, but these errors were encountered: