Hey, composers! I have a question about composable...
# compose
y
Hey, composers! I have a question about composable items reusability in
LazyColumn
/
LazyRow
. Basically, are underlying views in view hierarchy are ever reused for new views while scrolling? Or do they always created from scratch?
RecyclerView
created (
onCreateViewHolder
) views only for those which are on the first screen and reused them (
onBindViewHolder
) when scrolling.
I've done a quick investigation of the
LazyList
source code, but there I was able to find only the visible views calculations, which need to be displayed. But no hints on reusability of already allocated views.
b
My guess is no. Compose does not use views (even at a low level), or even anything that is conceptually similar. That’s part of what makes it so efficient. It draws content directly on the screen. So, for Lazy* composables, there is nothing to “reuse”. Instead, as the user scrolls, the list is re-composed, and it figures out which `item {}`’s should be rendered and it measures and places (renders) those items. I haven’t looked closely at the code myself, but that’s my understanding of how the
Lazy*
composables work.
1
a
Actually there is some kind of reuse. Not "view" though. See this.
👍 1
🙌 1
b
ah interesting
c
I think originally there was no reuse, and then the reuse was added pretty late IIRC.
but yeah, there were a few really good threads/reads here from Andrey.