diff --git a/navigation/common/src/commonMain/kotlin/com/mirego/pilot/navigation/DefaultPilotNavigationManager.kt b/navigation/common/src/commonMain/kotlin/com/mirego/pilot/navigation/DefaultPilotNavigationManager.kt index d99a22a6..70378223 100644 --- a/navigation/common/src/commonMain/kotlin/com/mirego/pilot/navigation/DefaultPilotNavigationManager.kt +++ b/navigation/common/src/commonMain/kotlin/com/mirego/pilot/navigation/DefaultPilotNavigationManager.kt @@ -1,6 +1,7 @@ package com.mirego.pilot.navigation import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay import kotlinx.coroutines.launch public open class DefaultPilotNavigationManager( @@ -9,6 +10,7 @@ public open class DefaultPilotNavigationManager() { private val internalRouteList: MutableList = mutableListOf() + private val internalTemporaryPoppedRouteList: MutableList = mutableListOf() override fun currentRoutes(): List = internalRouteList @@ -16,6 +18,7 @@ public open class DefaultPilotNavigationManager findRoute(uniqueId: String): T? = internalRouteList.firstOrNull { it.uniqueId == uniqueId } as? T + ?: internalTemporaryPoppedRouteList.firstOrNull { it.uniqueId == uniqueId } as? T override fun push(route: ROUTE, locally: Boolean) { coroutineScope.launch { @@ -40,6 +43,9 @@ public open class DefaultPilotNavigationManager) { + // We keep the routes for a little while in the popping list to allow animations to complete + // Otherwise, on android when pushing and pressing back quickly, the route would be removed + // from the list before the composable would have time to animate out and findRoute could not + // find the route anymore + internalTemporaryPoppedRouteList.addAll(routes) + coroutineScope.launch { + delay(5000) + internalTemporaryPoppedRouteList.removeAll(routes) + } + } + override fun popToId(uniqueId: String, inclusive: Boolean) { internalPopTo(popType = PopType.ById(uniqueId), inclusive = inclusive, callListener = true) } @@ -80,10 +102,12 @@ public open class DefaultPilotNavigationManager