GithubHelp home page GithubHelp logo

andrew-andilevko-itechart / react-native-infinite-flatlist-patch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ifsnow/react-native-infinite-flatlist-patch

0.0 0.0 0.0 22 KB

Now easily solve the problem of infinite scrolling!

JavaScript 100.00%

react-native-infinite-flatlist-patch's Introduction

NPM Version

Infinite scrolling is one of the most used UX in App. In React Native, This is implemented using the onEndReached props of FlatList.

Unfortunately, It doesn't work well as expected. I think it's one of the headaches that hasn't been solved for quite some time. We had to make it work by modifying onEndReachedThreshold several times, but eventually it doesn't work efficiently.

Now, This patch will make it work as you expect! It's too easy to use.

History

My PR is in progress, but React Native may not be easy to apply because there are so many things to consider. So, I decided to provide this patch for those who needed it.

Usage

Install

Once installed, react-native's FlatList is automatically patched.

yarn add react-native-infinite-flatlist-patch --dev

postinstall, postuninstall should be added to prevent this patch from being restored whenever packages are changed.

{
  ...
  "scripts": {
    ...,
    "postinstall": "yarn run infinite-flatlist-patch",
    "postuninstall": "yarn run infinite-flatlist-patch"
  }
}

If you were already using postinstall, you can add the patch script later.

"postinstall": "yarn run jetify; yarn run infinite-flatlist-patch"

Execute manually

You can execute the patch manually with the command below.

yarn run infinite-flatlist-patch

Uninstall

Just delete the command you added to postinstall, postuninstall and remove my package.

Check out the improvements

You can test it yourself with this test app.

This app is to test the improvements of onEndReached of FlatList.

  • The list has 10 items at the beginning.
  • When onEndReached is called, 10 items are added.

After the initial rendering

# Official FlatList

Official FlatList initial rendering

OnEndReached is called twice in a short period and FlatList has 30 items.

# Patched FlatList

Patched FlatList initial rendering

OnEndReached is not called and FlatList has 10 items.

After scrolling to the 11th item

# Official FlatList

Official FlatList scrolling

OnEndReached is called twice in a short period and FlatList has 50 items.

# Patched FlatList

Patched FlatList scrolling

OnEndReached is called twice when required and FlatList has 30 items.

react-native-infinite-flatlist-patch's People

Contributors

ifsnow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.