I'm using Expo
and implement Native Base
on it, I'm trying to do "Scroll to Top" whenever "MainTabNavigator" Icon <Ionicons/>
Should the handle implemented in <Content>
or in the <Ionicons/>
(in MainTabNavigator)?
Use the window. scrollTo() method to scroll to the top of the page in React, e.g. window. scrollTo(0, 0) . The scrollTo method on the window object scrolls to a particular set of coordinates in the document.
If your list items are of equal height, you can use them to implement scrolling to a specific item by calling scrollTo({y:itemIndex * ROW_HEIGHT}) .
try this
<Container>
<Content ref={c => (this.component = c)}>
<Text style={styles.text}>test</Text>
<Text style={styles.text}>test</Text>
<Text style={styles.text}>test</Text>
...
...
...
...
<Button onPress={() => this.component._root.scrollToPosition(0, 0)}>
<Text>Back to top</Text>
</Button>
</Content>
</Container>
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