voyager icon indicating copy to clipboard operation
voyager copied to clipboard

App Crashes, When The Button to Navigate to Another Screen, Is Pressed Twice in Succession

Open afolabisamguy opened this issue 1 year ago • 2 comments

E FATAL EXCEPTION: main (Ask Gemini) Process: com.alphatech.crypto, PID: 18748 java.lang.IllegalArgumentException: Key presentation.screen.ScanQrScreen: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:978) at android.view.Choreographer.doCallbacks(Choreographer.java:804) at android.view.Choreographer.doFrame(Choreographer.java:735) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:264) at android.app.ActivityThread.main(ActivityThread.java:7684) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:507) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@3962b5f, androidx.compose.ui.platform.MotionDurationScaleImpl@2a199ac, StandaloneCoroutine{Cancelling}@2a90675, AndroidUiDispatcher@56d960a]

afolabisamguy avatar Aug 19 '24 16:08 afolabisamguy

You can either provide a uniqueScreenKey for every screen class:

class MyScreen : Screen {
    override val key: ScreenKey = uniqueScreenKey
} 

or create some helper method to only navigate once:

public infix fun Stack<Screen>.pushOnce(item: Screen) {
    val lastScreen = lastItemOrNull

    if (lastScreen == null || lastScreen::class != item::class) {
        push(item)
    }
}

check official docs

ibraheemzulfiqar avatar Oct 08 '24 09:10 ibraheemzulfiqar

I'm encountring a similar issue where one button is able to push two screens with the same key onto the stack (and the screen models are shared for some reason, presumably because they have the same key?). This only occurs when I use transitions.

rushiiMachine avatar May 25 '25 08:05 rushiiMachine