xxxxxxxxxx
<ScrollView ref={view => this._scrollView = view} />
And set the scroll position elsewhere with:
scrollToRow(itemIndex) {
this._scrollView.scrollTo({y:itemIndex * ROW_HEIGHT});
}
xxxxxxxxxx
import React, {useRef} from 'react';
import { ScrollView, Text, Button } from 'react-native';
export default function App() {
const scrollViewRef = useRef();
const autoScroll = () => {
let offset = 0;
setInterval(()=> {
offset += 20
scrollViewRef.current?.scrollTo({x: 0, y: offset, animated: true})
}, 1000)
}
return (
<ScrollView ref={scrollViewRef} >
<Button onPress={autoScroll} title="Start scrolling" />
<Text>
[ Very long text here where user has to scroll ]
</Text>
</ScrollView>
)
}