7

LazyColumn and LazyRow are replacing for RecyclerView in the old UI but when scrolling the item in RecyclerView and back to it disappear then recycle to optimization UI.

LazyColumn and LazyRow are doing the same thing?

Hamdy Abd El Fattah
  • 1,405
  • 1
  • 16
  • 16

2 Answers2

0

I found it from Jetpack Compose basics Codelab

Note: LazyColumn doesn't recycle its children like RecyclerView. It emits new Composables as you scroll through it and is still performant, as emitting Composables is relatively cheap compared to instantiating Android Views

After testing, I see that LazyColumn just compose visible items. And, by scrolling the invisible items will recompose when it visible again.

Linh
  • 57,942
  • 23
  • 262
  • 279
0

LazyColumn uses LazyList which uses LazyLayout and it uses aSubComposeLayout to recompose children Composable when required unlike having a Column with Modifier.verticalScroll() which composes all of its children Composables.

Subcomposable has a subocompose function that can be called multiple times in the layout block. This is, for example, what happens in LazyRow. The slotId allows SubcomposeLayout to track and manage the compositions created by calling subcompose. For example, if you are generating the content from an array you might want use the index of the array as its slotId allowing SubcomposeLayout to determine which subcompose generated last time should be used to during recomposition. Also, if a slotid is not used any more, SubcomposeLayout will dispose its corresponding composition.

You can read full answer about SubcomposeLayout by Google developer here.

Thracian
  • 43,021
  • 16
  • 133
  • 222