airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.03k stars 5.41k forks source link

Lottie Compose with ViewPager compose in Android doesn't seem work correctly. #2224

Closed chanjungkim closed 1 year ago

chanjungkim commented 1 year ago

Here's my questions in Stackoverflow.

https://stackoverflow.com/questions/75118583/how-can-i-solve-outofmemory-issue-with-lottie-and-viewpager-in-jetpack-compose

https://stackoverflow.com/questions/75107130/how-can-i-call-a-page-once-in-jetpack-compose-viewpager

As far as I know, Android Devices have different memory size for each process. And some devices seems have memory problem with Lottie compose with ViewPager compose.

The OS that I've tested are from API23 to API33. Recent devices seem to work well but it uses a lot of memory.

The file I tried is attached. (Since I can't upload *.json, I uploaded in txt extension) intro_1.txt

  1. It draws the same content when the page isn't fully changed.
  2. The main problem is, Lottie is called many times. even though I don't touch anything. And also when I swipe to change the page, it's called a lot and it cause OutOfMemory.

Here's the record.

https://user-images.githubusercontent.com/19689773/212652410-231dd929-6726-4577-9811-7aed3ec8755d.mov

gpeal commented 1 year ago

Can you attach a project that reproduces this?

chanjungkim commented 1 year ago

@gpeal here's an example.

https://github.com/chanjungkim/viewPagerWithLottieInCompose

The points are

  1. memory issue. (app crashes in Lower API level or low process memory limit case)
  2. the behaviour is weird as I recorded above. I think this is not a lottie issue but ViewPager. But it you can consider lottie in this case, it would be better.
chanjungkim commented 1 year ago

@gpeal I followed accompanist and lottie compose document. But please let me know if there's something I missed in the code.

gpeal commented 1 year ago

Per the accompanist docs, you want to render the page passed into HorizontalPager child scope like this:

        ) { page ->
            ContentItem(contentList[page])
        }

I just switched your project to that and it seems to be working fine. I don't think this is a Lottie issue but feel free to reopen again if you think it is.