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

@ -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>?,