Skip to content

Commit 9149955

Browse files
authored
fix: welcome screen on small display (#11203)
2 parents 19d12c6 + 3bc7aa8 commit 9149955

2 files changed

Lines changed: 36 additions & 30 deletions

File tree

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package app.k9mail.core.ui.compose.designsystem.atom.text
22

3+
import androidx.compose.foundation.text.BasicText
4+
import androidx.compose.foundation.text.TextAutoSize
35
import androidx.compose.runtime.Composable
4-
import androidx.compose.runtime.getValue
5-
import androidx.compose.runtime.mutableStateOf
6-
import androidx.compose.runtime.remember
7-
import androidx.compose.runtime.setValue
6+
import androidx.compose.material3.Text as Material3Text
87
import androidx.compose.ui.Modifier
9-
import androidx.compose.ui.draw.drawWithContent
108
import androidx.compose.ui.graphics.Color
119
import androidx.compose.ui.text.TextStyle
1210
import androidx.compose.ui.text.style.TextAlign
11+
import androidx.compose.ui.unit.sp
1312
import net.thunderbird.core.ui.compose.theme2.MainTheme
14-
import androidx.compose.material3.Text as Material3Text
1513

1614
@Composable
1715
fun TextDisplayMediumAutoResize(
@@ -21,28 +19,18 @@ fun TextDisplayMediumAutoResize(
2119
textAlign: TextAlign? = null,
2220
) {
2321
val style: TextStyle = MainTheme.typography.displayMedium
24-
var shouldDraw by remember { mutableStateOf(false) }
25-
var resizedTextStyle by remember { mutableStateOf(style) }
26-
2722
Material3Text(
2823
text = text,
29-
modifier = modifier.drawWithContent {
30-
if (shouldDraw) {
31-
drawContent()
32-
}
33-
},
34-
color = color,
35-
textAlign = textAlign,
24+
modifier = modifier,
25+
style = style.merge(
26+
color = color,
27+
textAlign = textAlign ?: TextAlign.Unspecified,
28+
),
3629
softWrap = false,
37-
style = resizedTextStyle,
38-
onTextLayout = { result ->
39-
if (result.didOverflowWidth) {
40-
resizedTextStyle = resizedTextStyle.copy(
41-
fontSize = resizedTextStyle.fontSize * 0.95,
42-
)
43-
} else {
44-
shouldDraw = true
45-
}
46-
},
30+
autoSize = TextAutoSize.StepBased(
31+
minFontSize = style.fontSize * 0.35f,
32+
maxFontSize = MainTheme.typography.displayMedium.fontSize,
33+
stepSize = 0.5.sp,
34+
),
4735
)
4836
}

feature/onboarding/welcome/src/main/kotlin/app/k9mail/feature/onboarding/welcome/ui/WelcomeContent.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonFilled
2424
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonText
2525
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyLarge
2626
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodySmall
27-
import app.k9mail.core.ui.compose.designsystem.atom.text.TextDisplayMedium
27+
import app.k9mail.core.ui.compose.designsystem.atom.text.TextDisplayMediumAutoResize
2828
import app.k9mail.core.ui.compose.designsystem.template.LazyColumnWithHeaderFooter
2929
import app.k9mail.core.ui.compose.designsystem.template.ResponsiveContent
3030
import app.k9mail.feature.onboarding.welcome.R
31+
import net.thunderbird.core.ui.common.window.WindowSizeClass
32+
import net.thunderbird.core.ui.common.window.WindowWidthSizeClass
33+
import net.thunderbird.core.ui.common.window.calculateWindowSizeInfo
3134
import net.thunderbird.core.ui.compose.theme2.MainTheme
3235
import org.jetbrains.compose.resources.painterResource
3336

3437
private const val CIRCLE_COLOR = 0xFFEEEEEE
3538
private const val CIRCLE_SIZE_DP = 200
39+
private const val CIRCLE_SIZE_SMALL_DP = 125
3640
private const val LOGO_SIZE_DP = 125
41+
private const val LOGO_SIZE_SMALL_DP = 80
3742

3843
@Composable
3944
internal fun WelcomeContent(
@@ -89,6 +94,19 @@ private fun WelcomeHeaderSection(
8994
private fun WelcomeLogo(
9095
modifier: Modifier = Modifier,
9196
) {
97+
val windowSizeInfo = calculateWindowSizeInfo()
98+
val isSmallScreen =
99+
windowSizeInfo.sizeClass.widthSizeClass == WindowWidthSizeClass.Small
100+
val circleSize = if (isSmallScreen) {
101+
CIRCLE_SIZE_SMALL_DP
102+
} else {
103+
CIRCLE_SIZE_DP
104+
}
105+
val logoSize = if (isSmallScreen) {
106+
LOGO_SIZE_SMALL_DP
107+
} else {
108+
LOGO_SIZE_DP
109+
}
92110
Column(
93111
modifier = modifier,
94112
horizontalAlignment = Alignment.CenterHorizontally,
@@ -97,13 +115,13 @@ private fun WelcomeLogo(
97115
modifier = Modifier
98116
.clip(CircleShape)
99117
.background(Color(CIRCLE_COLOR))
100-
.size(CIRCLE_SIZE_DP.dp),
118+
.size(circleSize.dp),
101119
) {
102120
Image(
103121
painter = painterResource(MainTheme.images.logo),
104122
contentDescription = null,
105123
modifier = Modifier
106-
.size(LOGO_SIZE_DP.dp)
124+
.size(logoSize.dp)
107125
.align(Alignment.Center),
108126
)
109127
}
@@ -134,7 +152,7 @@ private fun WelcomeTitle(
134152
modifier = modifier.padding(horizontal = MainTheme.spacings.quadruple),
135153
horizontalAlignment = Alignment.CenterHorizontally,
136154
) {
137-
TextDisplayMedium(
155+
TextDisplayMediumAutoResize(
138156
text = title,
139157
textAlign = TextAlign.Center,
140158
)

0 commit comments

Comments
 (0)