Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Remember views across reconstructions #11

Open
y9vad9 opened this issue Dec 19, 2022 · 0 comments
Open

Remember views across reconstructions #11

y9vad9 opened this issue Dec 19, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@y9vad9
Copy link
Owner

y9vad9 commented Dec 19, 2022

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.

@y9vad9 y9vad9 added the enhancement New feature or request label Dec 19, 2022
@y9vad9 y9vad9 added this to the 1.0.0-prototype1 milestone Dec 19, 2022
@y9vad9 y9vad9 self-assigned this Dec 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant