mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
feat(AppBar): EnterAlwaysCollapsed for Compose
Google left out EnterAlwaysCollapsed for some reason
This commit is contained in:
parent
dec1a70091
commit
120d2cfb96
2 changed files with 5 additions and 29 deletions
|
@ -7,7 +7,6 @@ import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.TopAppBarDefaults
|
|
||||||
import androidx.compose.material3.rememberTopAppBarState
|
import androidx.compose.material3.rememberTopAppBarState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
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.LocalAlertDialog
|
||||||
import eu.kanade.tachiyomi.util.compose.LocalBackPress
|
import eu.kanade.tachiyomi.util.compose.LocalBackPress
|
||||||
import eu.kanade.tachiyomi.util.compose.currentOrThrow
|
import eu.kanade.tachiyomi.util.compose.currentOrThrow
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import yokai.presentation.AppBarType
|
import yokai.presentation.AppBarType
|
||||||
|
@ -28,7 +28,7 @@ import yokai.presentation.component.Gap
|
||||||
import yokai.presentation.component.preference.Preference
|
import yokai.presentation.component.preference.Preference
|
||||||
import yokai.presentation.component.preference.PreferenceItem
|
import yokai.presentation.component.preference.PreferenceItem
|
||||||
import yokai.presentation.component.preference.widget.PreferenceGroupHeader
|
import yokai.presentation.component.preference.widget.PreferenceGroupHeader
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import yokai.presentation.core.enterAlwaysCollapsedScrollBehavior
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsScaffold(
|
fun SettingsScaffold(
|
||||||
|
@ -48,7 +48,7 @@ fun SettingsScaffold(
|
||||||
title = title,
|
title = title,
|
||||||
appBarType = appBarType ?: if (useLargeAppBar) AppBarType.LARGE else AppBarType.SMALL,
|
appBarType = appBarType ?: if (useLargeAppBar) AppBarType.LARGE else AppBarType.SMALL,
|
||||||
actions = appBarActions,
|
actions = appBarActions,
|
||||||
scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
|
scrollBehavior = enterAlwaysCollapsedScrollBehavior(
|
||||||
state = rememberTopAppBarState(),
|
state = rememberTopAppBarState(),
|
||||||
canScroll = { listState.canScrollForward || listState.canScrollBackward },
|
canScroll = { listState.canScrollForward || listState.canScrollBackward },
|
||||||
),
|
),
|
||||||
|
|
|
@ -10,9 +10,6 @@ import androidx.compose.animation.core.animateDecay
|
||||||
import androidx.compose.animation.core.animateTo
|
import androidx.compose.animation.core.animateTo
|
||||||
import androidx.compose.animation.core.spring
|
import androidx.compose.animation.core.spring
|
||||||
import androidx.compose.animation.rememberSplineBasedDecay
|
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.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
@ -168,29 +165,7 @@ private fun TwoRowsTopAppBar(
|
||||||
val hideTopRowSemantics = colorTransitionFraction < 0.5f
|
val hideTopRowSemantics = colorTransitionFraction < 0.5f
|
||||||
val hideBottomRowSemantics = !hideTopRowSemantics
|
val hideBottomRowSemantics = !hideTopRowSemantics
|
||||||
|
|
||||||
// Set up support for resizing the top app bar when vertically dragging the bar itself.
|
Surface(modifier = modifier, color = appBarContainerColor) {
|
||||||
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) {
|
|
||||||
Column {
|
Column {
|
||||||
AppBarLayout(
|
AppBarLayout(
|
||||||
modifier =
|
modifier =
|
||||||
|
@ -557,6 +532,7 @@ fun enterAlwaysCollapsedScrollBehavior(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: AppBar size is overflowing if user flick the screen too fast
|
||||||
private class EnterAlwaysCollapsedScrollBehavior(
|
private class EnterAlwaysCollapsedScrollBehavior(
|
||||||
override val state: TopAppBarState,
|
override val state: TopAppBarState,
|
||||||
override val snapAnimationSpec: AnimationSpec<Float>?,
|
override val snapAnimationSpec: AnimationSpec<Float>?,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue