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

Commit 1eb4dea0 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Improve some common/ui/ utilities

This CL adds the @ReadyOnlyComposable to ContentDescription.load() and
Text.load(). This should slightly decrease the number of groups
generated by the Compose compiler, which is usually better for
performance.

This CL also makes use of rememberDrawablePainter() in Icon(), when the
passed icon is an Icon.Loaded(Drawable). I haven't measured this, but
this should be much better than converting the Drawable into a Bitmap
everytime Icon is recomposed.

Bug: 372412931
Test: Manual, volume panel (only user of Icon) still worked as expected
Flag: EXEMPT performance fix
Change-Id: I56f38a562f002645f6a625cc2cdf1e96e97ae5c6
parent acb120ef
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,11 +17,13 @@
package com.android.systemui.common.ui.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.res.stringResource
import com.android.systemui.common.shared.model.ContentDescription

/** Returns the loaded [String] or `null` if there isn't one. */
@Composable
@ReadOnlyComposable
fun ContentDescription.load(): String? {
    return when (this) {
        is ContentDescription.Loaded -> description
+2 −3
Original line number Diff line number Diff line
@@ -21,9 +21,8 @@ import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.res.painterResource
import androidx.core.graphics.drawable.toBitmap
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
import com.android.systemui.common.shared.model.Icon

/**
@@ -36,7 +35,7 @@ fun Icon(icon: Icon, modifier: Modifier = Modifier, tint: Color = LocalContentCo
    val contentDescription = icon.contentDescription?.load()
    when (icon) {
        is Icon.Loaded -> {
            Icon(icon.drawable.toBitmap().asImageBitmap(), contentDescription, modifier, tint)
            Icon(rememberDrawablePainter(icon.drawable), contentDescription, modifier, tint)
        }
        is Icon.Resource -> Icon(painterResource(icon.res), contentDescription, modifier, tint)
    }
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.common.ui.compose

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import com.android.systemui.common.shared.model.Text
@@ -26,6 +27,7 @@ import com.android.systemui.common.shared.model.Text.Companion.loadText

/** Returns the loaded [String] or `null` if there isn't one. */
@Composable
@ReadOnlyComposable
fun Text.load(): String? {
    return when (this) {
        is Text.Loaded -> text