feat(AppBar): EnterAlwaysCollapsed for Compose

Google left out EnterAlwaysCollapsed for some reason
This commit is contained in:
Ahmad Ansori Palembani 2024-12-25 16:19:59 +07:00
parent dec1a70091
commit 120d2cfb96
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 5 additions and 29 deletions

View file

@ -7,7 +7,6 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
@ -20,6 +19,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.compose.LocalAlertDialog
import eu.kanade.tachiyomi.util.compose.LocalBackPress
import eu.kanade.tachiyomi.util.compose.currentOrThrow
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.delay
import uy.kohesive.injekt.injectLazy
import yokai.presentation.AppBarType
@ -28,7 +28,7 @@ import yokai.presentation.component.Gap
import yokai.presentation.component.preference.Preference
import yokai.presentation.component.preference.PreferenceItem
import yokai.presentation.component.preference.widget.PreferenceGroupHeader
import kotlin.time.Duration.Companion.seconds
import yokai.presentation.core.enterAlwaysCollapsedScrollBehavior
@Composable
fun SettingsScaffold(
@ -48,7 +48,7 @@ fun SettingsScaffold(
title = title,
appBarType = appBarType ?: if (useLargeAppBar) AppBarType.LARGE else AppBarType.SMALL,
actions = appBarActions,
scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
scrollBehavior = enterAlwaysCollapsedScrollBehavior(
state = rememberTopAppBarState(),
canScroll = { listState.canScrollForward || listState.canScrollBackward },
),

View file

@ -10,9 +10,6 @@ import androidx.compose.animation.core.animateDecay
import androidx.compose.animation.core.animateTo
import androidx.compose.animation.core.spring
import androidx.compose.animation.rememberSplineBasedDecay
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -168,29 +165,7 @@ private fun TwoRowsTopAppBar(
val hideTopRowSemantics = colorTransitionFraction < 0.5f
val hideBottomRowSemantics = !hideTopRowSemantics
// Set up support for resizing the top app bar when vertically dragging the bar itself.
val appBarDragModifier =
if (scrollBehavior != null && !scrollBehavior.isPinned) {
Modifier.draggable(
orientation = Orientation.Vertical,
state =
rememberDraggableState { delta -> scrollBehavior.state.heightOffset += delta },
onDragStopped = { velocity ->
settleAppBar(
scrollBehavior.state,
velocity,
collapsedHeightPx,
expandedHeightPx,
scrollBehavior.flingAnimationSpec,
scrollBehavior.snapAnimationSpec
)
}
)
} else {
Modifier
}
Surface(modifier = modifier.then(appBarDragModifier), color = appBarContainerColor) {
Surface(modifier = modifier, color = appBarContainerColor) {
Column {
AppBarLayout(
modifier =
@ -557,6 +532,7 @@ fun enterAlwaysCollapsedScrollBehavior(
)
}
// FIXME: AppBar size is overflowing if user flick the screen too fast
private class EnterAlwaysCollapsedScrollBehavior(
override val state: TopAppBarState,
override val snapAnimationSpec: AnimationSpec<Float>?,