React native FlatList scrollToIndex指向大数据中的项目

React native FlatList scrollToIndex指向大数据中的项目,react-native,virtualization,react-native-flatlist,React Native,Virtualization,React Native Flatlist,我需要呈现+3000个大列表数据,我正在使用FlatList.scrollToIndex()来实现这一点 当他们按下字母表框时,我希望它自动滚动到以字母表开头的项目的索引 渲染后,它会滚动到某个项目。 但是,当索引远离当前窗口时,它会失败,因此它尚未渲染 所以我想知道是否有任何现实的方法可以做到这一点 如果有人告诉我怎么做,我将不胜感激。 谢谢大家! 功能滚动到alphabet(索引){ //当索引超出窗口太远时,此操作将失败。 listRef.current.scrollToIndex({i

我需要呈现+3000个大列表数据,我正在使用FlatList.scrollToIndex()来实现这一点

当他们按下字母表框时,我希望它自动滚动到以字母表开头的项目的索引

渲染后,它会滚动到某个项目。 但是,当索引远离当前窗口时,它会失败,因此它尚未渲染

所以我想知道是否有任何现实的方法可以做到这一点 如果有人告诉我怎么做,我将不胜感激。 谢谢大家!

功能滚动到alphabet(索引){
//当索引超出窗口太远时,此操作将失败。
listRef.current.scrollToIndex({index});
}
{
const{index,averageItemLength}=错误;
设置超时(()=>{
listRef.current.scrollToIndex({index});
//应该改为使用scrollToOffset({offset:currentScrollY+index*averageItemLength})?
}, 100);
}}
/>
function scrollToAlphabet(index) {
  // this fails when the index is too far outside of window.
  listRef.current.scrollToIndex({ index });
}

<FlatList
  ...
  ref={listRef}
  data={largeList}
  onScrollToIndexFailed={(error) => {
    const { index, averageItemLength } = error;
    setTimeout(() => {
      listRef.current.scrollToIndex({ index });
      // should instead like scrollToOffset({ offset: currentScrollY + index * averageItemLength }) ?
    }, 100);
  }}
/>