简体   繁体   English

复选框组合不会禁用 Animation - Android Jetpack Compose

[英]Checkbox Composable Won't Disable Animation - Android Jetpack Compose

Is there a way to disable the indication animation on the Composable Checkbox?有没有办法禁用可组合复选框上的指示 animation?

The typical path of adding the indication = null parameter to the .clickable Modifier doesn't appear to work.indication = null参数添加到.clickable修饰符的典型路径似乎不起作用。

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.它不起作用,因为Checkbox在实现中定义了自定义indication
You can provide a custom LocalRippleTheme to override the default behaviour.您可以提供自定义LocalRippleTheme来覆盖默认行为。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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