changes in AppBar

This commit is contained in:
Avently
2024-11-21 17:39:16 +07:00
parent 69793ac204
commit 6229ebf6f4
3 changed files with 12 additions and 5 deletions
@@ -24,10 +24,14 @@ fun AppBarTitle(
bottomPadding: Dp = DEFAULT_PADDING * 1.5f + 8.dp,
enableAlphaChanges: Boolean = true
) {
val handler = if (enableAlphaChanges) LocalAppBarHandler.current else null
val connection = handler?.connection
val handler = LocalAppBarHandler.current
val connection = if (enableAlphaChanges) handler?.connection else null
LaunchedEffect(title) {
handler?.title?.value = title
if (enableAlphaChanges) {
handler?.title?.value = title
} else {
handler?.connection?.scrollTrackingEnabled = false
}
}
val theme = CurrentColors.collectAsState()
val titleColor = MaterialTheme.appColors.title
@@ -60,7 +64,8 @@ fun AppBarTitle(
}
private fun bottomTitleAlpha(connection: CollapsingAppBarNestedScrollConnection?) =
if ((connection?.appBarOffset ?: 0f).absoluteValue < AppBarHandler.appBarMaxHeightPx / 3) 1f
if (connection?.scrollTrackingEnabled == false) 1f
else if ((connection?.appBarOffset ?: 0f).absoluteValue < AppBarHandler.appBarMaxHeightPx / 3) 1f
else ((AppBarHandler.appBarMaxHeightPx) + (connection?.appBarOffset ?: 0f) / 1.5f).coerceAtLeast(0f) / AppBarHandler.appBarMaxHeightPx
@Composable
@@ -84,6 +84,7 @@ class AppBarHandler(
}
class CollapsingAppBarNestedScrollConnection(): NestedScrollConnection {
var scrollTrackingEnabled = true
var appBarOffset: Float by mutableFloatStateOf(0f)
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
@@ -258,7 +258,8 @@ private fun AppBarCenterAligned(
}
private fun topTitleAlpha(text: Boolean, connection: CollapsingAppBarNestedScrollConnection, alpha: Float = appPrefs.inAppBarsAlpha.get()) =
if (connection.appBarOffset.absoluteValue < AppBarHandler.appBarMaxHeightPx / 3) 0f
if (!connection.scrollTrackingEnabled) 0f
else if (connection.appBarOffset.absoluteValue < AppBarHandler.appBarMaxHeightPx / 3) 0f
else ((-connection.appBarOffset * 1.5f) / (AppBarHandler.appBarMaxHeightPx)).coerceIn(0f, if (text) 1f else alpha)
val AppBarHeight = 56.dp