Trying to implement a image slider in React native using scrollview. The scrollview should scroll back to the first image if the user scrolls right from the last image. Implementing as a functional component. How do i detect that the user has scrolled ? I have tried using onScroll method of ScrollView , but it fires too many events. I want to basically reset the scrollview to first image if the user scrolls past the last image.
const scrollRef = useRef()
<View style={styles.container}>
<ScrollView
ref={ref => { scrollRef.current = ref }}
horizontal={true}
showsHorizontalScrollIndicator={false}
>
{images.map((image, imageId) => {
return (
<TouchableHighlight
key={imageId}
underlayColor='red'
>
<Image source={{uri: image}} style={{width:width, aspectRatio: 3, resizeMode: 'cover'}} />
</TouchableHighlight>
)
})}
</ScrollView>
</View>