From da2d88eeb720f1a735522a105907588ca3ddbb9f Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Wed, 8 Feb 2023 16:05:24 +0800 Subject: [PATCH] Fine tune the CustomizedAppBar To reduce flaky and match current Settings. Bug: 236346018 Test: Manually with Settings Change-Id: I8b31bdf2ed1b38aff6928f2ef331ecf1c691e8a8 --- .../spa/widget/scaffold/CustomizedAppBar.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt index e8b5b19daad05..f6bb3cc271fef 100644 --- a/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt +++ b/packages/SettingsLib/Spa/spa/src/com/android/settingslib/spa/widget/scaffold/CustomizedAppBar.kt @@ -119,7 +119,6 @@ internal fun CustomizedLargeTopAppBar( actions = actions, colors = topAppBarColors(), windowInsets = TopAppBarDefaults.windowInsets, - maxHeightWithoutTitle = 120.dp, pinnedHeight = ContainerHeight, scrollBehavior = scrollBehavior, ) @@ -261,7 +260,7 @@ private fun SingleRowTopAppBar( * A two-rows top app bar that is designed to be called by the Large and Medium top app bar * composables. * - * @throws [IllegalArgumentException] if the given [maxHeightWithoutTitle] is equal or smaller than + * @throws [IllegalArgumentException] if the given [MaxHeightWithoutTitle] is equal or smaller than * the [pinnedHeight] */ @OptIn(ExperimentalMaterial3Api::class) @@ -277,11 +276,10 @@ private fun TwoRowsTopAppBar( actions: @Composable RowScope.() -> Unit, windowInsets: WindowInsets, colors: TopAppBarColors, - maxHeightWithoutTitle: Dp, pinnedHeight: Dp, scrollBehavior: TopAppBarScrollBehavior? ) { - if (maxHeightWithoutTitle <= pinnedHeight) { + if (MaxHeightWithoutTitle <= pinnedHeight) { throw IllegalArgumentException( "A TwoRowsTopAppBar max height should be greater than its pinned height" ) @@ -289,7 +287,7 @@ private fun TwoRowsTopAppBar( val pinnedHeightPx: Float val density = LocalDensity.current val maxHeightPx = density.run { - remember { mutableStateOf((maxHeightWithoutTitle + pinnedHeight).toPx()) } + remember { mutableStateOf((MaxHeightWithoutTitle + DefaultTitleHeight).toPx()) } } val titleBottomPaddingPx: Int density.run { @@ -380,7 +378,7 @@ private fun TwoRowsTopAppBar( Box(modifier = Modifier.onGloballyPositioned { coordinates -> density.run { maxHeightPx.value = - maxHeightWithoutTitle.toPx() + coordinates.size.height.toFloat() + MaxHeightWithoutTitle.toPx() + coordinates.size.height.toFloat() } }) { title() } }, @@ -610,6 +608,8 @@ private suspend fun settleAppBar( // Medium or Large app bar. private val TopTitleAlphaEasing = CubicBezierEasing(.8f, 0f, .8f, .15f) +private val MaxHeightWithoutTitle = 124.dp +private val DefaultTitleHeight = 52.dp private val ContainerHeight = 56.dp private val LargeTitleBottomPadding = 28.dp private val TopAppBarHorizontalPadding = 4.dp