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 ->
|
||||
when (direction) {
|
||||
PadCanvasView.SwipeDirection.LEFT -> viewModel.navigateNext()
|
||||
PadCanvasView.SwipeDirection.RIGHT -> viewModel.navigatePrev()
|
||||
PadCanvasView.SwipeDirection.NEXT -> viewModel.navigateNext()
|
||||
PadCanvasView.SwipeDirection.PREV -> viewModel.navigatePrev()
|
||||
}
|
||||
}
|
||||
viewModel.onStrokeAdded = { stroke ->
|
||||
|
||||
@@ -110,7 +110,10 @@ class PadCanvasView(context: Context) : View(context) {
|
||||
private var moveOriginX = 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 ---
|
||||
private var zoom = 1f
|
||||
@@ -793,7 +796,7 @@ class PadCanvasView(context: Context) : View(context) {
|
||||
fingerDownY = event.y
|
||||
// Detect if finger started at screen edge
|
||||
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 -> {
|
||||
if (!scaleGestureDetector.isInProgress && event.pointerCount == 1) {
|
||||
@@ -818,13 +821,9 @@ class PadCanvasView(context: Context) : View(context) {
|
||||
val dy = event.y - fingerDownY
|
||||
val absDx = Math.abs(dx)
|
||||
val absDy = Math.abs(dy)
|
||||
if (absDx > EDGE_SWIPE_MIN_PX && absDx > absDy * 2) {
|
||||
// Horizontal swipe detected
|
||||
if (dx < 0) {
|
||||
onEdgeSwipe?.invoke(SwipeDirection.LEFT)
|
||||
} else {
|
||||
onEdgeSwipe?.invoke(SwipeDirection.RIGHT)
|
||||
}
|
||||
if (absDx > EDGE_SWIPE_MIN_PX && absDx > absDy * 2 && dx < 0) {
|
||||
// Swipe left from right edge = next page
|
||||
onEdgeSwipe?.invoke(SwipeDirection.NEXT)
|
||||
}
|
||||
}
|
||||
isEdgeSwipe = false
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.metacircular.engpad.ui.navigation
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.key
|
||||
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 selectedPageId by savedState.getStateFlow("selectedPageId", 0L)
|
||||
.collectAsState()
|
||||
LaunchedEffect(selectedPageId) {
|
||||
if (selectedPageId > 0) {
|
||||
val selectedPageId = savedState.get<Long>("selectedPageId")
|
||||
if (selectedPageId != null && selectedPageId > 0) {
|
||||
initialPageId = selectedPageId
|
||||
savedState["selectedPageId"] = 0L
|
||||
}
|
||||
savedState.remove<Long>("selectedPageId")
|
||||
}
|
||||
|
||||
val ps = pageSize
|
||||
|
||||
Reference in New Issue
Block a user