React Native SectionList滚动到部分

时间:2017-04-17 13:52:11

标签: javascript reactjs react-native

我刚刚将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 个答案:

答案 0 :(得分:2)

<SectionList
          ref={(sectionList) => { this.sectionList = sectionList }} .../>

this.sectionList.scrollToLocation(
        {
          sectionIndex: sectionIndex,
          itemIndex: itemIndex
        }
      );

这是我过去使用此帖子和https://snack.expo.io/HJp9mEQkG

的混合工作

答案 1 :(得分:0)

scrollToSection = (sectionIndex,itemIndex = 1 ) => {
 this.refs.foo.scrollToLocation({
      sectionIndex: sectionIndex,
      itemIndex: itemIndex
    });
}

sectionList:

<SectionList
 ref = "foo",
 //something
/>
相关问题