I am studying Arkady Ivanov’s Decompose library, but when changing the counter and changing the screen, the counter does not save its value and is reset to zero.
Interface of Component
interface SecondComponent {
val model: Value<Model>
fun onIncrementClicked()
fun onDecrementClicked()
fun onBackClicked()
data class Model(
val count: Int = 0
)
}
Interface implementation
class DefaultSecondComponent(
private val componentContext: ComponentContext,
private val onBack: () -> Unit,
): SecondComponent, ComponentContext by componentContext{
private val state = MutableValue(Model())
override val model: Value<Model> = state
override fun onIncrementClicked() {
state.update { it.copy(count = it.count + 1)}
}
override fun onDecrementClicked() {
state.update { it.copy(count = it.count - 1) }
}
override fun onBackClicked() {
onBack()
}
}
Creating navigation via ChildStack
private fun secondComponent(component: ComponentContext):
SecondComponent =
DefaultSecondComponent(
componentContext = component,
onBack = navigation::pop
)
I tried changing the lambda expression to update the variable
New contributor
xlzpm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.