adevinta / spark-android

✨ Simple, Modular & Accessible UI Components for your Android Applications
https://adevinta.github.io/spark-android/
MIT License
58 stars 24 forks source link

[Bug]: IconButtonGhost not displayed properly in a ConstraintLayout #773

Closed GoUpNorth closed 8 months ago

GoUpNorth commented 11 months ago

🕵️ Is there an existing issue for this?

What version of spark are you using?

1.0.0

🐛 What happened?

I'm having a hard time using the IconButtonGhost component in a ConstraintLayout, it looks like the constraints are not applied properly to it. I don't have any issue when using a Material3 component or the deprecated Spark IconButton. This code gives the following result.

ConstraintLayout(modifier = Modifier.padding(16.dp)) {
    val (title, button, radioButtons) = createRefs()

    Text(
        text = stringResource(R.string.search_chip_listing_choose_view_label),
        style = SparkTheme.typography.headline2,
        modifier = Modifier.constrainAs(title) {
            centerVerticallyTo(button)
        }
    )

    IconButton(
        onClick = dismiss,
        modifier = Modifier.constrainAs(button) {}
    ) {
        Icon(
            sparkIcon = SparkIcons.Close,
            contentDescription = stringResource(id = R.string.searchtoppanel_close),
            size = IconSize.Medium,
        )
    }
    createHorizontalChain(title, button)
}

And here is the result I get: image

When using it in a constraint layout, the button doesn't seem to respect the constraints. The code gives the following result.

ConstraintLayout(modifier = Modifier.padding(16.dp)) {
    val (title, button, radioButtons) = createRefs()

    Text(
        text = stringResource(R.string.search_chip_listing_choose_view_label),
        style = SparkTheme.typography.headline2,
        modifier = Modifier.constrainAs(title) {
            centerVerticallyTo(button)
        }
    )

    IconButtonGhost(
        icon = SparkIcons.Close,
        onClick = dismiss,
        intent = IconButtonIntent.Neutral,
        contentDescription = stringResource(id = R.string.searchtoppanel_close),
        modifier = Modifier.constrainAs(button) {}
    )

    createHorizontalChain(title, button)
}

image

Relevant logcat output

No response

Code of Conduct

soulcramer commented 10 months ago

Okay I think I know why this can happen, when creating this component we pass the modifier to the Surface instead of the PlainTooltipBox that wraps it

image