https://kotlinlang.org logo
a

Adriano Celentano

12/08/2019, 1:50 PM
I wanted to checkout how to draw to the canvas, but i wasnt sure where to keep my instances of Paint, which i want to reuse and not recreate on each onDraw(). I saw in the framework code this memo() function, which seems to serve this purpose. Unfortunately i didnt get it. Someone already understood how its working ?
Copy code
```with(+memo { DrawShapeCacheHolder() }) {
    lastShape = shape
    Draw { canvas, parentSize ->
...
}
m

mzgreen

12/08/2019, 2:17 PM
I recommend you to watch Leland Richardson’s talk from AndroidDevSummit 2019 or better the one from KotlinConf 2019.
1
👍 1
l

Luca Nicoletti

12/08/2019, 3:23 PM
Just outside of the draw, setup a paint
val paint = +memo { Paint() }
1
a

Adam Powell

12/08/2019, 6:23 PM
We're looking at automating a lot of the paint management, for now, yes, just memo one and modify as needed before use
3 Views