【问题标题】:React Native SectionList scroll to sectionReact Native SectionList 滚动到部分
【发布时间】:2017-09-13 03:39:49
【问题描述】:

我刚刚将我的 ListView 更改为 React Native 的新 SectionList,现在当我尝试使用 scrollTo 函数时应用程序崩溃,说明它未定义。我尝试查找可能有帮助的新/替代功能,但它们似乎都不起作用。

使用新的 SectionList 以编程方式滚动到特定部分的正确协议是什么?

到目前为止我一直在咨询的链接: https://github.com/facebook/react-native/issues/13151 https://facebook.github.io/react-native/releases/0.43/docs/virtualizedlist.html#scrolltoend

我目前的尝试:

var params = {animated:true,offset:Platform.OS == "ios" ? 244 : 264}
_mainListView.scrollToOffset(params)

【问题讨论】:

  • 已经 2 天了。到目前为止运气好吗?
  • @jpls93 还是不走运,看起来 GitHub 上有一些合并的分支为 SectionList 添加了 scrollTo 函数,但它们不是发布的一部分
  • 或许我们可以看看VirtualizedListscrollToprops
  • @jpls93 你知道如何向 VirtualizedList 添加节吗?
  • 也许这就是我们要找的scrollToItem/scrollToIndex/scrollToOffset

标签: javascript reactjs react-native


【解决方案1】:
scrollToSection = (sectionIndex,itemIndex = 1 ) => {
 this.refs.foo.scrollToLocation({
      sectionIndex: sectionIndex,
      itemIndex: itemIndex
    });
}

部分列表:

<SectionList
 ref = "foo",
 //something
/>

【讨论】:

    【解决方案2】:
    <SectionList
              ref={(sectionList) => { this.sectionList = sectionList }} .../>
    
    this.sectionList.scrollToLocation(
            {
              sectionIndex: sectionIndex,
              itemIndex: itemIndex
            }
          );
    

    这就是我过去使用这篇文章和https://snack.expo.io/HJp9mEQkG 的组合来让它工作的原因

    【讨论】:

      【解决方案3】:

      对我来说解决方法是

      list.current?.getScrollResponder()?.scrollTo({ x: 0, y: 0, animated: false })
      

      【讨论】:

        猜你喜欢
        • 2019-10-17
        • 2018-09-09
        • 1970-01-01
        • 2019-12-31
        • 2022-08-12
        • 2019-05-16
        • 2017-11-12
        • 1970-01-01
        • 2018-11-03
        相关资源
        最近更新 更多