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 399 times
0
Linh
- 51,033
- 19
- 228
- 256
-
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) – Pylyp Dukhov Jan 05 '22 at 10:28
-
@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. – Pylyp 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). – Pylyp Dukhov Jan 06 '22 at 03:37
1 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
- 106
- 1
- 5
-
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
-