With RecyclerView
, I can make some ViewHolder
not recyclable (follow some answers in
I want my RecyclerView to not recycle some items).
Can I make LazyColumn
to not recompose some items (similar to make RecyclerView
don't recycle some ViewHolder
)? I have few items in LazyColumn
with some big images, it recompose after scrolling down and up so scroll is not smooth.
Asked
Active
Viewed 1,667 times
2

Linh
- 57,942
- 23
- 262
- 279
-
it doesn't recompose unless you've done something wrong. Check out [this example](https://gist.github.com/PhilipDukhov/63317e2f3a2572226171f5c9a544ce99), logs firing only once for each cell when it appears, no recomposition happens during scrolling(expect new appearing cells) – Phil Dukhov Jan 05 '22 at 10:28
-
1@PhilipDukhov I tried you example but it recompose after I scroll to bottom then scroll up to the top. – Linh Jan 05 '22 at 11:40
-
It's a lazy list and for sure it should recompose when the cell disappears and then appears again. While not on then screen the lazy view is removed from the view tree, and needs to be composed when appears again. – Phil Dukhov Jan 05 '22 at 11:46
-
@PhilipDukhov yes, I agree with you but my question is different. `LazyColumn` solve the same problem like `RecyclerView`. You can check again this link https://stackoverflow.com/questions/36313079/i-want-my-recyclerview-to-not-recycle-some-items. In some case, we still want to make some item in RecyclerView to not recycle (eg: the item contains large image, canvas, or video). RecyclerView support this and I'm migrate from RecyclerView to LazyColumn – Linh Jan 06 '22 at 03:26
-
1I get it now, didn't notice that link, my bad. As far as I know, there is no way to do this with `LazyColumn`, I suggest you [create a feature request](https://issuetracker.google.com/issues/new?component=612128). – Phil Dukhov Jan 06 '22 at 03:37
2 Answers
0
I met the same problem and use Column instead with a modifier vertical scroll. If you don't want it recycle view, just load all ( few items)
Column(
modifier = Modifier
.constrainAs(listView) {
top.linkTo(
parent.top
)
}
.fillMaxSize()
.verticalScroll(rememberScrollState())
) {
list.forEachIndexed { index, itemModel ->
ItemView(itemModel, index) {
// on item click
}
}
Spacer(modifier = Modifier.height(40.dp))
}

Anh Luu
- 176
- 1
- 7
-
Use `Column` instead of `LazyColumn` could help. Unfortunately, I need `LazyColumn` to support drag and drop item in list so I can not use `Column` – Linh Jan 05 '22 at 09:18
-
[link](https://github.com/aclassen/ComposeReorderable) did u try this one? – Anh Luu Jan 05 '22 at 09:41
-
0
I had a similar issue with a composable that is heavily manipulating bitmaps and then draw them on a canvas. You noticed that processing while scrolling the lazyColumn up and down.
To face this issue a stored my manipulated bitmaps in a List<ImageBitmap>
as rememberSaveable
val rememberFruits by rememberSaveable(images) {
mutableStateOf(doBitmapOperations(images))
}
Canvas(
modifier = Modifier
.fillMaxWidth()
.height(height)
.constrainAs(circle) {}
) {
rememberFruits
.forEach { createScaledImageBitmap ->
val (image, offset) = createScaledImageBitmap
drawImage(
image = image,
topLeft = offset
)
}
}
My item in the lazyColumn was still recomposed but the heavy bitmap operations were no more executed while scrolling and making scrolling up and down smooth.
hope it helps!

Alexander Knauf
- 101
- 9