【问题标题】:How to go to Top of React Native Flatlist with HeaderComponent如何使用 HeaderComponent 转到 React Native Flatlist 的顶部
【发布时间】:2019-09-02 14:29:18
【问题描述】:

我有一个带有 3 个标签(标签 A、B、C)的应用。假设选项卡 A 有一个带有 ListHeaderComponent 的平面列表。当用户打开应用程序时,将首先显示选项卡 A。然后用户可以转到选项卡 B、选项卡 C。当用户返回选项卡 A 时,我想滚动到平面列表的顶部(不是索引 0),而是滚动到标题组件的最顶部。我试过了

this.refs.listRef.scrollToIndex({animated: true, index: 0, viewPosition: 0});

但它不起作用。以前有人做过吗?提前致谢。

【问题讨论】:

  • 你想显示你配置的完整元素代码吗?
  • 我可以举个例子:<FlatList ref="listRef" extraData={this.state} ListHeaderComponent={this.headerComponent} renderItem={item => ( ... )} />

标签: react-native react-native-flatlist


【解决方案1】:

我找到了解决办法:

this.flatListRef.scrollToOffset({ animated: true, offset: 0 });

将滚动到最顶部。

【讨论】:

    猜你喜欢
    • 2018-10-30
    • 2019-03-09
    • 2019-10-24
    • 2020-07-27
    • 2018-04-28
    • 2019-07-27
    • 2021-09-11
    • 2018-08-02
    • 1970-01-01
    相关资源
    最近更新 更多