Implementing Recyclerview in Reactnative using Custom component

The RecyclerView is much more powerful, flexible and a major enhancement over ListView.The advantages of Recyclerview are:

  1. ViewHolder Pattern:In a ListView, it was recommended to use the ViewHolder pattern but it was never a compulsion. In case of RecyclerView, this is mandatory using the RecyclerView.ViewHolder class. This is one of the major differences between the ListView and the RecyclerView.It makes things a bit more complex in RecyclerView but a lot of problems that we faced in the ListView are solved efficiently.
  2. Reuses cells while scrolling up/down — this is possible with implementing View Holder in the listView adapter, but it was an optional thing, while in the RecycleView it’s the default way of writing adapter.

We tried to implement RecyclerView in reactnative by exposing it as a custom component.The steps to implement it as a module are as follows:

  1. Install the npm module:

npm install react-native-recycler-listview

2 .Edit settings.gradle file to include the module as follows:

https://gist.github.com/smhatre59/b17498ed1be66a4b104d1379c66b6144#file-gistfile1-txt

3.Edit android/app/build.gradle file to add required dependency:

https://gist.github.com/smhatre59/2fb2e07c7caa9800e6ec0d104d7991e7#file-gistfile1-txt

Run gradle sync to sync the module

4.Register the module in MainApplication.java

https://gist.github.com/smhatre59/464f64c232f5e41dc904e84ebabc7a46#file-react-native-recyclerview

5.Usage in react native:

https://gist.github.com/smhatre59/c67683c2f7542146508410141e2a3bfc#file-react-native-recyclerview

At present we can pass fontSize,padding and fontColor as props to Recyclerview.

If you want to learn more about RecyclerViews then check out the Android documentation to see what it can do. That’s it for today’s tutorial.

If you like this post please click ♡ symbol to recommend this post to others.

To read more articles and posts about react native you can visit my blog at:

http://technoetics.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.