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

Commit 09510bc5 authored by Tianfan Zhang's avatar Tianfan Zhang Committed by Lucas Dupin
Browse files

Add close button to NavBarPill.

Bug: 403422950
Flag: com.android.systemui.enable_underlay
Test: atest NavBarPillScreenshotTest
Change-Id: I63100845a04d4100da121868f3977b7125ee1696
parent 6f6039e6
Loading
Loading
Loading
Loading
+68 −29
Original line number Diff line number Diff line
@@ -25,10 +25,12 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
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.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -45,12 +47,15 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEachIndexed
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.lerp
import com.android.compose.PlatformIconButton
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
import com.android.systemui.res.R
import com.android.systemui.underlay.ui.viewmodel.ActionViewModel

@Composable
@@ -61,6 +66,7 @@ fun NavBarPill(
    visible: Boolean = true,
    expanded: Boolean = false,
    onClick: () -> Unit = {},
    onCloseClick: () -> Unit = {},
) {
    val outlineColor = Color.White
    val backgroundColor = Color.Black
@@ -95,6 +101,13 @@ fun NavBarPill(
                    }
            }
    ) {
        Row(
            horizontalArrangement = Arrangement.spacedBy(8.dp),
            verticalAlignment = Alignment.CenterVertically,
        ) {
            val closeButtonSize = 28.dp
            Spacer(modifier = Modifier.size(closeButtonSize))

            Row(
                horizontalArrangement = Arrangement.spacedBy(4.dp),
                verticalAlignment = Alignment.CenterVertically,
@@ -106,27 +119,33 @@ fun NavBarPill(
                        .padding(horizontal = 8.dp, vertical = 6.dp)
                        .onGloballyPositioned { expandedSize = it.size },
            ) {
            actions.fastForEachIndexed { _, action ->
                val painter = rememberDrawablePainter(action.icon)
                actions.fastForEach { action ->
                    Image(
                    painter = painter,
                        painter = rememberDrawablePainter(action.icon),
                        colorFilter =
                        if (action.attribution != null) ColorFilter.tint(outlineColor) else null,
                            if (action.attribution != null) {
                                ColorFilter.tint(outlineColor)
                            } else {
                                null
                            },
                        contentDescription = action.label,
                        modifier = Modifier.size(16.dp).clip(CircleShape),
                    )
                }

            if (actions.size == 1 || (actions.isNotEmpty() && actions.last().attribution != null)) {
                val action = actions.last()
                if (
                    actions.size == 1 ||
                        (actions.isNotEmpty() && actions.last().attribution != null)
                ) {
                    val lastAction = actions.last()
                    Text(
                    action.label,
                        text = lastAction.label,
                        style = MaterialTheme.typography.labelSmall,
                        color = outlineColor,
                    )
                if (action.attribution != null) {
                    if (lastAction.attribution != null) {
                        Text(
                        action.attribution,
                            text = lastAction.attribution,
                            style = MaterialTheme.typography.labelSmall,
                            color = outlineColor,
                            modifier = Modifier.padding(start = 4.dp).alpha(0.4f),
@@ -134,5 +153,25 @@ fun NavBarPill(
                    }
                }
            }

            PlatformIconButton(
                modifier =
                    Modifier.size(closeButtonSize)
                        .clip(CircleShape)
                        .background(backgroundColor)
                        .padding(8.dp),
                iconResource = R.drawable.ic_close_white_rounded,
                colors =
                    IconButtonColors(
                        containerColor = backgroundColor,
                        contentColor = outlineColor,
                        disabledContainerColor = backgroundColor,
                        disabledContentColor = outlineColor,
                    ),
                contentDescription =
                    stringResource(id = R.string.underlay_close_button_content_description),
                onClick = onCloseClick,
            )
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ fun OverlayContainer(
            expanded = expanded,
            modifier = Modifier.align(Alignment.BottomCenter),
            onClick = { viewModel.expand() },
            onCloseClick = { viewModel.hide() },
        )
        ActionList(
            actions = actions,