Prepare pull down scaffold for gesture detection
This commit is contained in:
parent
4179172b0b
commit
deb5e0d9e7
@ -9,14 +9,13 @@ class GestureManager {
|
|||||||
private var currentDrag : Offset? = null
|
private var currentDrag : Offset? = null
|
||||||
|
|
||||||
fun reportDoubleTap(position: Offset) {
|
fun reportDoubleTap(position: Offset) {
|
||||||
Log.d("MM20", "double tap: $position")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reportLongPress(position: Offset) {
|
fun reportLongPress(position: Offset) {
|
||||||
Log.d("MM20", "long press: $position")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reportDrag(offset: Offset) {
|
fun reportDrag(offset: Offset) {
|
||||||
|
currentDrag = (currentDrag ?: Offset.Zero) + offset
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reportDragEnd() {
|
fun reportDragEnd() {
|
||||||
|
|||||||
@ -7,6 +7,11 @@ import androidx.compose.animation.core.animateFloatAsState
|
|||||||
import androidx.compose.animation.slideIn
|
import androidx.compose.animation.slideIn
|
||||||
import androidx.compose.animation.slideOut
|
import androidx.compose.animation.slideOut
|
||||||
import androidx.compose.foundation.LocalOverscrollConfiguration
|
import androidx.compose.foundation.LocalOverscrollConfiguration
|
||||||
|
import androidx.compose.foundation.gestures.Orientation
|
||||||
|
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
||||||
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
|
import androidx.compose.foundation.gestures.scrollable
|
||||||
|
import androidx.compose.foundation.horizontalScroll
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -51,6 +56,7 @@ import androidx.compose.ui.graphics.graphicsLayer
|
|||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
@ -63,6 +69,7 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
|||||||
import de.mm20.launcher2.preferences.Settings
|
import de.mm20.launcher2.preferences.Settings
|
||||||
import de.mm20.launcher2.ui.R
|
import de.mm20.launcher2.ui.R
|
||||||
import de.mm20.launcher2.ui.component.SearchBarLevel
|
import de.mm20.launcher2.ui.component.SearchBarLevel
|
||||||
|
import de.mm20.launcher2.ui.gestures.LocalGestureManager
|
||||||
import de.mm20.launcher2.ui.ktx.animateTo
|
import de.mm20.launcher2.ui.ktx.animateTo
|
||||||
import de.mm20.launcher2.ui.launcher.helper.WallpaperBlur
|
import de.mm20.launcher2.ui.launcher.helper.WallpaperBlur
|
||||||
import de.mm20.launcher2.ui.launcher.search.SearchColumn
|
import de.mm20.launcher2.ui.launcher.search.SearchColumn
|
||||||
@ -241,6 +248,7 @@ fun PullDownScaffold(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val keyboardController = LocalSoftwareKeyboardController.current
|
val keyboardController = LocalSoftwareKeyboardController.current
|
||||||
|
val gestureManager = LocalGestureManager.current
|
||||||
|
|
||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
@ -272,21 +280,24 @@ fun PullDownScaffold(
|
|||||||
else -> 0f
|
else -> 0f
|
||||||
}
|
}
|
||||||
|
|
||||||
val deltaSearchBarOffset = (available.y - consumed) * if (reverseSearchResults && isSearchOpen) -1f else 1f
|
|
||||||
|
|
||||||
searchBarOffset.value =
|
|
||||||
(searchBarOffset.value + deltaSearchBarOffset).coerceIn(
|
|
||||||
-maxSearchBarOffset,
|
|
||||||
0f
|
|
||||||
)
|
|
||||||
|
|
||||||
return Offset(0f, consumed)
|
return Offset(0f, consumed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPostScroll(
|
||||||
|
consumed: Offset,
|
||||||
|
available: Offset,
|
||||||
|
source: NestedScrollSource
|
||||||
|
): Offset {
|
||||||
|
val deltaSearchBarOffset = consumed.y * if (isSearchOpen && reverseSearchResults) 1 else -1
|
||||||
|
searchBarOffset.value = (searchBarOffset.value + deltaSearchBarOffset).coerceIn(0f, maxSearchBarOffset)
|
||||||
|
return super.onPostScroll(consumed, available, source)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun onPreFling(available: Velocity): Velocity {
|
override suspend fun onPreFling(available: Velocity): Velocity {
|
||||||
if (offsetY.value > toggleSearchThreshold || offsetY.value < -toggleSearchThreshold) {
|
if (offsetY.value > toggleSearchThreshold || offsetY.value < -toggleSearchThreshold) {
|
||||||
viewModel.toggleSearch()
|
viewModel.toggleSearch()
|
||||||
}
|
}
|
||||||
|
gestureManager.reportDragEnd()
|
||||||
if (offsetY.value != 0f) {
|
if (offsetY.value != 0f) {
|
||||||
offsetY.animateTo(0f)
|
offsetY.animateTo(0f)
|
||||||
return available
|
return available
|
||||||
@ -299,6 +310,16 @@ fun PullDownScaffold(
|
|||||||
val insets = WindowInsets.safeDrawing.asPaddingValues()
|
val insets = WindowInsets.safeDrawing.asPaddingValues()
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
|
.pointerInput(Unit) {
|
||||||
|
detectHorizontalDragGestures(
|
||||||
|
onDragEnd = {
|
||||||
|
gestureManager.reportDragEnd()
|
||||||
|
},
|
||||||
|
onHorizontalDrag = { _, dragAmount ->
|
||||||
|
gestureManager.reportDrag(Offset(dragAmount, 0f))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
.nestedScroll(nestedScrollConnection)
|
.nestedScroll(nestedScrollConnection)
|
||||||
.offset { IntOffset(0, offsetY.value.toInt()) },
|
.offset { IntOffset(0, offsetY.value.toInt()) },
|
||||||
contentAlignment = Alignment.TopCenter
|
contentAlignment = Alignment.TopCenter
|
||||||
@ -375,6 +396,16 @@ fun PullDownScaffold(
|
|||||||
scaleY = 1 - offset
|
scaleY = 1 - offset
|
||||||
alpha = 1 - offset
|
alpha = 1 - offset
|
||||||
}
|
}
|
||||||
|
.pointerInput(Unit) {
|
||||||
|
detectTapGestures(
|
||||||
|
onDoubleTap = {
|
||||||
|
gestureManager.reportDoubleTap(it)
|
||||||
|
},
|
||||||
|
onLongPress = {
|
||||||
|
gestureManager.reportLongPress(it)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.requiredHeight(height)
|
.requiredHeight(height)
|
||||||
.verticalScroll(widgetsScrollState)
|
.verticalScroll(widgetsScrollState)
|
||||||
@ -461,7 +492,7 @@ fun PullDownScaffold(
|
|||||||
.offset {
|
.offset {
|
||||||
IntOffset(
|
IntOffset(
|
||||||
0,
|
0,
|
||||||
if (searchBarFocused) 0 else searchBarOffset.value.toInt() * (if (bottomSearchBar) -1 else 1)
|
if (searchBarFocused) 0 else searchBarOffset.value.toInt() * (if (bottomSearchBar) 1 else -1)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.offset {
|
.offset {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user