This repository was archived by the owner on Jan 4, 2025. It is now read-only.
generated from y9vad9/kotlin-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Remember views across reconstructions #11
Copy link
Copy link
Open
Description
Problem
Currently, any change to State<T> causes the reconstruction that removes all views and readds it to view.
Solution
I propose next variant with wrapping view adding feature and comparing views ids on each reconstruction:
remember(ids = 1, ...) {
// this state is used for updating data of recyclerview that was created before
// data update.
val items = State<List<Account>>(emptyList())
state.constructOnEach { state ->
if(state is FooVM.State.Failure) {
...
} else {
// we set data to update old recycler view or for new, if it's first construction with recycler
items.value = state.accounts
recyclerView(id = 1, adapter = FooAdapter(), data = items)
}
}
}*It requires custom realization of recycler view that has items (data) as state value
For this kind of realization, we should have custom StatedViewGroup to be able to compare new and old trees.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request