Home > Software design >  Checkbox Composable Won't Disable Animation - Android Jetpack Compose
Checkbox Composable Won't Disable Animation - Android Jetpack Compose

Time:03-10

Is there a way to disable the indication animation on the Composable Checkbox?

The typical path of adding the indication = null parameter to the .clickable Modifier doesn't appear to work.

When I looked in the documentation it just directed me to the different modifiers.

Checkbox Composable Documentation

                Checkbox(
                    checked = checkedState.value,
                    onCheckedChange = {vm.HandleListItemClick(optionItems, i, checkedState)},
                    modifier = Modifier
                        .clickable(
                            interactionSource = interactionSource,
                            indication = null,
                            enabled = true,
                            onClickLabel = "${optionItems[i].label} checkbox selected status is ${checkedState.value}",
                            role = null,
                        ){},
                    enabled = true,
                )

CodePudding user response:

It doesn't work since the Checkbox defines a custom indication inside the implementation.
You can provide a custom LocalRippleTheme to override the default behaviour.

Something like:

CompositionLocalProvider(LocalRippleTheme provides NoRippleTheme) {
    val checkedState = remember { mutableStateOf(true) }
    Checkbox(
        checked = checkedState.value,
        onCheckedChange = { checkedState.value = it }
    )
}

private object NoRippleTheme : RippleTheme {
    @Composable
    override fun defaultColor() = Color.Unspecified

    @Composable
    override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f,0.0f,0.0f,0.0f)
}
  • Related