Skip to content

Commit

Permalink
Merge branch 'master' into setup_rework
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Nov 2, 2023
2 parents af500e9 + 3e41077 commit a650b69
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 22 deletions.
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ internal class BackStackManager : LifecycleObserver {
)
backStacks.value -= stacksToDrop
stacksToDrop.forEach {
it.destroyDirectly()
it.destroy()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +15,24 @@ class RouteBuilder(
) {
private val route = arrayListOf<Route>()

private fun sceneInternal(
route: String,
deepLinks: List<String>,
navTransition: NavTransition?,
swipeProperties: SwipeProperties?,
content: @Composable (State<BackStackEntry>) -> 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
Expand All @@ -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) },
)
}

Expand Down Expand Up @@ -74,6 +93,18 @@ class RouteBuilder(
)
}

private fun floatingInternal(
route: String,
content: @Composable (State<BackStackEntry>) -> 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
Expand All @@ -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) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit a650b69

Please sign in to comment.