Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "Scroll To Top" in Native Base <Content> Component?

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)?

like image 846
Hanny Setiawan Avatar asked Jan 23 '18 07:01

Hanny Setiawan


People also ask

How do I scroll back to the top in React?

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.

How do I scrollTo a specific element in React native?

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}) .


1 Answers

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>

enter image description here

like image 128
akhil xavier Avatar answered Dec 26 '22 15:12

akhil xavier