Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78ac5975 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Make chips only as long as they need to be

Fixes: 417815235
Flag: com.android.systemui.enable_underlay
Test: atest NavBarPillScreenshotTest
Change-Id: I068aa771459b54267df23656971e121f404c1d36
parent f25e3dfe
Loading
Loading
Loading
Loading
+30 −46
Original line number Diff line number Diff line
@@ -23,10 +23,12 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -70,6 +72,7 @@ fun NavBarPill(
    onClick: () -> Unit = {},
    onCloseClick: () -> Unit = {},
) {
    val maxPillWidth = 247.dp
    val outlineColor = Color.White
    val backgroundColor = Color.Black

@@ -115,7 +118,7 @@ fun NavBarPill(
                verticalAlignment = Alignment.CenterVertically,
                modifier =
                    Modifier.clip(RoundedCornerShape(16.dp))
                        .widthIn(min = navBarWidth, max = 247.dp)
                        .widthIn(min = navBarWidth, max = maxPillWidth)
                        .background(backgroundColor)
                        .animatedActionBorder(
                            strokeWidth = 2.dp,
@@ -130,18 +133,19 @@ fun NavBarPill(
                // Should have at most 1 expanded chip
                var expandedChip = false
                actions.fastForEach { action ->
                    if ((actions.size == 1 || action.attribution != null) && !expandedChip) {
                        expandedChip = true
                    val hasAttribution = action.attribution != null
                    Row(
                        horizontalArrangement =
                            Arrangement.spacedBy(4.dp, Alignment.CenterHorizontally),
                        verticalAlignment = Alignment.CenterVertically,
                            modifier = Modifier.weight(1f),
                        modifier =
                            if (hasAttribution) Modifier.weight(1f, false)
                            else Modifier.width(IntrinsicSize.Max),
                    ) {
                        Image(
                            painter = rememberDrawablePainter(action.icon),
                            colorFilter =
                                    if (action.attribution != null) {
                                if (hasAttribution) {
                                    ColorFilter.tint(outlineColor)
                                } else {
                                    null
@@ -150,47 +154,27 @@ fun NavBarPill(
                            modifier = Modifier.size(16.dp).clip(CircleShape),
                        )

                        if ((actions.size == 1 || hasAttribution) && !expandedChip) {
                            expandedChip = true
                            Text(
                                text = action.label,
                                style = MaterialTheme.typography.labelSmall,
                                maxLines = 1,
                                overflow = TextOverflow.Ellipsis,
                                color = outlineColor,
                                modifier = Modifier.weight(0.63f, fill = false),
                                modifier = Modifier.widthIn(0.dp, maxPillWidth * 0.5f),
                            )
                            if (action.attribution != null) {
                            if (hasAttribution) {
                                Text(
                                    text = action.attribution,
                                    text = action.attribution!!,
                                    style = MaterialTheme.typography.labelSmall,
                                    maxLines = 1,
                                    overflow = TextOverflow.Ellipsis,
                                    color = outlineColor,
                                    modifier =
                                        Modifier.padding(start = 4.dp)
                                            .alpha(0.4f)
                                            .weight(0.37f, false),
                                    modifier = Modifier.padding(start = 4.dp).alpha(0.4f),
                                )
                            }
                        }
                    } else {
                        // collapsed chip
                        Row(
                            horizontalArrangement =
                                Arrangement.spacedBy(4.dp, Alignment.CenterHorizontally),
                            verticalAlignment = Alignment.CenterVertically,
                        ) {
                            Image(
                                painter = rememberDrawablePainter(action.icon),
                                colorFilter =
                                    if (action.attribution != null) {
                                        ColorFilter.tint(outlineColor)
                                    } else {
                                        null
                                    },
                                contentDescription = action.label,
                                modifier = Modifier.size(16.dp).clip(CircleShape),
                            )
                        }
                    }
                }
            }