简体   繁体   English

在 FlatList 中未调用 onEndReached 触发器

[英]onEndReached trigger is not being called in FlatList

Expected Behaviour: On end of page arrival the handleLoadMore function should be get called.预期行为:在页面到达结束时,应调用 handleLoadMore function。 But it's not getting called.但它没有被调用。 [Using Functional Component]. [使用功能组件]。

I have tried in below way.我已经尝试过以下方式。 But didn't find any solution.但没有找到任何解决方案。

Using FlatGrid component (Library based on FlatList).使用FlatGrid组件(基于 FlatList 的库)。 Directly used FlatList also.也直接使用了 FlatList。 The problem still remains.问题仍然存在。

      <FlatGrid
        itemDimension={130}
        items={offers}
        renderItem={renderItem}
        ListFooterComponent={renderFooter}
        initialNumToRender={2}
        maxToRenderPerBatch={1}
        windowSize={2}
        onEndReached={handleLoadMore}
        onEndReachedThreshold={0}
      />

HandleLoadMore function - HandleLoadMore function -

  const handleLoadMore = () => {
    setPageNumber(pageNumber + 1);

    console.log('PageNumber', pageNumber);
    console.log('Item Length', offers.length);
    offersAction.getOffers(pageNumber);
  };

Console Output -控制台 Output -

图片

You probably need to bind handleLoadMore to the class.您可能需要将handleLoadMore绑定到 class。 From The React Docs来自React 文档

Generally, if you refer to a method without () after it, such as onClick={this.handleClick} , you should bind that method.一般来说,如果引用的方法后面不带 (),比如onClick={this.handleClick} ,就应该绑定那个方法。

I used ScrollView as wrapper for FlatList in Parent Component.我在父组件中使用 ScrollView 作为 FlatList 的包装器。 Which was creating the issue as mentioned in https://github.com/facebook/react-native/issues/14756 .正如https://github.com/facebook/react-native/issues/14756中提到的那样,这是造成问题的原因。

Instead of 'ScrollView' using 'View' wrapper solved the issue.而不是使用“View”包装器的“ScrollView”解决了这个问题。

<View style={{ flex: 1 }}>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM