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

Commit 23bab1dd authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Only apply text marquee to tiles with label overflow

Most tiles don't need to have a marquee modifier applied, and we can reduce the performance impact of marquee by ignoring these.

Test: using perfetto
Test: manually
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Bug: 400756252
Fixes: 402073344
Change-Id: I77d86d04b47536b885125b3d941bd372a21e8a65
parent 42261925
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ fun ContentScope.QuickQuickSettings(
                        viewModel.tileHapticsViewModelFactoryProvider,
                    // There should be no QuickQuickSettings when the details view is enabled.
                    detailsViewModel = null,
                    isVisible = listening,
                )
            }
        }
+38 −18
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@@ -102,6 +103,7 @@ fun LargeTileContent(
    sideDrawable: Drawable?,
    colors: TileColors,
    squishiness: () -> Float,
    isVisible: () -> Boolean = { true },
    accessibilityUiState: AccessibilityUiState? = null,
    iconShape: RoundedCornerShape = RoundedCornerShape(CommonTileDefaults.InactiveCornerRadius),
    toggleClick: (() -> Unit)? = null,
@@ -158,6 +160,7 @@ fun LargeTileContent(
            secondaryLabel = secondaryLabel,
            colors = colors,
            accessibilityUiState = accessibilityUiState,
            isVisible = isVisible,
        )

        if (sideDrawable != null) {
@@ -176,6 +179,7 @@ fun LargeTileLabels(
    secondaryLabel: String?,
    colors: TileColors,
    modifier: Modifier = Modifier,
    isVisible: () -> Boolean = { true },
    accessibilityUiState: AccessibilityUiState? = null,
) {
    val animatedLabelColor by animateColorAsState(colors.label, label = "QSTileLabelColor")
@@ -186,12 +190,14 @@ fun LargeTileLabels(
            text = label,
            style = MaterialTheme.typography.labelLarge,
            color = { animatedLabelColor },
            isVisible = isVisible,
        )
        if (!TextUtils.isEmpty(secondaryLabel)) {
            TileLabel(
                secondaryLabel ?: "",
                color = { animatedSecondaryLabelColor },
                style = MaterialTheme.typography.bodyMedium,
                isVisible = isVisible,
                modifier =
                    Modifier.thenIf(
                        accessibilityUiState?.stateDescription?.contains(secondaryLabel ?: "") ==
@@ -277,18 +283,27 @@ private fun TileLabel(
    color: ColorProducer,
    style: TextStyle,
    modifier: Modifier = Modifier,
    isVisible: () -> Boolean = { true },
) {
    var textSize by remember { mutableIntStateOf(0) }

    BasicText(
        text = text,
        color = color,
        style = style,
        maxLines = 1,
        onTextLayout = { textSize = it.size.width },
        modifier =
            modifier
                .fillMaxWidth()
                .graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
                .graphicsLayer {
                    if (textSize > size.width) {
                        compositingStrategy = CompositingStrategy.Offscreen
                    }
                }
                .drawWithContent {
                    drawContent()
                    if (textSize > size.width) {
                        // Draw a blur over the end of the text
                        val edgeWidthPx = TileLabelBlurWidth.toPx()
                        drawRect(
@@ -303,10 +318,15 @@ private fun TileLabel(
                            blendMode = BlendMode.DstIn,
                        )
                    }
                .basicMarquee(
                }
                .thenIf(isVisible()) {
                    // Only apply the marquee when the label is visible, which is needed for the
                    // always composed QS
                    Modifier.basicMarquee(
                        iterations = TILE_MARQUEE_ITERATIONS,
                        initialDelayMillis = TILE_INITIAL_DELAY_MILLIS,
                ),
                    )
                },
    )
}

+1 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ constructor(
                            isLastInRow = isLastInColumn,
                        ),
                    detailsViewModel = detailsViewModel,
                    isVisible = listening,
                )
            }
        }
+2 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ fun Tile(
    bounceableInfo: BounceableInfo,
    tileHapticsViewModelFactoryProvider: TileHapticsViewModelFactoryProvider,
    modifier: Modifier = Modifier,
    isVisible: () -> Boolean = { true },
    detailsViewModel: DetailsViewModel?,
) {
    trace(tile.traceName) {
@@ -248,6 +249,7 @@ fun Tile(
                        onLongClick = longClick,
                        accessibilityUiState = uiState.accessibilityUiState,
                        squishiness = squishiness,
                        isVisible = isVisible,
                    )
                }
            }