Fix! vertical scroll by locking scroll mode once vertical scroll is initiated
This commit is contained in:
parent
faa7119556
commit
aaec06944c
1 changed files with 95 additions and 61 deletions
|
|
@ -3,23 +3,20 @@ package mg.dot.feufaro
|
||||||
import SharedScreenModel
|
import SharedScreenModel
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
|
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
|
import androidx.compose.material.icons.automirrored.filled.PlaylistAdd
|
||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.*
|
||||||
import androidx.compose.material.icons.filled.Code
|
|
||||||
import androidx.compose.material.icons.filled.Favorite
|
|
||||||
import androidx.compose.material.icons.filled.FavoriteBorder
|
|
||||||
import androidx.compose.material.icons.filled.PlaylistRemove
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
|
@ -140,11 +137,15 @@ object ScreenSolfa : Screen {
|
||||||
qrCodeResult = qrCodeResult,
|
qrCodeResult = qrCodeResult,
|
||||||
solfaScrollState = scrollState
|
solfaScrollState = scrollState
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
|
var screenWidthPx by remember { mutableStateOf(0) }
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
.padding(horizontal = 16.dp)
|
.padding(horizontal = 16.dp)
|
||||||
|
.onGloballyPositioned { coordinates ->
|
||||||
|
screenWidthPx = coordinates.size.width
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
|
|
@ -161,85 +162,118 @@ object ScreenSolfa : Screen {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.pointerInput(stanza, allowedStanzas, activeFilePath) {
|
.pointerInput(stanza, allowedStanzas, activeFilePath, screenWidthPx) {
|
||||||
awaitPointerEventScope {
|
awaitPointerEventScope {
|
||||||
while (true) {
|
while (true) {
|
||||||
val event = awaitPointerEvent()
|
val initialEvent = awaitPointerEvent()
|
||||||
val pressed = event.changes.filter { it.pressed }
|
val pressedChanges = initialEvent.changes.filter { it.pressed }
|
||||||
if (pressed.isEmpty()) continue
|
if (pressedChanges.isEmpty()) continue
|
||||||
|
|
||||||
val isTwoFingers = pressed.size >= 2
|
val initialFingerCount = pressedChanges.size
|
||||||
val startX = if (isTwoFingers) (pressed[0].position.x + pressed[1].position.x) / 2f else pressed[0].position.x
|
val primaryChange = pressedChanges.first()
|
||||||
val startY = if (isTwoFingers) (pressed[0].position.y + pressed[1].position.y) / 2f else pressed[0].position.y
|
val startPos = primaryChange.position
|
||||||
|
|
||||||
var currentX = startX
|
if (startPos.x < 60f) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentX = startPos.x
|
||||||
|
var currentY = startPos.y
|
||||||
|
|
||||||
|
var dragging = false
|
||||||
var isHorizontalDrag = false
|
var isHorizontalDrag = false
|
||||||
|
var isVerticalDrag = false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isTwoFingers) pressed.forEach { it.consume() }
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
val moveEvent = awaitPointerEvent()
|
val moveEvent = awaitPointerEvent()
|
||||||
val movePressed = moveEvent.changes.filter { it.pressed }
|
val movePressed = moveEvent.changes.filter { it.pressed }
|
||||||
|
if (movePressed.isEmpty()) break
|
||||||
|
|
||||||
if (isTwoFingers && movePressed.size < 2) break
|
val primaryMove = movePressed.firstOrNull { it.id == primaryChange.id } ?: movePressed.first()
|
||||||
if (!isTwoFingers && movePressed.size != 1) break
|
currentX = primaryMove.position.x
|
||||||
|
currentY = primaryMove.position.y
|
||||||
|
|
||||||
currentX = if (isTwoFingers) {
|
val diffX = kotlin.math.abs(currentX - startPos.x)
|
||||||
(movePressed[0].position.x + movePressed[1].position.x) / 2f
|
val diffY = kotlin.math.abs(currentY - startPos.y)
|
||||||
} else {
|
|
||||||
movePressed.first().position.x
|
|
||||||
}
|
|
||||||
|
|
||||||
val currentY = if (isTwoFingers) {
|
if (diffX > 25f || diffY > 25f) {
|
||||||
(movePressed[0].position.y + movePressed[1].position.y) / 2f
|
dragging = true
|
||||||
} else {
|
if (diffX > diffY * 5.0f) {
|
||||||
movePressed.first().position.y
|
|
||||||
}
|
|
||||||
|
|
||||||
val diffX = kotlin.math.abs(currentX - startX)
|
|
||||||
val diffY = kotlin.math.abs(currentY - startY)
|
|
||||||
|
|
||||||
if (diffX > 15f || diffY > 15f) {
|
|
||||||
if (diffX > diffY) {
|
|
||||||
isHorizontalDrag = true
|
isHorizontalDrag = true
|
||||||
if (isTwoFingers) movePressed.forEach { it.consume() }
|
// println("DEBUG GESTURE -> HORIZONTAL dragging détecté (diffX: $diffX, diffY: $diffY)")
|
||||||
else movePressed.first().consume()
|
|
||||||
} else {
|
} else {
|
||||||
|
isVerticalDrag = true
|
||||||
|
// println("DEBUG GESTURE -> VERTICAL dragging : libération totale pour le scroll")
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dragging && isVerticalDrag) {
|
||||||
|
// println("DEBUG GESTURE -> VERTICAL dragging : libération totale, attente de la levée du doigt...")
|
||||||
|
while (true) {
|
||||||
|
val releaseEvent = awaitPointerEvent()
|
||||||
|
if (releaseEvent.changes.all { !it.pressed }) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {}
|
|
||||||
|
|
||||||
if (isHorizontalDrag) {
|
if (dragging && isHorizontalDrag) {
|
||||||
val totalDragX = currentX - startX
|
// println("DEBUG GESTURE -> HORIZONTAL dragging détecté")
|
||||||
val threshold = 70f
|
primaryChange.consume()
|
||||||
|
|
||||||
if (isTwoFingers) {
|
while (true) {
|
||||||
val path = when {
|
val dragEvent = awaitPointerEvent()
|
||||||
totalDragX < -threshold -> sharedScreenModel.getNextPlaylistItemPath()
|
val dragPressed = dragEvent.changes.filter { it.pressed }
|
||||||
totalDragX > threshold -> sharedScreenModel.getPrevPlaylistItemPath()
|
if (dragPressed.isEmpty()) {
|
||||||
else -> null
|
val totalDragX = currentX - startPos.x
|
||||||
}
|
val threshold = screenWidthPx * 0.30f
|
||||||
if (!path.isNullOrBlank()) {
|
|
||||||
sharedScreenModel.reset()
|
// println("DEBUG END DRAG -> totalDragX: ${totalDragX}f, threshold requis: ${threshold}f")
|
||||||
solfaScreenModel.loadFromFile(path)
|
|
||||||
}
|
if (screenWidthPx > 0 && kotlin.math.abs(totalDragX) >= threshold) {
|
||||||
} else {
|
if (initialFingerCount >= 2) {
|
||||||
val currentStanza = stanza.toString().toIntOrNull() ?: 1
|
// println("ACTION -> Changement de playlist (2 doigts)")
|
||||||
val target = when {
|
val path = if (totalDragX < 0) {
|
||||||
totalDragX < -threshold -> sharedScreenModel.nextAllowedStanza(currentStanza)
|
sharedScreenModel.getNextPlaylistItemPath()
|
||||||
totalDragX > threshold -> sharedScreenModel.prevAllowedStanza(currentStanza)
|
} else {
|
||||||
else -> null
|
sharedScreenModel.getPrevPlaylistItemPath()
|
||||||
}
|
}
|
||||||
if (target != null) {
|
if (!path.isNullOrBlank()) {
|
||||||
sharedScreenModel.setStanza(target)
|
sharedScreenModel.reset()
|
||||||
coroutineScope.launch {
|
solfaScreenModel.loadFromFile(path)
|
||||||
scrollState.animateScrollTo(0)
|
}
|
||||||
|
} else {
|
||||||
|
// println("ACTION -> Changement de stanza (1 doigt)")
|
||||||
|
val currentStanza = stanza.toString().toIntOrNull() ?: 1
|
||||||
|
val target = if (totalDragX < 0) {
|
||||||
|
sharedScreenModel.nextAllowedStanza(currentStanza)
|
||||||
|
} else {
|
||||||
|
sharedScreenModel.prevAllowedStanza(currentStanza)
|
||||||
|
}
|
||||||
|
if (target != null) {
|
||||||
|
sharedScreenModel.setStanza(target)
|
||||||
|
coroutineScope.launch {
|
||||||
|
scrollState.animateScrollTo(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// println("ACTION IGNORÉE -> Le drag n'a pas atteint les 30% de l'écran.")
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val primaryDrag = dragPressed.firstOrNull { it.id == primaryChange.id } ?: dragPressed.first()
|
||||||
|
currentX = primaryDrag.position.x
|
||||||
|
primaryDrag.consume()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// println("DEBUG EXCEPTION -> ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue