react-native: [FlatList] Sometimes FlatList rows are rendered, but not displayed until scroll. RN 0.43
Description
When using FlatList, rows are not displayed though renderItem
is called.
Rows appear immediately when scroll is triggered on the list.
Reproduction Steps and Sample Code
export default class List extends Component {
renderItem({item}) {
return (
<Text>{item}</Text>
);
}
render() {
return (
<FlatList
style={{
flex: 1,
backgroundColor: 'white',
}}
data={[1, 2]}
renderItem={this.renderItem}
/>
);
}
}
Solution
FlatList should always display its rendered items.
Additional Information
- React Native version: 0.43.0
- Platform: iOS
- Development Operating System: MacOS
- Dev tools: Xcode
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 36
- Comments: 78 (27 by maintainers)
Commits related to this issue
- disable removeClippedSubviews by default Summary: It's just causing problems (e.g. when combined with transform animations like those used in some navigators) and hopefully it's not necessary with JS... — committed to Maxwell2022/react-native by sahrens 7 years ago
- disable removeClippedSubviews by default Summary: It's just causing problems (e.g. when combined with transform animations like those used in some navigators) and hopefully it's not necessary with JS... — committed to thotegowda/react-native by sahrens 7 years ago
- Fix rows not showing until scrolled bug [React Native Issue #13316](https://github.com/facebook/react-native/issues/13316) This workaround renders all rows, even those outside of the list window. Th... — committed to EdgeApp/edge-react-gui by wolverineks 7 years ago
- Fix rows not showing until scrolled bug [React Native Issue #13316](https://github.com/facebook/react-native/issues/13316) This workaround renders all rows, even those outside of the list window. Th... — committed to EdgeApp/edge-react-gui by wolverineks 7 years ago
- Apply workaround for rows not showing on transaction list (React Native Issue #13316)[https://github.com/facebook/react-native/issues/13316] This commit disables the built-in optimizations for lists... — committed to EdgeApp/edge-react-gui by wolverineks 7 years ago
- Apply workaround for rows not showing on transaction list (React Native Issue #13316)[https://github.com/facebook/react-native/issues/13316] This commit disables the built-in optimizations for lists... — committed to EdgeApp/edge-react-gui by wolverineks 7 years ago
Does setting removeClippedSubviews={false} fix the issue? Sounds like the issue might be related to the navigator which would explain why we don’t see this problem at Facebook. cc @shergin
Hi mine fixed by giving
style={{ backgroundColor: 'white' }}
to flat listWhy the issue is closed?! 😃 Why
removeClippedSubviews={false}
is considered as working solution?When you set
removeClippedSubviews={false}
it renders ALL cells even those out of screen. Now imagine feed with 50-100 images. It will just blow up Android and probably any iOS app.@sahrens removeClippedSubviews={false} works for us for now.
We are using Navigator for a tab based app.
Still with the FlatList in React Native 0.54. It started happening all of a sudden and it’s actually annoying.
Here is a gif
Inspired by the comments in this thread from Kiarash-Z and douglasjunior, my fix to this solution was basically:
I could not use a
ActivityIndicator
but it seems RN needs new content to be rendered, even an “invisible” view (Note, with height of zero the bug still existed).I am having this issue still even with removeClippedSubviews={false}. Any additional solutions here?
We’re also seeing this issue. Looks like it could be something to do with the FlatList being in a navigator on iOS. Managed to reproduce it in a standalone project. You’ll have to excuse the code it’s a bit rough.
react-native init and add the following code as your index.ios.js. Once launched, tap on A. Tap remove. Tap back. Then you’ll need to scroll to get FlatList to re-render.
We found this on RN0.43.1 iOS simulator, iPad but not android. Seems to work as expected on android
My solution does not change the
removeClippedSubviews
.In my case, I do infinite scrolling loading 100 records per time, so I changed the values of
initialNumToRender
,maxToRenderPerBatch
andwindowSize
to 50.After loading more than 600 items, if I scroll up quickly, some items appear blank and are quickly loaded again, that was satisfactory to me. (In dev mode it looks pretty bad, but in release mode is good)
"react-native": "0.48.4"
removeClippedSubviews is now off by default in master.
This is still a problem with 0.50.3. removeClippedSubviews don’t seem to have any effect. Can we reopen this please?
@sahrens Could you explain why
removeClippedSubviews
fixes the issue? Is settingremoveClippedSubviews
asfalse
an optimal solution or is it just a temporary quick fix?Because I am using other RN libraries like react-native-sortable-listview that suffers from the similar issue (rows not appearing until initial scroll) even though it uses
ListView
, notFlatView
. Thus, I guess it’s not only limited toFlatList
, but also affect other types of scroll views as well. When I manually setremoveClippedSubviews={false}
, it fixes the issue, but also causes some unwanted side effects.@BlakeSimpson this is good, but again it is not viable solution in the long run because it is basically a hack.
Why is this closed again, if this is not resolved 👎
When fetching the data, render an
ActivityIndicator
asListFooterComponent
. Example here.this is still happening in 44 with removeClippedSubviews={false} set
initialNumToRender
&removeClippedSubviews
doesn’t seem like a viable answer here, because it removes all the optimisations when you have a huge list full of pictures.@Thomas101 @sahrens I am using
react-navigation
for your information.Found a working Hack for this.
Super weird, when I edited
getItemLayout
to not match my actual item component, it rendered immediately again for me…Edit: Or not.
we’ve migrated over to use https://github.com/Flipkart/recyclerlistview
@Kiarash-Z fix works and greatly improves performance. But why tho?
I have been fighting the problem of a FlatList with
horizontal={true}
andinitialScrollIndex
momentarily rendering the content, then blanking out until the view is scrolled again. The FlatList is rendered within a react-navigation StackNavigator.I found the following combination to work for me:
itemLayout
in whichlength
is equal to the window widthwidth
attribute on the top-level component within therenderitem
.This is my working component; I hope it’s helpful:
I’m still experiencing this issue.
removeClippedSubviews={false}
solved the problem for now.removeClippedSubviews
does not work for me, although I’m using a very common FlatList, as below:Currently, my solution is after retrieving list data, I have to manually scroll down 1px
this.listRef.scrollToOffset({offset: 1})
But it’s still a bug, I think it should only be closed after fixed by a new release.
@sahrens The list renders fine no matter what removeClippedSubviews is, as long as length is 0. Once I change back length to the screen width, regardless if removeClippedSubviews is turned off or not my list goes back to being blank until scroll.
<Flatlist style={{ flex: 1 }}/>
This trick work for me without switching to ListView.@DOHere Thank you very much for the tip.
I plan to stay with ListView as long as I can. FlatList has wasted way too much of my time.
After my experience of migrating multiple components to FlatList, I have had to roll back to ListView several times because of rendering not working properly as ListView did.
I will keep your advice in mind when I am forced to upgrade to FlatList.
I might have resolved it by only passing
initialScrollIndex
if the items would actually go off screen.Feels like this kind of logic should not be necessary.
React Native FlatList shows some blank in the quickly sliding. What is the solution?
I am still having this issue with
removeClippedSubviews = {false}
but then setting itfalse
also reducing my rendering performance. However, @douglasjunior solution worked perfectly fine for me without compromising performance. Thanks @douglasjunior 👍That shouldn’t be a problem - FlatListExample has an initialNumToRender much smaller than the data size with no issue.
@sahrens I just minimized
onScroll
property in my comment. Remove those properties does not affect anything. After investigating more,removeClippedSubviews={false}
works for me only if I addinitialNumToRender={myInitialData.length}
either. So my list does not render all items because my initial data size is more than the default number (10) of how many items to render in the initial batch.Does it worth to emphasize this in FlatList docs?
@dzuncoi, @huyanhh, do you think you might be able to put together an example project?
Got something really weird.
I’m trying to scroll to the end of my horizontal pager I made out of the Flatlist with this
Here’s my Flatlist:
When I make it like this, my list does not render until I scroll, but when I change
getItemLayout
to this:with the length attribute as 0, my list renders perfectly fine, and it scrolls to the end correctly in
componentDidMount
I am wodering this question as well. I am using react-navigation as well. Setting
removeClippedSubviews
to false also fixed this for me. I’m not sure of it’s implications (reduced perf?).