Hi, is it possible to remove the ripple-effect?
# compose-android
j
Hi, is it possible to remove the ripple-effect?
I tried using a custom theme:
Copy code
@Composable
fun CustomTheme(
    darkTheme: Boolean = false/*isSystemInDarkTheme()*/,
    content: @Composable () -> Unit
) {
    val customColors = if (darkTheme) DarkColorPalette else LightColorPalette
    CompositionLocalProvider(
        LocalCustomColors provides customColors,
        LocalRippleTheme provides NoRippleTheme,
        content = content
    )
}

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

    @Composable
    override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0F, 0.0F, 0.0f, 0.0F)
}
It seems that my App is using the NoRippleTheme correctly, because when I change the defaultColor to red is kinda red. Unfortunately the ripple is still there (grey) if I set defaultColor to Unspecified/Transparent. I am using this with a Button.
ł
try this:
Copy code
CompositionLocalProvider(
   LocalIndication provides NoRipple,
   ...
   content = content,
)

private object NoRipple : Indication, IndicationInstance {
    @Composable
    override fun rememberUpdatedInstance(interactionSource: InteractionSource) = this
    override fun ContentDrawScope.drawIndication() = drawContent()
}
j
Hm ... not working. Maybe its compose-multiplatfor related?
ł
Interesting just now I checked and it works on both versions ( multiplatform, android ). I use it:
Copy code
@Composable
fun CustomTheme(
    darkTheme: Boolean = false/*isSystemInDarkTheme()*/,
    content: @Composable () -> Unit
) {
    val customColors = if (darkTheme) DarkColorPalette else LightColorPalette
    CompositionLocalProvider(
        LocalIndication provides NoRipple,
        content = content
    )
}

private object NoRipple : Indication, IndicationInstance {
    @Composable
    override fun rememberUpdatedInstance(interactionSource: InteractionSource) = this
    override fun ContentDrawScope.drawIndication() = drawContent()
}
j
Hm … will check later and let you know. Thanks for help
Hi @Łukasz Nowakowski I am using this template https://github.com/JetBrains/compose-multiplatform-ios-android-template
and I changed the App file like this:
Copy code
@OptIn(ExperimentalResourceApi::class)
@Composable
fun App() {
    //MaterialTheme {
        CompositionLocalProvider(LocalIndication provides NoRipple) {
            var greetingText by remember { mutableStateOf("Hello, World!") }
            var showImage by remember { mutableStateOf(false) }
            Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
                Button(onClick = {
                    greetingText = "Hello, ${getPlatformName()}"
                    showImage = !showImage
                }) {
                    Text(greetingText)
                }
                AnimatedVisibility(showImage) {
                    Image(
                        painterResource("compose-multiplatform.xml"),
                        null
                    )
                }
            }
        }
    //}
}

object NoRipple : Indication, IndicationInstance {
    @Composable
    override fun rememberUpdatedInstance(interactionSource: InteractionSource) = this
    override fun ContentDrawScope.drawIndication() = drawContent()
}
on the Button there is still a Ripple effect
image.png
rememberRipple of Material-Surface seems to be the problem
God! Its a Bug with Android 13 ApiLevel 33
They want me to go crazy ...
330 Views