adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.27k stars 109 forks source link

RegisterScreen:transition was used multiple times #410

Open ArleyPereira opened 1 week ago

ArleyPereira commented 1 week ago

There is an issue I run into when I quickly double click a button that navigates to another screen in my Compose.

it looks like androidx.lifecycle:lifecycle added dropUnlessResumed in version 2.8.0-alpha02.

https://developer.android.com/jetpack/androidx/releases/lifecycle?hl=pt-br

I tested with version 2.8.0-rc01, but I got the error: CompositionLocal LocalLifecycleOwner not present.

voyager = "1.1.0-alpha04" composeBom = "2024.05.00" kotlin = "1.9.23"

FATAL EXCEPTION: main (Ask Gemini)
Process: br.com.hellodev.find360, PID: 15156
java.lang.IllegalArgumentException: Key br.com.hellodev.signup.presenter.screens.register.screen.RegisterScreen:transition was used multiple times
    at androidx.compose.runtime.saveable.SaveableStateHolderImpl$SaveableStateProvider$1$1.invoke(SaveableStateHolder.kt:89)
    at androidx.compose.runtime.saveable.SaveableStateHolderImpl$SaveableStateProvider$1$1.invoke(SaveableStateHolder.kt:88)
    at androidx.compose.runtime.DisposableEffectImpl.onRemembered(Effects.kt:83)
    at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers(Composition.kt:1295)
    at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:984)
    at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:1005)
    at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:639)
    at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:551)
    at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:41)
    at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109)
    at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41)
    at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1648)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1659)
    at android.view.Choreographer.doCallbacks(Choreographer.java:1129)
    at android.view.Choreographer.doFrame(Choreographer.java:1045)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1622)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:230)
    at android.os.Looper.loop(Looper.java:319)
    at android.app.ActivityThread.main(ActivityThread.java:8893)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@a7d1990, androidx.compose.ui.platform.MotionDurationScaleImpl@a6df289, StandaloneCoroutine{Cancelling}@fac328e, AndroidUiDispatcher@b8cfaaf]
Moozart commented 1 week ago

I think problem occurs when multiple click to navigate or same screen popud. If u remove SlideAnimation etc.. error can be gone. But I applied this solution for my project. I hope solver your problem.

override val key: ScreenKey = super.key + "${Random.nextDouble(Double.MIN_VALUE, Double.MAX_VALUE)}"
ArleyPereira commented 1 week ago

Thanks for your tip. I will try to apply it, while there is no solution from the library. From what I've seen, this error has been known for some time, but so far it still persists.

wiryadev commented 1 week ago

Face the same error. I used the 1.0.0 tho.

Edit: i tried 1.1.0 alpha04 and still the transition error

qdsfdhvh commented 1 week ago

I face the same crash,but i am upgrading to kotlin 2.0.0-RC2 and use release apk (r8), when I had open a object screen, and then open another object screen, app will be crash with it, i'm not sure what's the reason for that at the moment. ps: seem use data object can solve my problem.

wiryadev commented 1 week ago

Hi, i just found out something:

  1. dropUnlessResumed not working for this, not because of lifecycle owner, but when you click that quickly, the state is still resumed (check screenshot below)
  2. We can pass our own LifecycleOwner, but make sure you use LocalLifecyleOwner from androidx.compose.ui.platform, not the one from androidx.lifecycle.compose.

image

itsallan commented 11 hours ago

I think problem occurs when multiple click to navigate or same screen popud. If u remove SlideAnimation etc.. error can be gone. But I applied this solution for my project. I hope solver your problem.

override val key: ScreenKey = super.key + "${Random.nextDouble(Double.MIN_VALUE, Double.MAX_VALUE)}"

thanks mate this worked for me