I am using react native reanimated carousel. In the carousel I am rendering images and when I tap on the image it doesn't scroll to that image. Here is the code:
<Carousel
ref={carouselRef}
loop
width={Dimensions.get("window").width}
height={300 / 2}
data={carTypes}
mode="parallax"
defaultIndex={1}
style={{ alignSelf: "center",justifyContent: "center", alignContent: "center"}}
scrollAnimationDuration={1000}
onSnapToItem={(index) => setActiveSlide(index)}
renderItem={({ item, index }) => (
<TouchableOpacity
**onPress={() => carouselRef.current.scrollTo(index)}**
activeOpacity={0.1}
style={{
backgroundColor: activeSlide !== index ? carouselActiveSlide(index) : "#3887EF",
borderWidth: 1,
justifyContent: 'center',
transform: [{ rotate: "32deg" }],
borderRadius: 32,
width: 50
}}
/>
I tried to test if other event like .next() , .prev() and they work as expected but .scrollTo(index) doesn't work. Can you tell me what am I missing ?
If you look closer at the doc, you have to pass an object in scollTo with the index in it : https://github.com/dohooo/react-native-reanimated-carousel/blob/main/docs/props.md#ref
Like this :
scrollTo({index: 1})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With