alexzhirkevich / compottie

Compose Multiplatform Adobe After Effects Bodymovin (Lottie) animations rendering engine
https://alexzhirkevich.github.io/compottie
MIT License
202 stars 5 forks source link

[Bug]: iOS App hangs very frequently when using Compottie #15

Open Vaibhav2002 opened 1 month ago

Vaibhav2002 commented 1 month ago

What happened?

iOS App hangs very frequently when scrolling lists, swiping pager, selecting bottom nav items if there are lottie animations in the UI Like in every 2-3min while just scrolling a vertical lazy list or switching pager, iOS App completely hangs and user has to close the app and re-open it

Reason why I feel its due to Compottie

I replaced every lottie animation in app with a blank Box composable and even after hours of scrolling, swiping pages, doing all kind of interactions, app did not hang at all

Tested this for 2 days, and there has not been a single hang While as soon as i uncomment the Compottie code, the frequent app hangs starts again

This is degrading User Experience a lot.

This is only happening on iOS, Android works pretty good with no such hangs

Composable code

@Composable
fun Lottie(
    animationPath: String,
    modifier: Modifier = Modifier,
    isPlaying: Boolean = true,
    isInfinite: Boolean = true,
    contentScale: ContentScale = ContentScale.Fit,
    speed: Float = 1f,
    dynamicProperties: LottieDynamicProperties? = null,
    onComplete: (() -> Unit)? = null,
) {
    val composition by rememberLottieComposition {
        LottieCompositionSpec.JsonString(Res.readBytes(animationPath).decodeToString())
    }

    val progress by animateLottieCompositionAsState(composition)

    LaunchedEffect(progress) {
        if (progress == 1f) onComplete?.invoke()
    }

    val painter = rememberLottiePainter(
        composition = composition,
        isPlaying = isPlaying,
        iterations = if (isInfinite) Compottie.IterateForever else 1,
        speed = speed,
        dynamicProperties = dynamicProperties
    )

    Image(
        painter = painter,
        modifier = modifier,
        contentDescription = null,
        contentScale = contentScale
    )
}

Unsupported features

What Compottie version do you experience the bug on?

2.0.0-beta02

What platforms are you seeing the problem on?

iOS

Does Compottie log anythyng to the stdout / your logger set with Compottie.logger?

No
alexzhirkevich commented 1 month ago

Any animation example / xcode profiling info? What is causing the ANR? Memory? Cpu? Do you have multiple animations from the same json file on screen at the same time? Have you tested the release build? Can you try the sample app? There is also a lazy grid of various animations and nothing hangs for me

alexzhirkevich commented 1 month ago

Android works pretty good with no such hangs

The code is 99% shared so it can be a Compose issue

Vaibhav2002 commented 1 month ago

Yes, i have multiple animations from same json running in the same screen Some lazy column items have the same animation

This is only happening in release build, I never encountered this when running app on debug builds or in simulator I am using this on production, and its hanging in a lot of devices

Few animations which i am using:

alexzhirkevich commented 1 month ago

Try to disable composition cache with rememberLottieComposition(key = null)

alexzhirkevich commented 1 month ago

It's hard to tell anything concrete without a reproducer. Are there specific devices it hangs on? Old low-memory iphones? Is you app open source?

Vaibhav2002 commented 1 month ago

Making a reproducer is difficult, as it just happens even with a simple lazy column It hangs even on latest iPhone 15, 14 devices

App is not open source.

The composable i shared above, is how i use it everywhere.

I'll try with disabling composition cache and update here

Vaibhav2002 commented 1 month ago

@alexzhirkevich It still crashes Even after disabling composition cache

Vaibhav2002 commented 1 month ago

I managed to get some Crash logs, maybe that might help Medial-2024-08-05-171516.txt Medial-2024-08-05-171238.txt Medial-2024-08-05-171430.txt

LaatonWalaBhoot commented 2 weeks ago

@alexzhirkevich Any update on this? Facing the same issue

alexzhirkevich commented 2 weeks ago

Do you have a reproducer?

LaatonWalaBhoot commented 2 weeks ago

Its completely random. I am using it as in the Read me

alexzhirkevich commented 2 weeks ago

Any relevant stacktrace? Profiling info? Memory dump?

LaatonWalaBhoot commented 2 weeks ago

It's the same crash logs as @Vaibhav2002

alexzhirkevich commented 2 weeks ago

This logs only says that the app was terminated due to exceeding the backround work quota. What compose and kotlin version do you use?

LaatonWalaBhoot commented 2 weeks ago

Compose 1.6.11 Kotlin 2.0.0

alexzhirkevich commented 2 weeks ago

Any special usages? Maybe this happen when you use lotties with images or with dynamic properties?

LaatonWalaBhoot commented 2 weeks ago

Yes dynamic properties are used for light and dark switch Yes we use lottie with images but it works fine in Android Also the animation is in cells of lazy column

alexzhirkevich commented 2 weeks ago

Can you try it without dynamic properties and then without images? It will help to find the root cause