Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting error on updating 1.2.1 compose version on surface in jetpack compose

I am using compose version 1.1.1 in my project. I am using LocalRippleTheme like this

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Surface
import androidx.compose.material.ripple.LocalRippleTheme
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ClickableItemContainer(
    rippleColor: Color = TealLight,
    content: @Composable (MutableInteractionSource) -> Unit,
    clickAction: () -> Unit
) {
    val interactionSource = remember { MutableInteractionSource() }
    CompositionLocalProvider(
        LocalRippleTheme provides LgcRippleTheme(rippleColor),
        content = {
            Surface(
                onClick = { clickAction() },
                interactionSource = interactionSource,
                indication = rememberRipple(true),
                color = White
            ) {
                content(interactionSource)
            }
        }
    )
}

when I update to compose version to 1.2.1 I am getting weried error message on Surface

Using 'Surface(() -> Unit, Modifier = ..., Shape = ..., Color = ..., Color = ..., BorderStroke? = ..., Dp = ..., MutableInteractionSource = ..., Indication? = ..., Boolean = ..., String? = ..., Role? = ..., () -> Unit): Unit' is an error. This API is deprecated with the introduction a newer Surface function overload that accepts an onClick().

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to remove the indication attribute:

Surface(
    onClick = { clickAction() },
    interactionSource = interactionSource,
    color = White
) {
    content(interactionSource)
}

The M2 1.2.0 deprecated the clickable Surface function with the introduction a newer Surface function that accepts an onClick().

With this API you can’t define the indication that is defined internally by the clickable modifier.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading