1

我有一个SectionList如下,

 <SectionList
       ref={ref => this.sectionListRef = ref}
       renderItem={({ item, index, section }) => this.renderItems(item, index, section)}
       renderSectionHeader={({section: {title}}) => this.renderSectionHeader(title)}
       stickySectionHeadersEnabled={false}
       sections={openRequestsArrLength > 0 ? openRequestsArr : []}
       onScroll={(e) => this.handleScroll(e)}
 />

以下是将用户带到所需列表项的代码

  this.sectionListRef.scrollToLocation({
       viewOffset: scrollPosition,
       animated: false,
       itemIndex,
       sectionIndex
  });

当此代码执行时出现以下错误,

scrollToIndex 应与 getItemLayout 或 onScrollToIndexFailed 一起使用

我不确定如何使用既不getItemLayout也不onScrollToIndexFailed

任何人都可以让我知道如何从这一点开始以实现滚动到所需位置的要求吗?

谢谢你。

编辑:getItemLayout没有解决我的问题,它只是防止了上述错误。关于如何使用onScrollToIndexFailed作品scrollToLocation的任何建议

4

0 回答 0