react-native-reanimated icon indicating copy to clipboard operation
react-native-reanimated copied to clipboard

Layout Animation with flatlist numColumns > 1

Open Majed04 opened this issue 4 years ago • 14 comments

Description

Hey i was trying to make layout animation with flatlist it works just fine with numColumns 1 but if i try 2 or more than 1 it doesn't work anymore when i delete item or add new one the whole item re render which not happening when numColumns set to 1

Expected behavior

when add new item or delete it should animate the other item to re order them not re render the whole list again!.

Actual behavior & steps to reproduce

https://user-images.githubusercontent.com/70872870/148182776-944a7e96-8179-4893-8c99-9189288c6e84.mov

https://user-images.githubusercontent.com/70872870/148182794-d7820ebb-8029-487e-9b51-2b71aeabca29.mov

Snack or minimal code example

Flatlist -:

<Animated.FlatList
          key={columns ? "oneRow" : "twoRow"}
          data={Tasks.data}
          numColumns={columns ? 1 : 2}
          showsVerticalScrollIndicator={false}
          itemLayoutAnimation={Layout}
          style={styles.Wrapper}
          renderItem={({ item, index }) => (
            <List
              key={index}
              index={index}
              item={item}
              DeleteHanlder={DeleteHanlder}
            />
          )}
        />

item itself -:

<Animated.View
        entering={FadeInDown.springify().delay(index * 150)}
        exiting={FadeOutUp.springify()}
        .....

Package versions

  • React Native: 0.64.3
  • React Native Reanimated: ~2.3.1

Affected platforms

  • [✅] iOS

Majed04 avatar Jan 05 '22 06:01 Majed04

Issue validator

The issue is valid!

github-actions[bot] avatar Jan 05 '22 06:01 github-actions[bot]

Did you solve this?

agoyal0422 avatar Apr 29 '22 21:04 agoyal0422

Did you solve this?

no, i even made repo for this issue if anyone want to clone and test it out here

Majed04 avatar Apr 29 '22 21:04 Majed04

Bruh why is this documentation so bad

agoyal0422 avatar Apr 29 '22 22:04 agoyal0422

Bruh why is this documentation so bad

sure the documentation not that great but still it's not that bad , but i have been with this issue for like 3 months and still didn't solve it....tried everything but still...i think i missing something so i'm waiting for any better developer to help me 😞

Majed04 avatar Apr 29 '22 22:04 Majed04

i found work around if anyone interesting i'll show you guys when i'm back home...

Majed04 avatar May 07 '22 06:05 Majed04

anyway the solution was to replace flatlist with scrolllist and make the width of the content half of the screen so it will be two columns and add the layout prop to animated view for the item.

Majed04 avatar May 07 '22 14:05 Majed04

Thank you for submitting this issue! Unfortunately we are not planning to support this feature (multiple columns flatList) and I'm glad you've found other solution.

The bug explanation: When numColumns is grater than 1 keyExtractor is substituted under the hood, so your keys don't match. It is difficult to fix, since all elements in a single row have the very same key, so you can't differ between two views in a single row.

Latropos avatar Jun 22 '23 13:06 Latropos

"I'm glad you've found other solution." - replacing flatlist with scrollview is never a good solution for optimizational reasons... it will eventually bite you for that reason.

relaxmeister avatar Apr 09 '24 07:04 relaxmeister

"I'm glad you've found other solution." - replacing flatlist with scrollview is never a good solution for optimizational reasons... it will eventually bite you for that reason.

not really, it depends on the quantity of items within the list.

Majed04 avatar Apr 09 '24 20:04 Majed04

"I'm glad you've found other solution." - replacing flatlist with scrollview is never a good solution for optimizational reasons... it will eventually bite you for that reason.

not really, it depends on the quantity of items within the list.

Absolutely, but im asuming people use flatlist for starters because of the reason it can/will contain lots of items. If not... im stunned.

relaxmeister avatar Apr 10 '24 07:04 relaxmeister

I absolutely can't switch to a scrollview for performance reasons! and at the moment the entry and exit animations are broken. Any new solution?

NiccoloCase avatar Aug 05 '24 11:08 NiccoloCase

I absolutely can't switch to a scrollview for performance reasons! and at the moment the entry and exit animations are broken. Any new solution?

Unfortunately, this is the only workaround I have found to switch the ScrollView. I fully understand that the FlatList is more optimized for handling larger lists

Majed04 avatar Aug 05 '24 12:08 Majed04

I used a library called moti.fyi It works like magic :)

If the list is big, then implement a way to render animation on the first few list items that are on the screen and leave the rest because they are not on the screen anyway :)

george-raphael avatar Oct 12 '24 20:10 george-raphael