如何&#34;滚动到顶部&#34;在Native Base <content>组件?

时间:2018-01-23 07:43:15

标签: react-native expo native-base

我正在使用Expo并在其上实施Native Base,我正在努力做到&#34;滚动到顶部&#34;每当&#34; MainTabNavigator&#34;图标<Ionicons/>

句柄应该在<Content>还是<Ionicons/>(在MainTabNavigator中)实现?

2 个答案:

答案 0 :(得分:8)

试试这个

 <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

答案 1 :(得分:-1)

您可以查看react-native-keyboard-aware-scroll-view的API和方法,因为这是<Content>的替代元素

https://github.com/APSL/react-native-keyboard-aware-scroll-view