简体   繁体   中英

Checkbox Composable Won't Disable Animation - Android Jetpack Compose

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,
                )

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM