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

alexzhukovich

02/27/2020, 10:07 PM
Hello! I'm trying to add background image for card in a list and card has a favourite toggle. When favourite state changing the composable function re-drawing the card and background re-drawing again. Is it possible to avoid re-drawing background image every time?
l

Leland Richardson [G]

02/27/2020, 10:19 PM
how are you drawing the image?
a

alexzhukovich

02/27/2020, 10:30 PM
I tried to use DrawImage
Copy code
loadImageResource(imageResId).resource.resource?.let {
    DrawImage(image = it)
}
or
Copy code
DrawImage(imageResource(imageResId))
a

Andrey Kulikov

02/28/2020, 12:02 PM
to add draw caches you need to wrap Image into RepaintBoundary. this basically first draws Image into RenderNode and then reuses this rendernode
a

alexzhukovich

02/28/2020, 7:58 PM
Thank you for your answer, it was my fault I used ModelList with immutable data and created copy of object when pressed favourite button
2 Views