After upgrading to react-native 0.61 i get a lot of warnings like that:
VirtualizedLists should never be nested inside plain ScrollViews with the same orientation - use another VirtualizedList-backed container instead.
What is the other VirtualizedList-backed container
that i should use, and why is it now advised not to use like that?
If someone's still looking for a suggestion to the problem that @Ponleu and @David Schilling have described here (regarding content that goes above the FlatList), then this is the approach I took:
You can read more about this here: https://facebook.github.io/react-native/docs/flatlist#listheadercomponent
Hopefully it helps someone. :)
Just in case this helps someone, this is how I fixed the error in my case.
I had a
FlatList
nested inside aScrollView
:and I got rid of the
ScrollView
by using theFlatList
to render everything I needed, which got rid of the warning:I tried some ways to solve this, including
ListHeaderComponent
orListFooterComponent
, but it all didn't fit for me.layout I wanted to achieve is like this, and I wanted to get scrolled in once.
First I want to say thanks to this issue and comments, which gave me bunch of ideas.
I was thinking of
ListHeaderComponent
places above the Flatlist, but since myFlatlist
's direction was column, the header I wanted to place went on the left of theFlatlist
:(Then I had to try on
VirtualizedList-backed
thing. I just tried to pack all components inVirtualizedList
, whererenderItems
gives index and there I could pass components conditionally torenderItems
.I could have worked this with
Flatlist
, but I haven't tried yet.Finally it looks like this.
and of course able to scroll the whole screen.
In my opinion i can use map instead of FlatList. But in my case i wan't to show large list. Not using FlatList may cause performance issue. so i used this to suppress warning https://github.com/GeekyAnts/NativeBase/issues/2947#issuecomment-549210509
This problem come when you are using
<FlatList />
inside<ScrollView>
with the same orientation.To fix this, just add "horizontal" to your FlatList :
NB : Your FlatList will rendered horizontally
The warning appears because
ScrollView
andFlatList
share the same logic, ifFlatList
run insideScrollView
, it's duplicatedBy the way
SafeAreaView
doesn't work for me, the only way to solve isThe error disappears