https://kotlinlang.org logo
#compose
Title
# compose
y

Yev Kanivets

01/05/2022, 2:16 PM
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

Bradleycorn

01/05/2022, 3:43 PM
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

Albert Chang

01/05/2022, 6:15 PM
Actually there is some kind of reuse. Not "view" though. See this.
👍 1
🙌 1
b

Bradleycorn

01/05/2022, 7:21 PM
ah interesting
c

Colton Idle

01/06/2022, 3:14 AM
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.