accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Idea] Pager keys

Open natario1 opened this issue 5 years ago • 7 comments

Is your feature request related to a problem? Please describe. Seeing some issues with VerticalPager when the backing dataset is frequently updated with changes in order. Think of a list of chats, where you always sort them by the lastMessageDate.

Describe the solution you'd like Besides some weird glitches when scrolling, which I'm investigating - will try to get back with repro instructions - I think it would be very helpful for us if we could use a key() with the chat ID. Accompanist currently uses the page index I think which is causing unnecessary invalidations during such order changes.

From my understanding, a big improvement for this use case would be having an API to override the default key() and reuse composables efficiently.

natario1 avatar Jul 16 '21 17:07 natario1

Could this be the same problem that I described? https://github.com/google/accompanist/issues/524

mariobat88 avatar Jul 20 '21 11:07 mariobat88

Thanks for the report!

Could this be the same problem that I described? #524

Yeah, could very well be!

chrisbanes avatar Jul 20 '21 11:07 chrisbanes

Also in my case with the timer, I am passing the intentChannel from my ViewModel into my pages, which for some reason causes recomposition every time my timer emits (every 100 millis). For testing purposes I tried removing the intentChannel and just hardcoded the Channel() into every page like this:

when (page) {
  0 -> {
Page(
       stringResource(R.string.my_text_0),
       Channel()
       )
 }
1 -> {
Page(
       stringResource(R.string.my_text_1),
       Channel()
       )
}

That doesn't trigger the recomposition every 100 millis for some reason.

mariobat88 avatar Jul 20 '21 12:07 mariobat88

FWIW I'm not using anything fancy, not even scroll APIs, just finger scrolling and dataset reorderings. This ticket was more of a feature request for keys to track composables.

natario1 avatar Jul 21 '21 10:07 natario1

Yep, the problem is that providing a key won't necessarily fix the problem. The key() function is mostly used as a way to increase skipping and reduce composition.

I think this may be the point where we need to think about moving the implementation of Pager to be based on LazyRow, as adding key support is basically going to copy over a load of what we did there. That's not a small task though.

chrisbanes avatar Jul 21 '21 11:07 chrisbanes

That is one of the problems I have, the inability to properly remember things like remember(chatID) { expensiveStuff() }. Maybe I can hack this downstream with a Map<String, @Composable (Chat) -> Unit>, not sure. Also not sure whether this would fix scroll glitches, but I'm curious to try. Looking forward for a LazyRow based implementation!

natario1 avatar Jul 21 '21 12:07 natario1

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 21 '21 03:08 github-actions[bot]