Fix scroll issue in PullDownScaffold

Fix #77
This commit is contained in:
MM20 2022-05-23 21:38:51 +02:00
parent ff2c293ba6
commit eecc676c4b
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -1,5 +1,6 @@
package de.mm20.launcher2.ui.launcher package de.mm20.launcher2.ui.launcher
import android.util.Log
import androidx.activity.compose.BackHandler import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateDpAsState
@ -141,17 +142,16 @@ fun PullDownScaffold(
object : NestedScrollConnection { object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
if (isWidgetEditMode) return Offset.Zero if (isWidgetEditMode) return Offset.Zero
val diff = val value = if (isSearchOpen) searchScrollState.value else widgetsScrollState.value
(if (isSearchOpen) searchScrollState.value else widgetsScrollState.value) - available.y val newValue = value - available.y
val consumed = when { val consumed = when {
(offsetY.value > 0 || source == NestedScrollSource.Drag && diff < 0) -> { (offsetY.value > 0 || source == NestedScrollSource.Drag && newValue < 0) -> {
val consumed = -diff val consumed = available.y - value
offsetY.value = (offsetY.value + (consumed * 0.5f)).coerceIn(0f, maxOffset) offsetY.value = (offsetY.value + (consumed * 0.5f)).coerceIn(0f, maxOffset)
consumed consumed
} }
isSearchOpen && (offsetY.value < 0 || source == NestedScrollSource.Drag && diff > searchScrollState.maxValue) -> { isSearchOpen && (offsetY.value < 0 || source == NestedScrollSource.Drag && newValue > searchScrollState.maxValue) -> {
val consumed = val consumed = available.y - (value- searchScrollState.maxValue)
available.y - (searchScrollState.maxValue - searchScrollState.value)
offsetY.value = (offsetY.value + (consumed * 0.5f)).coerceIn(-maxOffset, 0f) offsetY.value = (offsetY.value + (consumed * 0.5f)).coerceIn(-maxOffset, 0f)
consumed consumed
} }