How you support orientation changes on FlatList without changing columns on the fly?
See original GitHub issueI remember using FlatList
when it didn’t have this check:
invariant(
nextProps.numColumns === this.props.numColumns,
'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
'changing the number of columns to force a fresh render of the component.',
);
So basically I wrapped the FlatList
in a View
with onLayout
prop, and when the width of screen changes (from portrait <-> layout) I would change the number of columns (and some other calculations). This is not allowed now, so what it forces me to do is changing the key
prop of the FlatList
… This renders a completely new list, losing the scroll position and with a big delay even in production.
Any workarounds, thoughts ?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Invariant Violation: Changing numColumns on the fly is not ...
These are two different lists and I am not changing numColumns. It seems to me that react native is trying to use the...
Read more >FlatList - React Native
FlatList. A performant interface for rendering basic, flat lists, supporting the most handy features: Fully cross-platform.
Read more >A deep dive into React Native FlatList - LogRocket Blog
FlatList is a React Native component that allows you to render lists with zero hassle and minimal code. Learn how to customize FlatList....
Read more >Displaying a List in React Native: Map Method or FlatList ...
FlatList is a React Native component that provides scrolling features by default. ... Scroll to a specific position in the list; Multiple column...
Read more >Horizontal Flatlist item adapting to orientation changes - Reddit
My issue was that previous stack screen is a flatlist of not so simple row renders and that screen was getting re-rendered when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having same issue. Don’t understand why, I am re-rendering the child with the FlatList with a new number of columns. Is there some magic to work around this?
Sombody suggest do use
extraData
property of Flatlist to let Flatlist notice, that something changed.But this didn’t work for me, here is what work for me: Use
key={this.state.orientation}
while orientation e.g is “portrait” or “landscape”… it can be everything you want, but it had to change, if orientation changed.