Updated on 2026-08-14
This commit is contained in:
parent
b8fc2d4f76
commit
283e760a4b
15 changed files with 68 additions and 6 deletions
|
|
@ -40,6 +40,12 @@ internal class ProxyAppRouter(
|
|||
}
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: AppRoute, onComplete: (Boolean) -> Unit) {
|
||||
safeNavigate(onComplete, message = "Replace a current route with $route") {
|
||||
innerRouter.replaceCurrent(route, onComplete)
|
||||
}
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: AppRoute, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
safeNavigate(onComplete, message = "Replace all routes with $routes") {
|
||||
runCatching {
|
||||
|
|
|
|||
|
|
@ -562,6 +562,7 @@ internal class ChildFactory @Inject constructor(
|
|||
params = CreateWalletBackupComponent.Params(
|
||||
userWalletId = route.userWalletId,
|
||||
isUpgradeFlow = route.isUpgradeFlow,
|
||||
setAccessCode = route.setAccessCode,
|
||||
),
|
||||
componentFactory = createWalletBackupComponentFactory,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -364,7 +364,8 @@ sealed class AppRoute(val path: String) : Route {
|
|||
@Serializable
|
||||
data class CreateWalletBackup(
|
||||
val userWalletId: UserWalletId,
|
||||
val isUpgradeFlow: Boolean,
|
||||
val isUpgradeFlow: Boolean = false,
|
||||
val setAccessCode: Boolean = false,
|
||||
) : AppRoute(path = "/create_wallet_backup/${userWalletId.stringValue}")
|
||||
|
||||
@Serializable
|
||||
|
|
|
|||
|
|
@ -30,6 +30,19 @@ interface AppRouter {
|
|||
},
|
||||
)
|
||||
|
||||
/**
|
||||
* Replaces a current route with a new one.
|
||||
*
|
||||
* @param route The route to replace a current one.
|
||||
* @param onComplete The callback to be invoked when the operation is complete.
|
||||
*/
|
||||
fun replaceCurrent(
|
||||
route: AppRoute,
|
||||
onComplete: (isSuccess: Boolean) -> Unit = { isSuccess ->
|
||||
defaultCompletionHandler(isSuccess, errorMessage = "Unable to replace a current route with $route")
|
||||
},
|
||||
)
|
||||
|
||||
/**
|
||||
* Replaces ***all*** routes in the navigation stack with the specified [routes].
|
||||
*
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ private class RouterProxy(
|
|||
}
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: Route, onComplete: (Boolean) -> Unit) {
|
||||
if (route is AppRoute) {
|
||||
appRouter.replaceCurrent(route, onComplete)
|
||||
}
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
routes.filterIsInstance<AppRoute>().let {
|
||||
appRouter.replaceAll(*it.toTypedArray(), onComplete = onComplete)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.tangem.core.decompose.navigation
|
||||
|
||||
import com.arkivanov.decompose.ExperimentalDecomposeApi
|
||||
import com.arkivanov.decompose.router.stack.StackNavigation
|
||||
import com.arkivanov.decompose.router.stack.pop
|
||||
import com.arkivanov.decompose.router.stack.pushNew
|
||||
import com.arkivanov.decompose.router.stack.replaceCurrent
|
||||
import com.arkivanov.essenty.instancekeeper.InstanceKeeper
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
|
@ -14,11 +14,14 @@ internal class DefaultRouter(
|
|||
private val navigation: StackNavigation<Route>
|
||||
get() = navigationProvider.getOrCreate()
|
||||
|
||||
@OptIn(ExperimentalDecomposeApi::class)
|
||||
override fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
navigation.pushNew(route, onComplete)
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: Route, onComplete: (Boolean) -> Unit) {
|
||||
navigation.replaceCurrent(route, { onComplete(true) })
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
val newRoutes = routes.toList()
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ class DummyRouter : Router {
|
|||
onComplete(true)
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: Route, onComplete: (Boolean) -> Unit) {
|
||||
onComplete(true)
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (isSuccess: Boolean) -> Unit) {
|
||||
onComplete(true)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,14 @@ interface Router {
|
|||
*/
|
||||
fun push(route: Route, onComplete: (isSuccess: Boolean) -> Unit = {})
|
||||
|
||||
/**
|
||||
* Replaces a current route with a new one.
|
||||
*
|
||||
* @param route The route to replace a current one.
|
||||
* @param onComplete The callback to be invoked when the operation is complete.
|
||||
*/
|
||||
fun replaceCurrent(route: Route, onComplete: (isSuccess: Boolean) -> Unit = {})
|
||||
|
||||
/**
|
||||
* Replaces ***all*** routes in the navigation stack with the specified [routes].
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ inline fun AppComponentContext.InnerPopRouter(
|
|||
router.push(route, onComplete)
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: Route, onComplete: (Boolean) -> Unit) {
|
||||
router.replaceCurrent(route, onComplete)
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (Boolean) -> Unit) {
|
||||
router.replaceAll(*routes, onComplete = onComplete)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.tangem.core.decompose.navigation.inner
|
|||
import com.arkivanov.decompose.router.stack.StackNavigation
|
||||
import com.arkivanov.decompose.router.stack.pop
|
||||
import com.arkivanov.decompose.router.stack.pushNew
|
||||
import com.arkivanov.decompose.router.stack.replaceCurrent
|
||||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
import com.tangem.core.decompose.navigation.Route
|
||||
import com.tangem.core.decompose.navigation.Router
|
||||
|
|
@ -32,6 +33,14 @@ inline fun <reified T : Route> AppComponentContext.InnerRouter(
|
|||
}
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: Route, onComplete: (Boolean) -> Unit) {
|
||||
if (route is T) {
|
||||
stackNavigation.replaceCurrent(route, { onComplete(true) })
|
||||
} else {
|
||||
fallBackRouter.replaceCurrent(route, onComplete)
|
||||
}
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (Boolean) -> Unit) {
|
||||
if (routes.any { it is T }) {
|
||||
val newRoutes = routes.toList().filterIsInstance<T>()
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ interface CreateWalletBackupComponent : ComposableContentComponent {
|
|||
data class Params(
|
||||
val userWalletId: UserWalletId,
|
||||
val isUpgradeFlow: Boolean,
|
||||
val setAccessCode: Boolean,
|
||||
)
|
||||
|
||||
interface Factory : ComponentFactory<Params, CreateWalletBackupComponent>
|
||||
|
|
|
|||
|
|
@ -71,7 +71,11 @@ internal class CreateWalletBackupModel @Inject constructor(
|
|||
}
|
||||
|
||||
fun onManualBackupCompleted() {
|
||||
router.pop()
|
||||
if (params.setAccessCode) {
|
||||
router.replaceCurrent(AppRoute.UpdateAccessCode(userWalletId = params.userWalletId))
|
||||
} else {
|
||||
router.pop()
|
||||
}
|
||||
}
|
||||
|
||||
inner class ManualBackupStartModelCallbacks : ManualBackupStartComponent.ModelCallbacks {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ internal class WalletBackupModel @Inject constructor(
|
|||
router.push(
|
||||
AppRoute.CreateWalletBackup(
|
||||
userWalletId = params.userWalletId,
|
||||
isUpgradeFlow = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -525,7 +525,6 @@ internal class WalletSettingsModel @Inject constructor(
|
|||
router.push(
|
||||
AppRoute.CreateWalletBackup(
|
||||
userWalletId = userWallet.walletId,
|
||||
isUpgradeFlow = false,
|
||||
),
|
||||
)
|
||||
closeBs()
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ internal class WcRouter(
|
|||
onComplete(isComplete)
|
||||
}
|
||||
|
||||
override fun replaceCurrent(route: Route, onComplete: (Boolean) -> Unit) {
|
||||
/** Not allowed */
|
||||
}
|
||||
|
||||
override fun replaceAll(vararg routes: Route, onComplete: (Boolean) -> Unit) {
|
||||
/** Not allowed */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue