简体   繁体   English

LazyColumn 不重新组合某些项目

[英]LazyColumn to not recompose some items

With RecyclerView , I can make some ViewHolder not recyclable (follow some answers in I want my RecyclerView to not recycle some items ).使用RecyclerView ,我可以使某些ViewHolder不可回收(按照我希望我的 RecyclerView 不回收某些项目中的一些答案)。
Can I make LazyColumn to not recompose some items (similar to make RecyclerView don't recycle some ViewHolder )?我可以让LazyColumn不重新组合某些项目(类似于让RecyclerView不回收某些ViewHolder )吗? I have few items in LazyColumn with some big images, it recompose after scrolling down and up so scroll is not smooth.我在LazyColumn中有一些带有一些大图像的项目,它在向下和向上滚动后重新组合,因此滚动不流畅。

I met the same problem and use Column instead with a modifier vertical scroll.我遇到了同样的问题,并使用 Column 来代替修饰符垂直滚动。 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))
        }

I had a similar issue with a composable that is heavily manipulating bitmaps and then draw them on a canvas.我有一个类似的问题,一个可组合的大量操作位图,然后在 canvas 上绘制它们。 You noticed that processing while scrolling the lazyColumn up and down.您注意到上下滚动lazyColumn 时的处理。

To face this issue a stored my manipulated bitmaps in a List<ImageBitmap> as rememberSaveable为了解决这个问题,将我操作的位图存储在List<ImageBitmap>作为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.我在lazyColumn 中的项目仍然重新组合,但是在滚动时不再执行繁重的 bitmap 操作,并使上下滚动平滑。

hope it helps!希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM