I am a beginner to react native. I would like to know how to change the scrollview's offset on pressing a button because I could not find any props for ScrollView that lets you set the scroll position.The code looks roughly like this, where scrollOffset stores the position to scroll into.and a button that represents a position.
const example = () => {
const [scrollOffset, setScrollOffset] = useState(0);
const goToOffset = (val) => {
setScrollOffset(val);
}
return (
<View>
<Button onPress={goToOffset(width*5)} />
<ScrollView horizontal pagingEnabled >
{
images.map(
(item, index) => (
<Image
key={index}
source={{ uri: item }}
style={{ width:width/5, height:width/5, borderWidth:2, borderColor:index==active?"green":null }}
/>
)
)
}
</ScrollView>
</View>
)}