Updated on 2026-08-14

This commit is contained in:
Tangem 2024-06-11 15:24:34 +04:00
parent 821be73571
commit ba4ceb2e8b
8 changed files with 101 additions and 14 deletions

View file

@ -0,0 +1,8 @@
package com.tangem.core.decompose.factory
import com.tangem.core.decompose.context.AppComponentContext
interface ComponentFactory<Component : Any, Params : Any> {
fun create(context: AppComponentContext, params: Params): Component
}

View file

@ -6,6 +6,7 @@ import com.arkivanov.decompose.router.stack.pop
import com.arkivanov.decompose.router.stack.popWhile
import com.arkivanov.decompose.router.stack.pushNew
import com.arkivanov.essenty.instancekeeper.InstanceKeeper
import kotlin.reflect.KClass
internal class DefaultRouter(
private val navigationProvider: AppNavigationProvider,
@ -23,9 +24,23 @@ internal class DefaultRouter(
navigation.pop(onComplete)
}
override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
override fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit) {
navigation.popWhile(
predicate = { it != route },
predicate = { it::class != routeClass },
onComplete = onComplete,
)
}
override fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit) {
navigation.popWhile(
predicate = { it::class != routeClass },
onComplete = onComplete,
)
}
override fun clear(onComplete: (isSuccess: Boolean) -> Unit) {
navigation.popWhile(
predicate = { true },
onComplete = onComplete,
)
}

View file

@ -0,0 +1,26 @@
package com.tangem.core.decompose.navigation
import kotlin.reflect.KClass
class DummyRouter : Router {
override fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
onComplete(true)
}
override fun pop(onComplete: (isSuccess: Boolean) -> Unit) {
onComplete(true)
}
override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
onComplete(true)
}
override fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit) {
onComplete(true)
}
override fun clear(onComplete: (isSuccess: Boolean) -> Unit) {
onComplete(true)
}
}

View file

@ -1,5 +1,7 @@
package com.tangem.core.decompose.navigation
import kotlin.reflect.KClass
/**
* Interface for a router in the application.
* It provides methods for navigating through the application.
@ -22,10 +24,25 @@ interface Router {
fun pop(onComplete: (isSuccess: Boolean) -> Unit = {})
/**
* Pops routes from the navigation stack until the specified route is found.
* Pops routes from the navigation stack until the specified [route] is found.
*
* @param route The route to pop to.
* @param onComplete The callback to be invoked when the operation is complete.
*/
fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit = {})
/**
* Pops routes from the navigation stack until the ***first*** specified [routeClass] is found.
*
* @param routeClass The route class to pop to.
* @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 = {})
}

View file

@ -0,0 +1,11 @@
package com.tangem.core.decompose.navigation
/**
* Pops routes from the navigation stack until the specified route [R] is found.
*
* @param R The route to pop to.
* @param onComplete The callback to be invoked when the operation is complete.
*/
inline fun <reified R : Route> Router.popTo(noinline onComplete: (isSuccess: Boolean) -> Unit = {}) {
popTo(R::class, onComplete)
}