0
I’m building an app on React Native
using the services of Firebase
and Redux
. Every day, I register new Documents there and so my database gets bigger.
In my app
I was giving a rescue all records of a collection of Firebase when opening a kind of screen "Feed". I knew I would eventually have to implement a code pagination. So, recently I reached ~35 records on DB
and things got weird: The app didn’t always load all the records, and when it did, it didn’t allow it to touch the renderItems
of FlatList
.
Here is the code of mine FlatList
:
<FlatList
ListHeaderComponent={/*irrelevante*/}
data={this.props.locals}
keyExtractor={item => item.id}
renderItem={this.renderLocal}
/>
this.renderLocal
renderLocal = ({item, index}) => {
return <Local {...item} goToLocal={() => this.goToLocal(item.id)}/>
}
Important to mention: the component Local
which is rendered several times by Flatlist, is "heavy" since it contains certain styling, two images loaded through URI and two images stored locally.
So I started the process of creating a pagination, doing some things:
- I created the
paginationIndex
and inserted it into thestate
in areducer
with value of 15. - Dei
slice(0, this.props.paginationIndex)
in the property arraydata
in theFlatList
. I chose to do so the expectation that my database contains something like 200 records at most, which would be light when rescuing all and entering in theReducer
. - I created a button that gives a
dispatch
which increases by 15 opaginationIndex
. - I made my component
Local
in aPureComponent
, to improve performance withFlatList
And the resulting behavior was always the same: at the beginning it loads the 15 components, when clicking on the pagination button, sometimes another 15 appear but everything hangs (as described in the second paragraph). I tried to make changes to understand the limits of that. Searching 15 initially, with a pagination incrementing 10 more components, it works, only in the next pagination (which would result in a total of 35 components) the same error occurs.
The conclusion I had is that Flatlist has this limitation of rendering. But I can’t go through it, to have the effect of "Infinite Scroll" as seen on Instagram, for example.
My question then, is on how to create this Infinite Scroll correctly.
Follow the link of some discussions on similar problems, where I tried some proposed solutions without result.
https://github.com/Flipkart/recyclerlistview uses this lib, it is extremely perfomatic.
– Marconi