Scroll to top of ScrollView
in functional components
import { useRef } from 'react';
const scrollRef = useRef();
const onPressTouch = () => {
scrollRef.current?.scrollTo({
y: 0,
animated: true,
});
}
<ScrollView ref={scrollRef}>
...your elements
</ScrollView>
<TouchableOpacity onPress={onPressTouch}></TouchableOpacity>
- First add a
ref
attribute to yourScrollView
component. Example:<ScrollView ref='_scrollView'>
- Then wherever you want to scroll to top do this Example:
onPress={() => { this.refs._scrollView.scrollTo(0); }}