google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.31k stars 590 forks source link

[Placeholder] Placeholder height incorrect with Material3 AssistChip #1568

Closed ammargitham closed 1 year ago

ammargitham commented 1 year ago

Describe the bug

As visible in the screenshot below, the placeholder height is greater than the AssistChip height.

To Reproduce

Code to reproduce:

import androidx.compose.material3.AssistChip
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.surfaceColorAtElevation
import com.google.accompanist.placeholder.PlaceholderHighlight
import com.google.accompanist.placeholder.material.fade
import com.google.accompanist.placeholder.material.placeholder

AssistChip(
    modifier = Modifier.placeholder(
        color = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
        visible = loading,
        highlight = PlaceholderHighlight.fade(),
        shape = AssistChipDefaults.shape,
    ),
    onClick = {},
    label = { Text(text = "#Test-1") },
)

Expected behavior

The placeholder height should be same as the rendered AssistChip height.

Screenshots?

tag

Environment:

ammargitham commented 1 year ago

As a workaround this works for me (Preview seems to show the chip peeking from behind, but on device seems fine):

Box(
    modifier = Modifier.width(IntrinsicSize.Max),
) {
    AssistChip(
        onClick = {},
        label = { Text(text = "#Test-1") },
    )
    if (loading) {
        Box(
            modifier = Modifier
                .height(AssistChipDefaults.Height)
                .fillMaxWidth()
                .align(Alignment.Center)
                .placeholder(
                    color = MaterialTheme.colorScheme.surfaceColorAtElevation(2.dp),
                    visible = true,
                    highlight = PlaceholderHighlight.fade(),
                    shape = AssistChipDefaults.shape,
                )
        )
    }
}

workaround

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.