From e559520df327c766c09cba54266fcd9acf68b0f9 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Fri, 16 May 2025 23:40:50 +0800 Subject: [PATCH] Minor cleanup --- .../gestures/AnchoredHorizontalDraggable.kt | 188 +----------------- .../androidx/compose/material3/SideDrawer.kt | 4 +- .../material3/fork/SwipeToDismissBox.fork.kt | 4 +- .../com/hippo/ehviewer/ui/main/GalleryList.kt | 2 +- .../hippo/ehviewer/ui/reader/ReaderScreen.kt | 13 +- .../com/hippo/ehviewer/ui/reader/Utils.kt | 21 -- .../ehviewer/ui/screen/DownloadsScreen.kt | 3 +- .../ehviewer/ui/screen/FavoritesScreen.kt | 3 +- .../ui/screen/GalleryDetailContent.kt | 4 +- .../ehviewer/ui/screen/GalleryListScreen.kt | 5 +- .../com/hippo/ehviewer/ui/tools/LazyGrid.kt | 4 +- .../com/hippo/ehviewer/ui/tools/LazyList.kt | 3 +- .../ehviewer/ui/tools/VerticalScrollbar.kt | 2 +- .../hippo/ehviewer/ui/tools/WindowInsets.kt | 5 - 14 files changed, 28 insertions(+), 233 deletions(-) delete mode 100644 app/src/main/kotlin/com/hippo/ehviewer/ui/tools/WindowInsets.kt diff --git a/app/src/main/kotlin/androidx/compose/foundation/gestures/AnchoredHorizontalDraggable.kt b/app/src/main/kotlin/androidx/compose/foundation/gestures/AnchoredHorizontalDraggable.kt index 24a3fd6cc..33f7beb58 100644 --- a/app/src/main/kotlin/androidx/compose/foundation/gestures/AnchoredHorizontalDraggable.kt +++ b/app/src/main/kotlin/androidx/compose/foundation/gestures/AnchoredHorizontalDraggable.kt @@ -16,16 +16,8 @@ package androidx.compose.foundation.gestures -import androidx.compose.animation.core.AnimationSpec -import androidx.compose.animation.core.DecayAnimationSpec -import androidx.compose.animation.core.FloatDecayAnimationSpec -import androidx.compose.animation.core.generateDecayAnimationSpec import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.gestures.HorizontalDragEvent.DragDelta -import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider -import androidx.compose.foundation.gestures.snapping.snapFlingBehavior -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.input.pointer.PointerInputChange @@ -35,23 +27,15 @@ import androidx.compose.ui.layout.MeasureResult import androidx.compose.ui.layout.MeasureScope import androidx.compose.ui.node.LayoutModifierNode import androidx.compose.ui.node.ModifierNodeElement -import androidx.compose.ui.node.ObserverModifierNode -import androidx.compose.ui.node.currentValueOf -import androidx.compose.ui.node.observeReads import androidx.compose.ui.node.requireLayoutDirection import androidx.compose.ui.platform.InspectorInfo -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.debugInspectorInfo import androidx.compose.ui.unit.Constraints -import androidx.compose.ui.unit.Density import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.Velocity -import androidx.compose.ui.unit.dp -import kotlin.math.abs import kotlin.math.absoluteValue import kotlin.math.roundToInt -import kotlin.math.sign import kotlinx.coroutines.launch @ExperimentalFoundationApi @@ -61,7 +45,7 @@ fun Modifier.anchoredHorizontalDraggable( enableDragFromEndToStart: Boolean = true, enabled: Boolean = true, startDragImmediately: Boolean = state.isAnimationRunning, - flingBehavior: FlingBehavior? = null, + flingBehavior: FlingBehavior, ): Modifier = this then AnchoredHorizontalDraggableElement( state = state, canDrag = { (x, y) -> @@ -78,7 +62,7 @@ private class AnchoredHorizontalDraggableElement( private val canDrag: (Offset) -> Boolean, private val enabled: Boolean, private val startDragImmediately: Boolean, - private val flingBehavior: FlingBehavior?, + private val flingBehavior: FlingBehavior, ) : ModifierNodeElement>() { override fun create() = AnchoredHorizontalDraggableNode( state, @@ -136,45 +120,12 @@ private class AnchoredHorizontalDraggableNode( private var canDrag: (Offset) -> Boolean, enabled: Boolean, private var startDragImmediately: Boolean, - private var flingBehavior: FlingBehavior?, -) : HorizontalDragGestureNode(enabled = enabled), - ObserverModifierNode { - - lateinit var resolvedFlingBehavior: FlingBehavior - lateinit var density: Density + private var flingBehavior: FlingBehavior, +) : HorizontalDragGestureNode(enabled = enabled) { private val isReverseDirection: Boolean get() = requireLayoutDirection() == LayoutDirection.Rtl - override fun onAttach() { - updateFlingBehavior(flingBehavior) - } - - override fun onObservedReadsChanged() { - val newDensity = currentValueOf(LocalDensity) - if (density != newDensity) { - density = newDensity - updateFlingBehavior(flingBehavior) - } - } - - private fun updateFlingBehavior(newFlingBehavior: FlingBehavior?) { - // Fall back to default fling behavior if the new fling behavior is null - this.resolvedFlingBehavior = - if (newFlingBehavior == null) { - // Only register for LocalDensity snapshot updates if we are creating a decay - observeReads { density = currentValueOf(LocalDensity) } - anchoredDraggableFlingBehavior( - snapAnimationSpec = AnchoredDraggableDefaults.SnapAnimationSpec, - positionalThreshold = AnchoredDraggableDefaults.PositionalThreshold, - density = density, - state = state, - ) - } else { - newFlingBehavior - } - } - override fun canDrag(change: PointerInputChange): Boolean = canDrag(change.positionChange().reverseIfNeeded()) override suspend fun drag(forEachDelta: suspend ((dragDelta: DragDelta) -> Unit) -> Unit) { @@ -206,7 +157,7 @@ private class AnchoredHorizontalDraggableNode( return consumed } } - with(resolvedFlingBehavior) { + with(flingBehavior) { leftoverVelocity = scrollScope.performFling(velocity) } } @@ -220,7 +171,7 @@ private class AnchoredHorizontalDraggableNode( canDrag: (Offset) -> Boolean, enabled: Boolean, startDragImmediately: Boolean, - flingBehavior: FlingBehavior?, + flingBehavior: FlingBehavior, ) { this.flingBehavior = flingBehavior @@ -228,7 +179,6 @@ private class AnchoredHorizontalDraggableNode( if (this.state != state) { this.state = state - updateFlingBehavior(flingBehavior) resetPointerInputHandling = true } @@ -248,132 +198,6 @@ private class AnchoredHorizontalDraggableNode( internal fun AnchoredDraggableState.newOffsetForDelta(delta: Float) = ((if (offset.isNaN()) 0f else offset) + delta) .coerceIn(anchors.minPosition(), anchors.maxPosition()) -/** - * Compute the target anchor based on the [currentOffset], [velocity] and [positionalThreshold] and - * [velocityThreshold]. - * - * @return The suggested target anchor - */ -@ExperimentalFoundationApi -private fun DraggableAnchors.computeTarget( - currentOffset: Float, - velocity: Float, - positionalThreshold: (totalDistance: Float) -> Float, - velocityThreshold: () -> Float, -): T { - val currentAnchors = this - require(!currentOffset.isNaN()) { "The offset provided to computeTarget must not be NaN." } - val velocitySign = sign(velocity) - val isMovingForward = velocitySign == 1.0f - val isMoving = isMovingForward || velocitySign == -1.0f - // When we're not moving, just pick the closest anchor and don't consider directionality - return if (!isMoving) { - currentAnchors.closestAnchor(currentOffset)!! - } else if (abs(velocity) >= abs(velocityThreshold())) { - currentAnchors.closestAnchor(currentOffset, searchUpwards = isMovingForward)!! - } else { - val left = currentAnchors.closestAnchor(currentOffset, false)!! - val leftAnchorPosition = currentAnchors.positionOf(left) - val right = currentAnchors.closestAnchor(currentOffset, true)!! - val rightAnchorPosition = currentAnchors.positionOf(right) - val distance = abs(leftAnchorPosition - rightAnchorPosition) - val relativeThreshold = abs(positionalThreshold(distance)) - val closestAnchorFromStart = - if (isMovingForward) leftAnchorPosition else rightAnchorPosition - val relativePosition = abs(closestAnchorFromStart - currentOffset) - if (relativePosition <= relativeThreshold) left else right - } -} - -// https://issuetracker.google.com/374241709 -@Composable -fun flingBehavior( - state: AnchoredDraggableState, - positionalThreshold: (totalDistance: Float) -> Float = AnchoredDraggableDefaults.PositionalThreshold, - animationSpec: AnimationSpec = AnchoredDraggableDefaults.SnapAnimationSpec, -): TargetedFlingBehavior { - val density = LocalDensity.current - return remember(density, state, positionalThreshold, animationSpec) { - anchoredDraggableFlingBehavior( - state = state, - density = density, - positionalThreshold = positionalThreshold, - snapAnimationSpec = animationSpec, - ) - } -} - -/** - * Construct a [FlingBehavior] for use with [Modifier.anchoredDraggable]. - * - * @param state The [AnchoredDraggableState] that will be used for the fling animation - * @param positionalThreshold A positional threshold that needs to be crossed in order to reach the - * next anchor when flinging, in pixels. This can be a derived from the distance that the lambda - * is invoked with. - * @param snapAnimationSpec The animation spec that will be used to snap to a new state. - */ -@ExperimentalFoundationApi -internal fun anchoredDraggableFlingBehavior( - state: AnchoredDraggableState, - density: Density, - positionalThreshold: (totalDistance: Float) -> Float, - snapAnimationSpec: AnimationSpec, -): TargetedFlingBehavior = snapFlingBehavior( - decayAnimationSpec = NoOpDecayAnimationSpec, - snapAnimationSpec = snapAnimationSpec, - snapLayoutInfoProvider = - AnchoredDraggableLayoutInfoProvider( - state = state, - positionalThreshold = positionalThreshold, - velocityThreshold = { with(density) { 125.dp.toPx() } }, - ), -) - -@Suppress("FunctionName") -@OptIn(ExperimentalFoundationApi::class) -private fun AnchoredDraggableLayoutInfoProvider( - state: AnchoredDraggableState, - positionalThreshold: (totalDistance: Float) -> Float, - velocityThreshold: () -> Float, -): SnapLayoutInfoProvider = object : SnapLayoutInfoProvider { - - // We never decay in AnchoredDraggable's fling - override fun calculateApproachOffset(velocity: Float, decayOffset: Float) = 0f - - override fun calculateSnapOffset(velocity: Float): Float { - val currentOffset = state.requireOffset() - val target = - state.anchors.computeTarget( - currentOffset = currentOffset, - velocity = velocity, - positionalThreshold = positionalThreshold, - velocityThreshold = velocityThreshold, - ) - return state.anchors.positionOf(target) - currentOffset - } -} - -private val NoOpDecayAnimationSpec: DecayAnimationSpec = - object : FloatDecayAnimationSpec { - override val absVelocityThreshold = 0f - - override fun getValueFromNanos( - playTimeNanos: Long, - initialValue: Float, - initialVelocity: Float, - ) = 0f - - override fun getDurationNanos(initialValue: Float, initialVelocity: Float) = 0L - - override fun getVelocityFromNanos( - playTimeNanos: Long, - initialValue: Float, - initialVelocity: Float, - ) = 0f - - override fun getTargetValue(initialValue: Float, initialVelocity: Float) = 0f - }.generateDecayAnimationSpec() - /** * This Modifier allows configuring an [AnchoredDraggableState]'s anchors based on this layout * node's size and offsetting it. diff --git a/app/src/main/kotlin/androidx/compose/material3/SideDrawer.kt b/app/src/main/kotlin/androidx/compose/material3/SideDrawer.kt index cd5777c65..f6f937725 100644 --- a/app/src/main/kotlin/androidx/compose/material3/SideDrawer.kt +++ b/app/src/main/kotlin/androidx/compose/material3/SideDrawer.kt @@ -7,11 +7,11 @@ import androidx.compose.animation.core.TweenSpec import androidx.compose.animation.core.animate import androidx.compose.foundation.Canvas import androidx.compose.foundation.background +import androidx.compose.foundation.gestures.AnchoredDraggableDefaults import androidx.compose.foundation.gestures.AnchoredDraggableState import androidx.compose.foundation.gestures.DraggableAnchors import androidx.compose.foundation.gestures.anchoredHorizontalDraggable import androidx.compose.foundation.gestures.detectTapGestures -import androidx.compose.foundation.gestures.flingBehavior import androidx.compose.foundation.gestures.snapTo import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize @@ -249,7 +249,7 @@ fun ModalSideDrawer( enableDragFromStartToEnd = drawerState.isOpen, enableDragFromEndToStart = drawerState.isClosed, enabled = gesturesEnabled, - flingBehavior = flingBehavior( + flingBehavior = AnchoredDraggableDefaults.flingBehavior( state = drawerState.anchoredDraggableState, animationSpec = AnimationSpec, ), diff --git a/app/src/main/kotlin/androidx/compose/material3/fork/SwipeToDismissBox.fork.kt b/app/src/main/kotlin/androidx/compose/material3/fork/SwipeToDismissBox.fork.kt index d3f151a1e..1f1d8a575 100644 --- a/app/src/main/kotlin/androidx/compose/material3/fork/SwipeToDismissBox.fork.kt +++ b/app/src/main/kotlin/androidx/compose/material3/fork/SwipeToDismissBox.fork.kt @@ -18,13 +18,13 @@ package androidx.compose.material3.fork import androidx.annotation.FloatRange import androidx.compose.animation.core.SpringSpec +import androidx.compose.foundation.gestures.AnchoredDraggableDefaults import androidx.compose.foundation.gestures.AnchoredDraggableState import androidx.compose.foundation.gestures.DraggableAnchors import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.anchoredHorizontalDraggable import androidx.compose.foundation.gestures.animateTo import androidx.compose.foundation.gestures.draggableAnchors -import androidx.compose.foundation.gestures.flingBehavior import androidx.compose.foundation.gestures.snapTo import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row @@ -186,7 +186,7 @@ fun SwipeToDismissBox( enableDragFromStartToEnd = enableDismissFromStartToEnd, enableDragFromEndToStart = enableDismissFromEndToStart, enabled = gesturesEnabled && state.currentValue == SwipeToDismissBoxValue.Settled, - flingBehavior = flingBehavior( + flingBehavior = AnchoredDraggableDefaults.flingBehavior( state = state.anchoredDraggableState, positionalThreshold = SwipeToDismissBoxDefaults.positionalThreshold, animationSpec = SnapAnimationSpec, diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt index f70771daf..73f2a84c4 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/GalleryList.kt @@ -84,7 +84,7 @@ fun GalleryList( modifier: Modifier = Modifier, data: LazyPagingItems, contentModifier: Modifier = Modifier, - contentPadding: PaddingValues = PaddingValues(0.dp), + contentPadding: PaddingValues = PaddingValues.Zero, listMode: Int, detailListState: LazyGridState = rememberLazyGridState(), detailItemContent: @Composable (LazyGridItemScope.(BaseGalleryInfo) -> Unit), diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/ReaderScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/ReaderScreen.kt index fcb272dc1..1869d4268 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/ReaderScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/ReaderScreen.kt @@ -49,6 +49,7 @@ import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.BlendMode import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerInput +import androidx.compose.ui.keepScreenOn import androidx.compose.ui.res.colorResource import androidx.core.view.WindowInsetsControllerCompat import arrow.core.Either @@ -75,8 +76,8 @@ import com.hippo.ehviewer.ui.Screen import com.hippo.ehviewer.ui.theme.EhTheme import com.hippo.ehviewer.ui.tools.Await import com.hippo.ehviewer.ui.tools.DialogState -import com.hippo.ehviewer.ui.tools.EmptyWindowInsets import com.hippo.ehviewer.ui.tools.asyncInVM +import com.hippo.ehviewer.ui.tools.thenIf import com.hippo.ehviewer.util.displayString import com.hippo.ehviewer.util.hasAds import com.hippo.files.toOkioPath @@ -176,7 +177,6 @@ fun AnimatedVisibilityScope.ReaderScreen(args: ReaderScreenArgs, navigator: Dest context(MainActivity, SnackbarHostState, DialogState, CoroutineScope) @Composable fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalleryInfo?) { - ConfigureKeepScreenOn() LaunchedEffect(Unit) { val orientation = requestedOrientation Settings.orientationMode.valueFlow() @@ -195,6 +195,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle val reverseControls by Settings.readerReverseControls.collectAsState() val fullscreen by Settings.fullscreen.collectAsState() val cutoutShort by Settings.cutoutShort.collectAsState() + val keepScreenOn by Settings.keepScreenOn.collectAsState() val uiController = rememberSystemUiController() DisposableEffect(uiController) { uiController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE @@ -223,7 +224,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle if (isWebtoon) lazyListState.scrollDown() else pagerState.moveToNext() } }, - ).focusRequester(focusRequester).focusable(), + ).focusRequester(focusRequester).focusable().thenIf(keepScreenOn) { keepScreenOn() }, ) { LaunchedEffect(Unit) { focusRequester.requestFocus() @@ -256,7 +257,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle onDismissRequest = { dispose() }, modifier = Modifier.windowInsetsPadding(WindowInsets.safeDrawing.only(WindowInsetsSides.Top)), sheetState = state, - contentWindowInsets = { EmptyWindowInsets }, + contentWindowInsets = { WindowInsets() }, ) { ReaderPageSheetMeta( retry = { pageLoader.retryPage(page.index) }, @@ -276,7 +277,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle EhTheme(useDarkTheme = bgColor != Color.White) { val insets = if (fullscreen) { if (cutoutShort) { - EmptyWindowInsets + WindowInsets() } else { WindowInsets.displayCutout } @@ -360,7 +361,7 @@ fun AnimatedVisibilityScope.ReaderScreen(pageLoader: PageLoader, info: BaseGalle // Yeah, I know color state should not be read here, but we have to do it... scrimColor = scrim, dragHandle = null, - contentWindowInsets = { EmptyWindowInsets }, + contentWindowInsets = { WindowInsets() }, ) { SettingsPager(modifier = Modifier.fillMaxSize()) { page -> isColorFilter = page == 2 diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/Utils.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/Utils.kt index 8184b762c..7e9672f05 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/Utils.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/reader/Utils.kt @@ -1,14 +1,11 @@ package com.hippo.ehviewer.ui.reader import android.app.Activity -import android.view.Window import android.view.WindowManager import androidx.compose.foundation.gestures.animateScrollBy import androidx.compose.foundation.gestures.scrollBy import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.pager.PagerState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.Stable import androidx.compose.ui.AbsoluteAlignment import androidx.compose.ui.Alignment @@ -17,24 +14,6 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.FixedScale import com.hippo.ehviewer.Settings import eu.kanade.tachiyomi.ui.reader.setting.OrientationType -import kotlinx.coroutines.flow.onCompletion - -fun Window.updateKeepScreenOn(enabled: Boolean) { - if (enabled) { - addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - } else { - clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - } -} - -@Composable -fun Activity.ConfigureKeepScreenOn() { - LaunchedEffect(Unit) { - Settings.keepScreenOn.valueFlow() - .onCompletion { window.updateKeepScreenOn(false) } - .collect { window.updateKeepScreenOn(it) } - } -} /** * Forces the user preferred [orientation] on the activity. diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/DownloadsScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/DownloadsScreen.kt index c48dd41d4..1134aa238 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/DownloadsScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/DownloadsScreen.kt @@ -109,7 +109,6 @@ import com.hippo.ehviewer.ui.navToReader import com.hippo.ehviewer.ui.showMoveDownloadLabelList import com.hippo.ehviewer.ui.tools.Await import com.hippo.ehviewer.ui.tools.DialogState -import com.hippo.ehviewer.ui.tools.EmptyWindowInsets import com.hippo.ehviewer.ui.tools.FastScrollLazyColumn import com.hippo.ehviewer.ui.tools.FastScrollLazyVerticalStaggeredGrid import com.hippo.ehviewer.ui.tools.HapticFeedbackType @@ -220,7 +219,7 @@ fun AnimatedVisibilityScope.DownloadsScreen(navigator: DestinationsNavigator) = fun closeSheet() = launch { drawerState.close() } TopAppBar( title = { Text(text = labelsStr) }, - windowInsets = EmptyWindowInsets, + windowInsets = WindowInsets(), colors = topBarOnDrawerColor(), actions = { if (DownloadsFilterMode.CUSTOM == filterMode) { diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/FavoritesScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/FavoritesScreen.kt index 51dcb16c1..083018972 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/FavoritesScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/FavoritesScreen.kt @@ -79,7 +79,6 @@ import com.hippo.ehviewer.ui.main.GalleryInfoGridItem import com.hippo.ehviewer.ui.main.GalleryInfoListItem import com.hippo.ehviewer.ui.main.GalleryList import com.hippo.ehviewer.ui.startDownload -import com.hippo.ehviewer.ui.tools.EmptyWindowInsets import com.hippo.ehviewer.ui.tools.asyncState import com.hippo.ehviewer.ui.tools.foldToLoadResult import com.hippo.ehviewer.ui.tools.rememberInVM @@ -191,7 +190,7 @@ fun AnimatedVisibilityScope.FavouritesScreen(navigator: DestinationsNavigator) = val localFavCount by localFavCountFlow.collectAsState(0) TopAppBar( title = { Text(text = stringResource(id = R.string.collections)) }, - windowInsets = EmptyWindowInsets, + windowInsets = WindowInsets(), colors = topBarOnDrawerColor(), ) val scope = currentRecomposeScope diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt index e8136693f..a89561ab2 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryDetailContent.kt @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height @@ -116,7 +117,6 @@ import com.hippo.ehviewer.ui.openBrowser import com.hippo.ehviewer.ui.startDownload import com.hippo.ehviewer.ui.tools.CrystalCard import com.hippo.ehviewer.ui.tools.DialogState -import com.hippo.ehviewer.ui.tools.EmptyWindowInsets import com.hippo.ehviewer.ui.tools.FastScrollLazyVerticalGrid import com.hippo.ehviewer.ui.tools.FilledTertiaryIconButton import com.hippo.ehviewer.ui.tools.FilledTertiaryIconToggleButton @@ -213,7 +213,7 @@ fun GalleryDetailContent( dialog { cont -> ModalBottomSheet( onDismissRequest = { cont.cancel() }, - contentWindowInsets = { EmptyWindowInsets }, + contentWindowInsets = { WindowInsets() }, ) { GalleryInfoBottomSheet(galleryDetail) } diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt index bf7190029..243a42eec 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/screen/GalleryListScreen.kt @@ -111,7 +111,6 @@ import com.hippo.ehviewer.ui.main.GalleryList import com.hippo.ehviewer.ui.main.SearchFilter import com.hippo.ehviewer.ui.tools.Await import com.hippo.ehviewer.ui.tools.DialogState -import com.hippo.ehviewer.ui.tools.EmptyWindowInsets import com.hippo.ehviewer.ui.tools.FastScrollLazyColumn import com.hippo.ehviewer.ui.tools.HapticFeedbackType import com.hippo.ehviewer.ui.tools.asyncState @@ -252,7 +251,7 @@ fun AnimatedVisibilityScope.GalleryListScreen(lub: ListUrlBuilder, navigator: De ProvideSideSheetContent { sheetState -> TopAppBar( title = { Text(text = stringResource(id = R.string.toplist)) }, - windowInsets = EmptyWindowInsets, + windowInsets = WindowInsets(), colors = topBarOnDrawerColor(), ) toplists.forEach { (name, keyword) -> @@ -343,7 +342,7 @@ fun AnimatedVisibilityScope.GalleryListScreen(lub: ListUrlBuilder, navigator: De ) } }, - windowInsets = EmptyWindowInsets, + windowInsets = WindowInsets(), ) Box(modifier = Modifier.fillMaxSize()) { val dialogState by rememberUpdatedState(implicit()) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyGrid.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyGrid.kt index 462eb94a8..eac210016 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyGrid.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyGrid.kt @@ -25,7 +25,7 @@ fun FastScrollLazyVerticalGrid( columns: GridCells, modifier: Modifier = Modifier, state: LazyGridState = rememberLazyGridState(), - contentPadding: PaddingValues = PaddingValues(0.dp), + contentPadding: PaddingValues = PaddingValues.Zero, reverseLayout: Boolean = false, verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom, horizontalArrangement: Arrangement.Horizontal = Arrangement.Start, @@ -59,7 +59,7 @@ fun FastScrollLazyVerticalStaggeredGrid( columns: StaggeredGridCells, modifier: Modifier = Modifier, state: LazyStaggeredGridState = rememberLazyStaggeredGridState(), - contentPadding: PaddingValues = PaddingValues(0.dp), + contentPadding: PaddingValues = PaddingValues.Zero, reverseLayout: Boolean = false, verticalItemSpacing: Dp = 0.dp, horizontalArrangement: Arrangement.Horizontal = Arrangement.Start, diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyList.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyList.kt index 04fa9b0fe..06bda2f99 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyList.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/LazyList.kt @@ -12,13 +12,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.layout.Layout import androidx.compose.ui.unit.IntOffset -import androidx.compose.ui.unit.dp @Composable fun FastScrollLazyColumn( modifier: Modifier = Modifier, state: LazyListState = rememberLazyListState(), - contentPadding: PaddingValues = PaddingValues(0.dp), + contentPadding: PaddingValues = PaddingValues.Zero, reverseLayout: Boolean = false, verticalArrangement: Arrangement.Vertical = if (!reverseLayout) Arrangement.Top else Arrangement.Bottom, horizontalAlignment: Alignment.Horizontal = Alignment.Start, diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/VerticalScrollbar.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/VerticalScrollbar.kt index 5ca3024f2..6f500d229 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/VerticalScrollbar.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/VerticalScrollbar.kt @@ -30,7 +30,7 @@ fun VerticalScrollbar( adapter: ScrollbarAdapter, isScrollInProgress: Boolean, modifier: Modifier = Modifier, - contentPadding: PaddingValues = PaddingValues(0.dp), + contentPadding: PaddingValues = PaddingValues.Zero, reverseLayout: Boolean = false, ) { val isScrolling by rememberUpdatedState(isScrollInProgress) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/WindowInsets.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/WindowInsets.kt deleted file mode 100644 index cccf0b66c..000000000 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/tools/WindowInsets.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.hippo.ehviewer.ui.tools - -import androidx.compose.foundation.layout.WindowInsets - -val EmptyWindowInsets = WindowInsets(0, 0, 0, 0)