boolder-org / boolder-android

Boolder Android app https://www.boolder.com/en/app
MIT License
23 stars 12 forks source link

Fix navigation crashes when spamming clicks #129

Closed wang-li closed 1 month ago

wang-li commented 1 month ago

Spamming some buttons that would trigger a navigation could lead to multiple navigation event being processed by the navigation components library, with this kind of stack trace:

java.lang.IllegalArgumentException: Navigation action/destination com.boolder.boolder:id/navigate_to_area_overview_screen cannot be found from the current destination Destination(com.boolder.boolder:id/area_overview_fragment) label=Area overview fragment class=com.boolder.boolder.view.areadetails.areaoverview.AreaOverviewFragment
    at androidx.navigation.NavController.navigate(NavController.kt:1691)
    at androidx.navigation.NavController.navigate(NavController.kt:1609)
    at androidx.navigation.NavController.navigate(NavController.kt:2169)
    at com.boolder.boolder.view.map.MapFragment$navigateToAreaOverviewScreen$1.invokeSuspend(MapFragment.kt:458)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:231)
    at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:164)
    at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:466)
    at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:500)
    at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:489)
    at kotlinx.coroutines.CancellableContinuationImpl.resumeUndispatched(CancellableContinuationImpl.kt:587)
    at kotlinx.coroutines.android.HandlerContext$scheduleResumeAfterDelay$$inlined$Runnable$1.run(Runnable.kt:15)
    at android.os.Handler.handleCallback(Handler.java:958)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8177)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

and the following behavior:

https://github.com/boolder-org/boolder-android/assets/8343416/3a9d1c98-d9c6-4f55-b44c-6355883c3df1

This behavior is fixed by checking that the current destination is not already the intended one before triggering the navigation

https://github.com/boolder-org/boolder-android/assets/8343416/94575f03-9dc2-4c43-834e-ea06a3f5dd0c