How to track compose screens #696
Answered
by
arkivanov
Foenix00001
asked this question in
Q&A
-
Hi, could you please tell me, how I can track jetpack compose screens , using decompose? This is like navController.addOnDestinationChangedListener in google navigation library for logging event "user entered screen XXX". Please, give an idea. |
Beta Was this translation helpful? Give feedback.
Answered by
arkivanov
Apr 22, 2024
Replies: 1 comment 1 reply
-
You can observe navigation state changes as follows: class DefaultRootComponent(
componentContext: ComponentContext,
) : RootComponent, ComponentContext by componentContext {
private val navigation = StackNavigation<Config>()
private val _stack =
childStack(
source = navigation,
serializer = Config.serializer(),
initialStack = ...,
childFactory = ::child,
)
override val stack: Value<ChildStack<*, Child>> = _stack
init {
var lastActiveConfig: Config? = null
_stack.subscribe {
val activeConfig = it.active.configuration
if (activeConfig != lastActiveConfig) {
lastActiveConfig = activeConfig
// Track the active screen here
}
}
} You can also convert |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Foenix00001
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can observe navigation state changes as follows: