[Idea] Pager keys
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.
Could this be the same problem that I described? https://github.com/google/accompanist/issues/524
Thanks for the report!
Could this be the same problem that I described? #524
Yeah, could very well be!
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.
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.
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.
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!
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.