Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant