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

Layout Animation doesn't work on Android with FlatList

Open adelbeke opened this issue 3 years ago • 12 comments

Description

There is two different behavior between iOS and Android, in fact on iOS this code runs without any problem but on Android none of theses animations works.

Expected behavior

The items should enter and exit smoothly for both platforms.

Actual behavior & steps to reproduce

iOS => The items enter and exit smoothly Android => The items enter and exit without animations

To reproduce, just runs this code with your own renderItem.

Snack or minimal code example

import React from 'react'
import { FlatList, FlatListProps } from 'react-native'
import Animated, { FadeInUp, FadeOut } from 'react-native-reanimated'

interface Props extends FlatListProps<any> {

}

const AnimatedFlatList = Animated.createAnimatedComponent(FlatList)

const createCellRenderer = () => {
    const cellRenderer: React.FC = (props) => {
        return (
            <Animated.View
                entering={FadeInUp.duration(250)}
                exiting={FadeOut.duration(250)}
            >
                {props.children}
            </Animated.View>
        )
    }

    return cellRenderer
}

export const AnimatedList = (props: Props) => {
    const CellRenderer = React.useMemo(
        () => createCellRenderer(),
        [],
    )

    return (
        <AnimatedFlatList
            {...props}
            CellRendererComponent={CellRenderer}
        />
    )
}

Package versions

  • React Native: 0.64.3
  • React Native Reanimated: 2.3.1
  • NodeJS: 16.13.0

Affected platforms

  • [X] Android
  • [ ] iOS
  • [ ] Web

adelbeke avatar Dec 20 '21 09:12 adelbeke

Issue validator

The issue is valid!

github-actions[bot] avatar Dec 20 '21 09:12 github-actions[bot]

For LayoutAnimation, please try Animated.FlatList as shown here #2674 instead of using createAnimatedComponent.

But there are some weird bugs atm #2703 #2704

Elabar avatar Dec 20 '21 16:12 Elabar

In fact, their example use createAnimatedComponent, take a look here: https://github.com/software-mansion/react-native-reanimated/blob/main/src/reanimated2/component/FlatList.tsx

adelbeke avatar Dec 20 '21 18:12 adelbeke

thats not example, it is their version of FlatList which overwrite the original FlatList's CellRendererComponent

Edit: opps, take back my words. Didnt see your implementation actually overwrite the CellRendererComponent

Elabar avatar Dec 20 '21 18:12 Elabar

Idea: Have you tried replacing default scrollView with createAnimatedComponent(ScrollView) via renderScrollComponent?

Another suggestion is to use layout animations outside of renderer, that's the one thing your code does differently from Reanimated implementation.

jgonet avatar Jan 28 '22 10:01 jgonet

@jakub-gonet Hello, In fact, I use the Flat List in this issue, your idea remains valuable?

adelbeke avatar Jan 28 '22 13:01 adelbeke

FlatList is actually VirtualizedList that uses ScrollView under the hood, my idea is to replace this component with AnimatedScrollView. You can use renderScrollComponent prop in FlatList to control which component is used for scrolling (as I said, ScrollView is the default but you can replace it with different component).

jgonet avatar Jan 28 '22 13:01 jgonet

Nice idea, little bit busy for now, but I'll try it !!! Thanks.

adelbeke avatar Jan 28 '22 14:01 adelbeke

I come to the news. I tested your implementation which didn't change much, I went back to the basic Flat List without overloading the cellRenderer, it works for the entering animation on both platforms, only the exiting on Android doesn't works.

It's an improvement I have an animation for the entering on Android. :)

adelbeke avatar Feb 01 '22 14:02 adelbeke

I'm having the same issue, entering works on both platforms but exiting only works on IOS. Did you happen to find a solution for this?

jacobSND avatar Mar 06 '22 21:03 jacobSND

@jacobSND Nop

adelbeke avatar Mar 06 '22 21:03 adelbeke

Still, having the same issue any update on this?

dev-asfand avatar Jul 26 '22 18:07 dev-asfand

Also seeing this issue

eprice122 avatar Aug 25 '22 01:08 eprice122

as well

tondeee avatar Nov 06 '22 12:11 tondeee

Is there an update ?

Facundo1609 avatar Dec 06 '22 20:12 Facundo1609

Issue is still open and replicable. I am using Expo react native and flat list

albanx avatar Mar 17 '23 10:03 albanx

Anyone found a solution for this yet?

eprice122 avatar Apr 06 '23 05:04 eprice122

any solution now? I am using v3.1.0 but seem not solved

fukemy avatar May 26 '23 02:05 fukemy

Closing this issue, since

  • const AnimatedFlatList = Animated.createAnimatedComponent(FlatList) is not a valid way to create animated flatlist, please use Animated.FlatList instead
  • We overwrite prop CellRendererComponent so unfortunately providing its value is not supported

Also it seems to be a duplicate of https://github.com/software-mansion/react-native-reanimated/issues/3100 which has slightly better repro

Latropos avatar Nov 15 '23 09:11 Latropos