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

Commit 13a778e5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[SB][Chips] Fix chip sizings, paddings, and visibility." into main

parents 27e388f6 a765eda7
Loading
Loading
Loading
Loading
+28 −13
Original line number Diff line number Diff line
@@ -127,6 +127,8 @@ import kotlin.math.min
 *
 * @sample com.android.systemui.compose.gallery.ActivityLaunchScreen
 * @sample com.android.systemui.compose.gallery.DialogLaunchScreen
 * @param defaultMinSize true if a default minimum size should be enforced even if this Expandable
 *   isn't currently clickable and false otherwise.
 */
@Composable
fun Expandable(
@@ -140,6 +142,7 @@ fun Expandable(
    // TODO(b/285250939): Default this to true then remove once the Compose QS expandables have
    // proven that the new implementation is robust.
    useModifierBasedImplementation: Boolean = false,
    defaultMinSize: Boolean = true,
    transitionControllerFactory: ComposableControllerFactory? = null,
    content: @Composable (Expandable) -> Unit,
) {
@@ -155,6 +158,7 @@ fun Expandable(
        onClick,
        interactionSource,
        useModifierBasedImplementation,
        defaultMinSize,
        content,
    )
}
@@ -182,6 +186,8 @@ fun Expandable(
 *
 * @sample com.android.systemui.compose.gallery.ActivityLaunchScreen
 * @sample com.android.systemui.compose.gallery.DialogLaunchScreen
 * @param defaultMinSize true if a default minimum size should be enforced even if this Expandable
 *   isn't currently clickable and false otherwise.
 */
@Composable
fun Expandable(
@@ -192,6 +198,7 @@ fun Expandable(
    // TODO(b/285250939): Default this to true then remove once the Compose QS expandables have
    // proven that the new implementation is robust.
    useModifierBasedImplementation: Boolean = false,
    defaultMinSize: Boolean = true,
    content: @Composable (Expandable) -> Unit,
) {
    val controller = controller as ExpandableControllerImpl
@@ -209,7 +216,12 @@ fun Expandable(

    if (useModifierBasedImplementation) {
        Box(modifier.expandable(controller, onClick, interactionSource)) {
            WrappedContent(controller.expandable, controller.contentColor, content)
            WrappedContent(
                controller.expandable,
                controller.contentColor,
                defaultMinSize = defaultMinSize,
                content,
            )
        }
        return
    }
@@ -221,7 +233,7 @@ fun Expandable(
    val wrappedContent =
        remember(content) {
            movableContentOf { expandable: Expandable ->
                WrappedContent(expandable, contentColor, content)
                WrappedContent(expandable, contentColor, defaultMinSize = defaultMinSize, content)
            }
        }

@@ -306,23 +318,26 @@ fun Expandable(
private fun WrappedContent(
    expandable: Expandable,
    contentColor: Color,
    defaultMinSize: Boolean,
    content: @Composable (Expandable) -> Unit,
) {
    val minSizeContent =
        @Composable {
            // We make sure that the content itself (wrapped by the background) is at least 40.dp,
            // which is the same as the M3 buttons. This applies even if onClick is null, to make it
            // easier to write expandables that are sometimes clickable and sometimes not. There
            // shouldn't be any Expandable smaller than 40dp because if the expandable is not
            // clickable directly, then something in its content should be (and with a size >=
            // 40dp).
            if (defaultMinSize) {
                // We make sure that the content itself (wrapped by the background) is at
                // least 40.dp, which is the same as the M3 buttons. This applies even if
                // onClick is null, to make it easier to write expandables that are
                // sometimes clickable and sometimes not.
                val minSize = 40.dp
                Box(
                Modifier.defaultMinSize(minWidth = minSize, minHeight = minSize),
                    modifier = Modifier.defaultMinSize(minWidth = minSize, minHeight = minSize),
                    contentAlignment = Alignment.Center,
                ) {
                    content(expandable)
                }
            } else {
                content(expandable)
            }
        }

    if (contentColor.isSpecified) {
+31 −19
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@@ -36,8 +37,10 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.viewinterop.AndroidView
import com.android.compose.animation.Expandable
import com.android.compose.modifiers.thenIf
import com.android.systemui.animation.Expandable
import com.android.systemui.common.ui.compose.Icon
import com.android.systemui.common.ui.compose.load
@@ -79,6 +82,17 @@ fun OngoingActivityChip(
                }
            is OngoingActivityChipModel.ClickBehavior.None -> null
        }
    val isClickable = onClick != null

    val chipSidePadding = dimensionResource(id = R.dimen.ongoing_activity_chip_side_padding)
    val minWidth =
        if (isClickable) {
            dimensionResource(id = R.dimen.min_clickable_item_size)
        } else if (model.icon != null) {
            dimensionResource(id = R.dimen.ongoing_activity_chip_icon_size) + chipSidePadding
        } else {
            dimensionResource(id = R.dimen.ongoing_activity_chip_min_text_width) + chipSidePadding
        }

    Expandable(
        color = Color(model.colors.background(LocalContext.current).defaultColor),
@@ -92,6 +106,15 @@ fun OngoingActivityChip(
                        this.contentDescription = contentDescription
                    }
                }
                .thenIf(isClickable) { Modifier.widthIn(min = minWidth) }
                .layout { measurable, constraints ->
                    val placeable = measurable.measure(constraints)
                    layout(placeable.width, placeable.height) {
                        if (constraints.maxWidth >= minWidth.roundToPx()) {
                            placeable.place(0, 0)
                        }
                    }
                }
                .graphicsLayer(
                    alpha =
                        if (model.transitionManager?.hideChipForTransition == true) {
@@ -103,9 +126,12 @@ fun OngoingActivityChip(
        borderStroke = borderStroke,
        onClick = onClick,
        useModifierBasedImplementation = StatusBarChipsReturnAnimations.isEnabled,
        // Some chips like the 3-2-1 countdown chip should be very small, smaller than a
        // reasonable minimum size.
        defaultMinSize = false,
        transitionControllerFactory = model.transitionManager?.controllerFactory,
    ) {
        ChipBody(model, iconViewStore, isClickable = onClick != null)
        ChipBody(model, iconViewStore, isClickable = isClickable, minWidth = minWidth)
    }
}

@@ -114,36 +140,22 @@ private fun ChipBody(
    model: OngoingActivityChipModel.Active,
    iconViewStore: NotificationIconContainerViewBinder.IconViewStore?,
    isClickable: Boolean,
    minWidth: Dp,
    modifier: Modifier = Modifier,
) {
    val hasEmbeddedIcon =
        model.icon is OngoingActivityChipModel.ChipIcon.StatusBarView ||
            model.icon is OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon

    val chipSidePadding = dimensionResource(id = R.dimen.ongoing_activity_chip_side_padding)
    val minWidth =
        if (isClickable) {
            dimensionResource(id = R.dimen.min_clickable_item_size)
        } else if (model.icon != null) {
            dimensionResource(id = R.dimen.ongoing_activity_chip_icon_size) + chipSidePadding
        } else {
            dimensionResource(id = R.dimen.ongoing_activity_chip_min_text_width) + chipSidePadding
        }

    Row(
        horizontalArrangement = Arrangement.Center,
        verticalAlignment = Alignment.CenterVertically,
        modifier =
            modifier
                .fillMaxHeight()
                .layout { measurable, constraints ->
                    val placeable = measurable.measure(constraints)
                    layout(placeable.width, placeable.height) {
                        if (constraints.maxWidth >= minWidth.roundToPx()) {
                            placeable.place(0, 0)
                        }
                    }
                }
                // Set the minWidth here as well as on the Expandable so that the content within
                // this row is still centered correctly horizontally
                .thenIf(isClickable) { Modifier.widthIn(min = minWidth) }
                .padding(
                    horizontal =
                        if (hasEmbeddedIcon) {