Font size on 'All Chats' was changing mid animation (#2073)

* Font size on 'All Chats' was changing mid animation
This commit is contained in:
Jorge Martin Espinosa 2023-12-20 14:52:19 +01:00 committed by GitHub
parent 9eb249c9e7
commit 96ebe1a11c
2 changed files with 116 additions and 110 deletions

1
changelog.d/1572.bugfix Normal file
View file

@ -0,0 +1 @@
Font size in 'All Chats' header was changing mid-animation.

View file

@ -24,6 +24,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState import androidx.compose.material3.rememberTopAppBarState
@ -149,6 +150,20 @@ private fun DefaultRoomListTopBar(
val statusBarPadding = with(LocalDensity.current) { WindowInsets.statusBars.getTop(this).toDp() } val statusBarPadding = with(LocalDensity.current) { WindowInsets.statusBars.getTop(this).toDp() }
Box(modifier = modifier) { Box(modifier = modifier) {
val collapsedTitleTextStyle = ElementTheme.typography.aliasScreenTitle
val expandedTitleTextStyle = ElementTheme.typography.fontHeadingLgBold.copy(
// Due to a limitation of MediumTopAppBar, and to avoid the text to be truncated,
// ensure that the font size will never be bigger than 28.dp.
fontSize = 28.dp.applyScaleDown().toSp()
)
MaterialTheme(
colorScheme = ElementTheme.materialColors,
shapes = MaterialTheme.shapes,
typography = ElementTheme.materialTypography.copy(
headlineSmall = expandedTitleTextStyle,
titleLarge = collapsedTitleTextStyle
),
) {
MediumTopAppBar( MediumTopAppBar(
modifier = Modifier modifier = Modifier
.onSizeChanged { .onSizeChanged {
@ -179,18 +194,7 @@ private fun DefaultRoomListTopBar(
scrolledContainerColor = Color.Transparent, scrolledContainerColor = Color.Transparent,
), ),
title = { title = {
val fontStyle = if (scrollBehavior.state.collapsedFraction > 0.5) Text(text = stringResource(id = R.string.screen_roomlist_main_space_title))
ElementTheme.typography.aliasScreenTitle
else
ElementTheme.typography.fontHeadingLgBold.copy(
// Due to a limitation of MediumTopAppBar, and to avoid the text to be truncated,
// ensure that the font size will never be bigger than 28.dp.
fontSize = 28.dp.applyScaleDown().toSp()
)
Text(
style = fontStyle,
text = stringResource(id = R.string.screen_roomlist_main_space_title)
)
}, },
navigationIcon = { navigationIcon = {
avatarData?.let { avatarData?.let {
@ -273,6 +277,7 @@ private fun DefaultRoomListTopBar(
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
windowInsets = WindowInsets(0.dp), windowInsets = WindowInsets(0.dp),
) )
}
HorizontalDivider( HorizontalDivider(
modifier = modifier =