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

Remember views across reconstructions #11

@y9vad9

Description

@y9vad9

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions