Updated on 2026-08-14
This commit is contained in:
parent
3d16de3f4f
commit
d65b4039da
15 changed files with 26 additions and 945 deletions
|
|
@ -3,22 +3,13 @@ package com.tangem.tap.routing.component
|
|||
import android.content.Intent
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.arkivanov.decompose.router.stack.ChildStack
|
||||
import com.arkivanov.decompose.value.Value
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
import com.tangem.core.decompose.navigation.Router
|
||||
import com.tangem.core.ui.decompose.ComposableContentComponent
|
||||
import com.tangem.utils.Provider
|
||||
|
||||
internal interface RoutingComponent : ComposableContentComponent {
|
||||
|
||||
// TODO: Remove after full navigation refactoring
|
||||
val router: Router
|
||||
|
||||
// TODO: Remove after full navigation refactoring
|
||||
val stack: Value<ChildStack<AppRoute, Child>>
|
||||
|
||||
@Immutable
|
||||
sealed class Child {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
package com.tangem.tap.routing.component.impl
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import com.arkivanov.decompose.ComponentContext
|
||||
import com.arkivanov.decompose.router.stack.ChildStack
|
||||
import com.arkivanov.decompose.router.stack.childStack
|
||||
import com.arkivanov.decompose.value.Value
|
||||
import com.arkivanov.decompose.value.subscribe
|
||||
import com.arkivanov.essenty.lifecycle.doOnDestroy
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
|
|
@ -23,7 +20,6 @@ import com.tangem.tap.routing.RootContent
|
|||
import com.tangem.tap.routing.component.RoutingComponent
|
||||
import com.tangem.tap.routing.component.RoutingComponent.Child
|
||||
import com.tangem.tap.routing.configurator.AppRouterConfig
|
||||
import com.tangem.tap.routing.toggle.RoutingFeatureToggles
|
||||
import com.tangem.tap.routing.utils.ChildFactory
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
|
|
@ -36,35 +32,30 @@ internal class DefaultRoutingComponent @AssistedInject constructor(
|
|||
private val childFactory: ChildFactory,
|
||||
private val appRouterConfig: AppRouterConfig,
|
||||
private val uiDependencies: UiDependencies,
|
||||
routingFeatureToggles: RoutingFeatureToggles,
|
||||
) : RoutingComponent,
|
||||
AppComponentContext by context,
|
||||
SnackbarHandler {
|
||||
|
||||
override val stack: Value<ChildStack<AppRoute, Child>> = childStack(
|
||||
private val stack: Value<ChildStack<AppRoute, Child>> = childStack(
|
||||
source = navigationProvider.getOrCreateTyped(),
|
||||
initialStack = { getInitialStackOrInit() },
|
||||
serializer = null, // AppRoute.serializer(), // Disabled until Nav refactoring completes
|
||||
handleBackButton = routingFeatureToggles.isNavigationRefactoringEnabled,
|
||||
childFactory = ::child,
|
||||
handleBackButton = true,
|
||||
childFactory = { route, childContext ->
|
||||
childFactory.createChild(route, childByContext(childContext))
|
||||
},
|
||||
)
|
||||
|
||||
init {
|
||||
lifecycle.doOnDestroy {
|
||||
childFactory.doOnDestroy()
|
||||
}
|
||||
appRouterConfig.routerScope = componentScope
|
||||
appRouterConfig.componentRouter = router
|
||||
appRouterConfig.snackbarHandler = this
|
||||
|
||||
if (routingFeatureToggles.isNavigationRefactoringEnabled) {
|
||||
appRouterConfig.routerScope = componentScope
|
||||
appRouterConfig.componentRouter = router
|
||||
appRouterConfig.snackbarHandler = this
|
||||
stack.subscribe(lifecycle) { stack ->
|
||||
val stackItems = stack.items.map { it.configuration }
|
||||
|
||||
stack.subscribe(lifecycle) { stack ->
|
||||
val stackItems = stack.items.map { it.configuration }
|
||||
|
||||
if (appRouterConfig.stack != stackItems) {
|
||||
appRouterConfig.stack = stackItems
|
||||
}
|
||||
if (appRouterConfig.stack != stackItems) {
|
||||
appRouterConfig.stack = stackItems
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -114,10 +105,6 @@ internal class DefaultRoutingComponent @AssistedInject constructor(
|
|||
initialStack
|
||||
}
|
||||
|
||||
private fun child(route: AppRoute, context: ComponentContext): Child {
|
||||
return childFactory.createChild(route) { childByContext(context) }
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : RoutingComponent.Factory {
|
||||
override fun create(context: AppComponentContext, initialStack: List<AppRoute>?): DefaultRoutingComponent
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue