From f286cf7002557b819d3c7da154b9a04555f4ef25 Mon Sep 17 00:00:00 2001 From: DreVla Date: Tue, 2 May 2023 11:54:28 +0300 Subject: [PATCH] Bug 1830112 - Display full text in compose button when large font When using the compose button and the the size of the font is set to largest for accessibility purposes, the font should not cut if it doesn't fit. Instead, the button accommodates the entirety of the text. --- .../java/org/mozilla/fenix/compose/button/Button.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/mozilla/fenix/compose/button/Button.kt b/app/src/main/java/org/mozilla/fenix/compose/button/Button.kt index 79c934273f..873e3e304d 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/button/Button.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/button/Button.kt @@ -19,12 +19,16 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import org.mozilla.fenix.R import org.mozilla.fenix.compose.annotation.LightDarkPreview import org.mozilla.fenix.theme.FirefoxTheme +const val DEFAULT_MAX_LINES = 2 + /** * Base component for buttons. * @@ -44,6 +48,9 @@ private fun Button( tint: Color, onClick: () -> Unit, ) { + // Required to detect if font increased due to accessibility. + val fontScale: Float = LocalConfiguration.current.fontScale + androidx.compose.material.Button( onClick = onClick, modifier = Modifier.fillMaxWidth(), @@ -65,9 +72,10 @@ private fun Button( Text( text = text, + textAlign = TextAlign.Center, color = textColor, style = FirefoxTheme.typography.button, - maxLines = 1, + maxLines = if (fontScale > 1.0f) Int.MAX_VALUE else DEFAULT_MAX_LINES, ) } }