Updated on 2026-08-14

This commit is contained in:
Tangem 2024-06-14 11:22:01 +04:00
parent 8be6a6bf9d
commit 01c263e4e1
6 changed files with 28 additions and 51 deletions

View file

@ -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,
)
}
}

View file

@ -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)
}
}

View file

@ -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 = {})
}

View file

@ -55,7 +55,7 @@ internal class DetailsRouter @Inject constructor(
TODO("This class will be removed in future")
}
override fun clear(onComplete: (isSuccess: Boolean) -> Unit) {
override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) {
TODO("This class will be removed in future")
}
}

View file

@ -3,6 +3,7 @@ package com.tangem.features.details.component.preview
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.tangem.core.decompose.navigation.DummyRouter
import com.tangem.features.details.component.DetailsComponent
import com.tangem.features.details.entity.DetailsFooterUM
import com.tangem.features.details.entity.DetailsUM
@ -17,12 +18,12 @@ internal class PreviewDetailsComponent : DetailsComponent {
private val previewBlocks = runBlocking {
ItemsBuilder(
router = PreviewRouter(),
router = DummyRouter(),
).buldAll(isWalletConnectAvailable = true)
}
private val previewFooter = DetailsFooterUM(
socials = SocialsBuilder(PreviewRouter()).buildAll(),
socials = SocialsBuilder(DummyRouter()).buildAll(),
appVersion = "1.0.0-preview",
)

View file

@ -1,27 +0,0 @@
package com.tangem.features.details.component.preview
import com.tangem.core.decompose.navigation.Route
import com.tangem.core.decompose.navigation.Router
import kotlin.reflect.KClass
internal class PreviewRouter : Router {
override fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
/* no-op */
}
override fun pop(onComplete: (isSuccess: Boolean) -> Unit) {
/* no-op */
}
override fun popTo(routeClass: KClass<out Route>, onComplete: (isSuccess: Boolean) -> Unit) {
/* no-op */
}
override fun popTo(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
/* no-op */
}
override fun clear(onComplete: (isSuccess: Boolean) -> Unit) {
/* no-op */
}
}