Chris Pi
Chris Pi

Reputation: 612

Clickable function of composable does not work anymore

So these are my Project Versions:

    val compose_version by extra("1.0.0-beta07")
    val kotlin_version by extra("1.4.32")
    val hilt_version by extra("2.36")

So I have a LazyColum which displays a custom composable card list:

package com.veloce.montageservice.ui.composables

// Here are imports but its too much code for stackoverflow

@Composable
fun SimpleCard(
    imageVector: ImageVector,
    title: String,
    description: String,
    @DrawableRes trailingButton: Int? = null,
    clickable: () -> Unit
) {
    Card(
        modifier = Modifier
            .padding(8.dp)
            .fillMaxWidth()
            .clickable {
                clickable()
            },
        border = BorderStroke(
            (0.5).dp,
            brush = Brush.horizontalGradient(
                colors = listOf(
                    MaterialTheme.colors.primary, MaterialTheme.colors.primaryVariant
                )
            )
        ),
        elevation = 5.dp
//        backgroundColor = Color.Gray
    ) {
        Row(
            modifier = Modifier.padding(8.dp),
            horizontalArrangement = if (trailingButton != null) Arrangement.SpaceEvenly else Arrangement.Start
        ) {
            Surface(
                shape = CircleShape,
                modifier = Modifier.size(50.dp),
                color = MaterialTheme.colors.primaryVariant
            ) {
                Icon(
                    modifier = Modifier.padding(4.dp),
                    imageVector = imageVector,
                    contentDescription = "Icon of a building",
                    tint = Color.White
                )
            }
            Column(
                modifier = Modifier.padding(8.dp),
                verticalArrangement = Arrangement.SpaceEvenly
            ) {
                Text(
                    title,
                    fontWeight = FontWeight.Bold
                )
                Text(description)
            }
            trailingButton?.let {
                Surface(
                    shape = CircleShape,
                    modifier = Modifier.size(35.dp),
                    color = MaterialTheme.colors.primaryVariant
                ) {
                    Icon(
                        modifier = Modifier.padding(4.dp),
                        imageVector = ImageVector.vectorResource(id = it),
                        contentDescription = "Icon of a building",
                        tint = Color.White
                    )
                }
            }
        }
    }
}

And this should be clickable. It was, but now it's not anymore and I didn't have changed anything in this composable. Has anyone an idea what went wrong? The scroll function of LazyColumnworks perfectly fine, it's just that I can't click it anymore from one day to the other.

Upvotes: 0

Views: 801

Answers (1)

jns
jns

Reputation: 6952

In compose 1.0.0-beta08 there was a breaking API Change (https://developer.android.com/jetpack/androidx/releases/compose-material) which causes the clickable modifier to be ignored. You have to use the onClickparameter of Card instead:

Card(onClick = { count++ }) {
    Text("Clickable card content with count: $count")
}

Upvotes: 4

Related Questions