I found that in my composable is recomposing every...
# compose
z
I found that in my composable is recomposing every time the
hue
,
saturation
, or
value
params change. But if their type to a lambda producing a float,
() -> Float
, there's no recomposing and its skipped. I'm curious why this works and if it's good to do this change.
Copy code
@Composable
public fun RingColorPicker(
    hue: Float,
    saturation: Float = 1f,
    value: Float = 1f,
    onHueChange: (Float) -> Unit,
    modifier: Modifier = Modifier,
    interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
    ringStrokeWidth: Dp = 16.dp,
    thumb: @Composable () -> Unit = {
        ColorPickerDefaults.Thumb(Color.hsv(hue, saturation, value), interactionSource)
    },
    onColorChangeFinished: () -> Unit = {}
)
s
Could you provide example of how it is used?
z
Do you mean the function itself? Like this
Copy code
var hue by remember { mutableStateOf(90f) }

RingColorPicker(
    hue = { hue },
    onHueChange = { hue = it }
)
s
that explains it, if you only read hue in draw, the state read is likely not recorded in composition