Fix edge swipe and page list navigation
Edge swipe: - Only detect from RIGHT edge (swipe left = next page) - Left edge no longer triggers page nav (avoids conflict with system back gesture) - Previous page navigation via binder dropdown or system back only Page list navigation: - Simplified selectedPageId handling — read and clear synchronously during recomposition instead of async StateFlow observation - Fixes issue where clicking a page in view-all-pages went to last visited page instead of the selected one Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -85,8 +85,8 @@ fun EditorScreen(
|
|||||||
}
|
}
|
||||||
canvasView.onEdgeSwipe = { direction ->
|
canvasView.onEdgeSwipe = { direction ->
|
||||||
when (direction) {
|
when (direction) {
|
||||||
PadCanvasView.SwipeDirection.LEFT -> viewModel.navigateNext()
|
PadCanvasView.SwipeDirection.NEXT -> viewModel.navigateNext()
|
||||||
PadCanvasView.SwipeDirection.RIGHT -> viewModel.navigatePrev()
|
PadCanvasView.SwipeDirection.PREV -> viewModel.navigatePrev()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.onStrokeAdded = { stroke ->
|
viewModel.onStrokeAdded = { stroke ->
|
||||||
|
|||||||
@@ -110,7 +110,10 @@ class PadCanvasView(context: Context) : View(context) {
|
|||||||
private var moveOriginX = 0f
|
private var moveOriginX = 0f
|
||||||
private var moveOriginY = 0f
|
private var moveOriginY = 0f
|
||||||
|
|
||||||
enum class SwipeDirection { LEFT, RIGHT }
|
enum class SwipeDirection {
|
||||||
|
NEXT, // Swipe from right edge toward left = next page
|
||||||
|
PREV, // Swipe from left edge toward right = prev page
|
||||||
|
}
|
||||||
|
|
||||||
// --- Zoom/pan state ---
|
// --- Zoom/pan state ---
|
||||||
private var zoom = 1f
|
private var zoom = 1f
|
||||||
@@ -793,7 +796,7 @@ class PadCanvasView(context: Context) : View(context) {
|
|||||||
fingerDownY = event.y
|
fingerDownY = event.y
|
||||||
// Detect if finger started at screen edge
|
// Detect if finger started at screen edge
|
||||||
val edgeZone = width * EDGE_ZONE_FRACTION
|
val edgeZone = width * EDGE_ZONE_FRACTION
|
||||||
isEdgeSwipe = event.x < edgeZone || event.x > width - edgeZone
|
isEdgeSwipe = event.x > width - edgeZone // Only right edge for next page
|
||||||
}
|
}
|
||||||
MotionEvent.ACTION_MOVE -> {
|
MotionEvent.ACTION_MOVE -> {
|
||||||
if (!scaleGestureDetector.isInProgress && event.pointerCount == 1) {
|
if (!scaleGestureDetector.isInProgress && event.pointerCount == 1) {
|
||||||
@@ -818,13 +821,9 @@ class PadCanvasView(context: Context) : View(context) {
|
|||||||
val dy = event.y - fingerDownY
|
val dy = event.y - fingerDownY
|
||||||
val absDx = Math.abs(dx)
|
val absDx = Math.abs(dx)
|
||||||
val absDy = Math.abs(dy)
|
val absDy = Math.abs(dy)
|
||||||
if (absDx > EDGE_SWIPE_MIN_PX && absDx > absDy * 2) {
|
if (absDx > EDGE_SWIPE_MIN_PX && absDx > absDy * 2 && dx < 0) {
|
||||||
// Horizontal swipe detected
|
// Swipe left from right edge = next page
|
||||||
if (dx < 0) {
|
onEdgeSwipe?.invoke(SwipeDirection.NEXT)
|
||||||
onEdgeSwipe?.invoke(SwipeDirection.LEFT)
|
|
||||||
} else {
|
|
||||||
onEdgeSwipe?.invoke(SwipeDirection.RIGHT)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isEdgeSwipe = false
|
isEdgeSwipe = false
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package net.metacircular.engpad.ui.navigation
|
|||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.collectAsState
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.key
|
import androidx.compose.runtime.key
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -92,15 +91,12 @@ fun EngPadNavGraph(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Observe page selection from the page list screen
|
// Check for page selection from the page list screen
|
||||||
val savedState = backStackEntry.savedStateHandle
|
val savedState = backStackEntry.savedStateHandle
|
||||||
val selectedPageId by savedState.getStateFlow("selectedPageId", 0L)
|
val selectedPageId = savedState.get<Long>("selectedPageId")
|
||||||
.collectAsState()
|
if (selectedPageId != null && selectedPageId > 0) {
|
||||||
LaunchedEffect(selectedPageId) {
|
|
||||||
if (selectedPageId > 0) {
|
|
||||||
initialPageId = selectedPageId
|
initialPageId = selectedPageId
|
||||||
savedState["selectedPageId"] = 0L
|
savedState.remove<Long>("selectedPageId")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val ps = pageSize
|
val ps = pageSize
|
||||||
|
|||||||
Reference in New Issue
Block a user