Updated on 2026-08-14
This commit is contained in:
parent
8be6a6bf9d
commit
01c263e4e1
6 changed files with 28 additions and 51 deletions
|
|
@ -20,13 +20,22 @@ internal class DefaultRouter(
|
|||
navigation.pushNew(route, onComplete)
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
val newRoutes = routes.toList()
|
||||
|
||||
navigation.navigate(
|
||||
transformer = { newRoutes },
|
||||
onComplete = { newStack, _ -> onComplete(newStack.size == newRoutes.size) },
|
||||
)
|
||||
}
|
||||
|
||||
override fun pop(onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
navigation.pop(onComplete)
|
||||
}
|
||||
|
||||
override fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
navigation.popWhile(
|
||||
predicate = { it::class != routeClass },
|
||||
predicate = { it != route },
|
||||
onComplete = onComplete,
|
||||
)
|
||||
}
|
||||
|
|
@ -37,11 +46,4 @@ internal class DefaultRouter(
|
|||
onComplete = onComplete,
|
||||
)
|
||||
}
|
||||
|
||||
override fun clear(onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
navigation.popWhile(
|
||||
predicate = { true },
|
||||
onComplete = onComplete,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,10 @@ class DummyRouter : Router {
|
|||
onComplete(true)
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
onComplete(true)
|
||||
}
|
||||
|
||||
override fun pop(onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
onComplete(true)
|
||||
}
|
||||
|
|
@ -19,8 +23,4 @@ class DummyRouter : Router {
|
|||
override fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
onComplete(true)
|
||||
}
|
||||
|
||||
override fun clear(onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
onComplete(true)
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import kotlin.reflect.KClass
|
|||
|
||||
/**
|
||||
* Interface for a router in the application.
|
||||
* It provides methods for navigating through the application.
|
||||
* It provides methods for navigating through the application by stack.
|
||||
*/
|
||||
interface Router {
|
||||
|
||||
|
|
@ -16,6 +16,14 @@ interface Router {
|
|||
*/
|
||||
fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit = {})
|
||||
|
||||
/**
|
||||
* Replaces ***all*** routes in the navigation stack with the specified [routes].
|
||||
*
|
||||
* @param routes The routes to replace the current stack with.
|
||||
* @param onComplete The callback to be invoked when the operation is complete.
|
||||
*/
|
||||
fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit = {})
|
||||
|
||||
/**
|
||||
* Pops the top route from the navigation stack.
|
||||
*
|
||||
|
|
@ -38,11 +46,4 @@ interface Router {
|
|||
* @param onComplete The callback to be invoked when the operation is complete.
|
||||
*/
|
||||
fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit = {})
|
||||
|
||||
/**
|
||||
* Pops all routes from the navigation stack.
|
||||
*
|
||||
* @param onComplete The callback to be invoked when the operation is complete.
|
||||
*/
|
||||
fun clear(onComplete: (isSuccess: Boolean) -> Unit = {})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue