Is this bad practice? ```val (currentSize, setCur...
# compose
y
Is this bad practice?
Copy code
val (currentSize, setCurrentSize) = remember { mutableStateOf(Size.Zero) }
val matrix = remember(currentSize) {
    Matrix().apply {
        setRectToRect(
            box,
            RectF(0f, 0f, currentSize.width, currentSize.height),
            Matrix.ScaleToFit.CENTER
        )
    }
}

remember(matrix) { // heavy work }

Canvas(modifier = Modifier.fillMaxSize()) {
    setCurrentSize(size)
	
	// Do some drawing ...
}
I didn't find any alternative to retrieve the size and be able to
remember
some result with it as a key 🤔
s
In the codelabs about layout Modifier.layout is explained to get children size.
n
In this case you would want to remember the matrix and conditionally update the computation within the DrawScope receiver scope within the Canvas composable only when the size changes
y
How would you check that the size changed? You'd need to remember the size right? So the only difference would be that the computation would be inside the DrawScope instead of in the matrix creation lambda 🤔
n
You can create a wrapper object that keeps track of both the size and the matrix and remember that. Then within the DrawScope callback you can compare/update the size parameter and matrix computations
y
Indeed, thanks for the help