question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How you support orientation changes on FlatList without changing columns on the fly?

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cyphirecommented, Jan 10, 2018

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?

1reaction
xstablecommented, Jul 27, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found