diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c7eeb653..a8e14259 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,15 +8,15 @@ androidGradlePlugin = "8.1.1" junit = "4.13.2" junitJupiterEngine = "5.10.0" junitJupiterApi = "5.10.0" -kotlin = "1.9.10" +kotlin = "1.9.20" kotlinxCoroutinesCore = "1.7.3" lifecycleRuntimeKtx = "2.6.2" -material = "1.5.3" -moleculeRuntime = "1.2.1" +material = "1.5.0" +moleculeRuntime = "1.3.0" savedstateKtx = "1.2.1" spotless = "6.22.0" -jetbrainsComposePlugin = "1.5.3" -skiko = "0.7.81" +jetbrainsComposePlugin = "1.5.10" +skiko = "0.7.85" koin = "3.5.0" koin-compose = "1.1.0" diff --git a/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/BackStackManager.kt b/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/BackStackManager.kt index 74b1a160..a8eb708d 100644 --- a/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/BackStackManager.kt +++ b/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/BackStackManager.kt @@ -150,7 +150,7 @@ internal class BackStackManager : LifecycleObserver { ) backStacks.value -= stacksToDrop stacksToDrop.forEach { - it.destroyDirectly() + it.destroy() } } } diff --git a/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/RouteBuilder.kt b/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/RouteBuilder.kt index 27914c14..feed09f9 100644 --- a/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/RouteBuilder.kt +++ b/precompose/src/commonMain/kotlin/moe/tlaster/precompose/navigation/RouteBuilder.kt @@ -1,6 +1,9 @@ package moe.tlaster.precompose.navigation import androidx.compose.runtime.Composable +import androidx.compose.runtime.State +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import moe.tlaster.precompose.navigation.route.FloatingRoute import moe.tlaster.precompose.navigation.route.GroupRoute import moe.tlaster.precompose.navigation.route.Route @@ -12,6 +15,24 @@ class RouteBuilder( ) { private val route = arrayListOf() + private fun sceneInternal( + route: String, + deepLinks: List, + navTransition: NavTransition?, + swipeProperties: SwipeProperties?, + content: @Composable (State) -> Unit, + ) { + addRoute( + SceneRoute( + route = route, + navTransition = navTransition, + deepLinks = deepLinks, + swipeProperties = swipeProperties, + content = { content(remember { mutableStateOf(it) }) }, + ), + ) + } + /** * Add the scene [Composable] to the [RouteBuilder] * @param route route for the destination @@ -26,14 +47,12 @@ class RouteBuilder( swipeProperties: SwipeProperties? = null, content: @Composable (BackStackEntry) -> Unit, ) { - addRoute( - SceneRoute( - route = route, - navTransition = navTransition, - deepLinks = deepLinks, - swipeProperties = swipeProperties, - content = content, - ), + sceneInternal( + route = route, + navTransition = navTransition, + deepLinks = deepLinks, + swipeProperties = swipeProperties, + content = { content(it.value) }, ) } @@ -74,6 +93,18 @@ class RouteBuilder( ) } + private fun floatingInternal( + route: String, + content: @Composable (State) -> Unit, + ) { + addRoute( + FloatingRoute( + route = route, + content = { content(remember { mutableStateOf(it) }) }, + ), + ) + } + /** * Add the floating [Composable] to the [RouteBuilder], which will show over the scene * @param route route for the destination @@ -83,11 +114,9 @@ class RouteBuilder( route: String, content: @Composable (BackStackEntry) -> Unit, ) { - addRoute( - FloatingRoute( - route = route, - content = content, - ), + floatingInternal( + route = route, + content = { content(it.value) }, ) } diff --git a/precompose/src/commonTest/kotlin/moe/tlaster/precompose/navigation/BackStackManagerTest.kt b/precompose/src/commonTest/kotlin/moe/tlaster/precompose/navigation/BackStackManagerTest.kt index 34c4951a..43cd265c 100644 --- a/precompose/src/commonTest/kotlin/moe/tlaster/precompose/navigation/BackStackManagerTest.kt +++ b/precompose/src/commonTest/kotlin/moe/tlaster/precompose/navigation/BackStackManagerTest.kt @@ -581,9 +581,17 @@ class BackStackManagerTest { lifecycleOwner = lifecycleOwner, persistNavState = false, ) - manager.push("screen2") - manager.push("screen1", NavOptions(popUpTo = PopUpTo("screen1"))) - manager.push("screen1") + + fun navigate(path: String, navOptions: NavOptions) { + val previousEntry = manager.backStacks.value.lastOrNull() + manager.push(path, navOptions) + // Mark the previous entry as inactive to simulate the lifecycle change by the NavHost + previousEntry?.inActive() + } + + navigate("screen2", NavOptions()) + navigate("screen1", NavOptions(popUpTo = PopUpTo("screen1"))) + navigate("screen1", NavOptions()) assertEquals( listOf("screen1", "screen1", "screen1"),