如何在Native Base <Content>组件中"滚动到顶部"?

Han*_*wan 5 react-native native-base expo

我正在使用Expo并实现Native Base它,每当"MainTabNavigator"图标时我都会尝试"滚动到顶部"<Ionicons/>

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

akh*_*ier 9

试试这个

 <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>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述