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

Commit f2f64833 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

[Compose Notifs] Center title & expander when we have no content

When the notification has only one line (sometimes referred to as
"header-only" in the legacy codebase), we want that line and the
expander to be centered vertically.

Bug: 431222735
Test: manual in the Gallery app
Flag: EXEMPT not production code yet
Change-Id: Ib22d78747586250517d7cb4c0e4101d4bd3312d2
parent 6d49f7b6
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -39,12 +39,11 @@ import com.android.systemui.notifications.ui.viewmodel.NotificationViewModel
@Composable
public fun NotificationContent(viewModel: NotificationViewModel, modifier: Modifier = Modifier) {
    // TODO: b/431222735 - Handle transitions using STL.
    // TODO: b/431222735 - Handle empty text edge cases.
    if (!viewModel.isExpanded) {
        NotificationRow(
            viewModel,
            firstLine = { Title(viewModel.title) },
            secondLine = { CollapsedText(viewModel.text) },
            secondLine = { viewModel.text?.let { CollapsedText(it) } },
            modifier,
        )
    } else {
@@ -57,7 +56,7 @@ public fun NotificationContent(viewModel: NotificationViewModel, modifier: Modif
            secondLine = { Title(viewModel.title) },
            modifier,
        ) {
            ExpandedText(viewModel.text, maxLines = viewModel.maxLinesWhenExpanded)
            viewModel.text?.let { ExpandedText(it, maxLines = viewModel.maxLinesWhenExpanded) }
        }
    }
}
@@ -103,7 +102,9 @@ private fun HeaderWithLargeIcon(
) {
    Row(modifier.fillMaxWidth()) {
        Column(
            modifier = Modifier.weight(1f).padding(top = 4.dp),
            // The text container has a min height in order to align correctly to the app icon when
            // there's only one line of text, or the font size is smaller.
            modifier = Modifier.weight(1f).padding(top = 4.dp).heightIn(min = 40.dp),
            verticalArrangement = Arrangement.Center,
        ) {
            firstLine()
@@ -125,7 +126,12 @@ private fun HeaderWithoutLargeIcon(
    secondLine: @Composable () -> Unit,
    modifier: Modifier = Modifier,
) {
    Column(modifier.padding(top = 4.dp).fillMaxWidth()) {
    Column(
        // The text container has a min height in order to align correctly to the app icon when
        // there's only one line of text, or the font size is smaller.
        modifier.padding(top = 4.dp).fillMaxWidth().heightIn(min = 40.dp),
        verticalArrangement = Arrangement.Center,
    ) {
        Row(verticalAlignment = Alignment.CenterVertically) {
            Box(Modifier.weight(1f)) { firstLine() }
            Expander(expanded = viewModel.isExpanded)
+2 −1
Original line number Diff line number Diff line
@@ -31,10 +31,11 @@ public interface NotificationViewModel {
    /** The "large icon" shown on the top end of the notification beside the expander. */
    public val largeIcon: Drawable?

    // TODO: b/431222735 - Make this nullable once we implement the top line fields.
    /** The title of the notification, emphasized in the content. */
    public val title: String
    /** The content text of the notification, shown below the title. */
    public val text: String
    public val text: String?

    /** How many lines of text can be displayed when the notification is expanded. */
    public val maxLinesWhenExpanded: Int