I have a composable that lets the user select a co...
# compose
z
I have a composable that lets the user select a color. My problem is my code does extra calculations when it shouldnt. The cursor position is updated whenever through a pointerInput modifier: (onColorChange is just a callback provided in the function params)
Copy code
detectTapGestures { tapPosition ->
    val newColor = colorForPosition(tapPosition, radius, color.hsvValue)
    if (newColor.isSpecified) {
        offsetX = tapPosition.x
        offsetY = tapPosition.y
        onColorChange(newColor)
    }
}
I have this:
Copy code
var offsetX by rememberSaveable(color) {
    mutableStateOf(positionForColor(color))
}
var offsetY by rememberSaveable(color) {
    mutableStateOf(positionForColor(color))
}
But then whenever my code calls onColorChange with the new color, it calculates the position again, even though the offset variables are already correct. What can I do to optimize this?