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

Unverified Commit 450d8f12 authored by Shamim Shahrier Emon's avatar Shamim Shahrier Emon Committed by GitHub
Browse files

Auto-resize brand name in `AppTitleTopHeader` to fit screen width (#8322)

parent 075e37e0
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
package app.k9mail.core.ui.compose.designsystem.atom.text

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import app.k9mail.core.ui.compose.theme2.MainTheme
import androidx.compose.material3.Text as Material3Text
@@ -39,3 +45,37 @@ fun TextDisplayMedium(
        style = MainTheme.typography.displayMedium,
    )
}

@Composable
fun TextDisplayMediumAutoResize(
    text: String,
    modifier: Modifier = Modifier,
    color: Color = Color.Unspecified,
    textAlign: TextAlign? = null,
) {
    val style: TextStyle = MainTheme.typography.displayMedium
    var shouldDraw by remember { mutableStateOf(false) }
    var resizedTextStyle by remember { mutableStateOf(style) }

    Material3Text(
        text = text,
        modifier = modifier.drawWithContent {
            if (shouldDraw) {
                drawContent()
            }
        },
        color = color,
        textAlign = textAlign,
        softWrap = false,
        style = resizedTextStyle,
        onTextLayout = { result ->
            if (result.didOverflowWidth) {
                resizedTextStyle = resizedTextStyle.copy(
                    fontSize = resizedTextStyle.fontSize * 0.95,
                )
            } else {
                shouldDraw = true
            }
        },
    )
}
+2 −2
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import app.k9mail.core.ui.compose.designsystem.atom.text.TextDisplayMedium
import app.k9mail.core.ui.compose.designsystem.atom.text.TextDisplayMediumAutoResize
import app.k9mail.core.ui.compose.designsystem.template.ResponsiveWidthContainer
import app.k9mail.core.ui.compose.theme2.MainTheme

@@ -51,7 +51,7 @@ fun AppTitleTopHeader(
                contentDescription = null,
            )

            TextDisplayMedium(text = title)
            TextDisplayMediumAutoResize(text = title)
        }
    }
}