From 2cc445a30d3aa671e33db95c5930ca9079236824 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 24 Mar 2026 18:38:43 -0700 Subject: [PATCH] Fix edge swipe and page list navigation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../engpad/ui/editor/EditorScreen.kt | 4 ++-- .../engpad/ui/editor/PadCanvasView.kt | 17 ++++++++--------- .../engpad/ui/navigation/NavGraph.kt | 14 +++++--------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorScreen.kt b/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorScreen.kt index bd72f9e..4c3e97e 100644 --- a/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorScreen.kt +++ b/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorScreen.kt @@ -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 -> diff --git a/app/src/main/kotlin/net/metacircular/engpad/ui/editor/PadCanvasView.kt b/app/src/main/kotlin/net/metacircular/engpad/ui/editor/PadCanvasView.kt index e8e1702..890b7ea 100644 --- a/app/src/main/kotlin/net/metacircular/engpad/ui/editor/PadCanvasView.kt +++ b/app/src/main/kotlin/net/metacircular/engpad/ui/editor/PadCanvasView.kt @@ -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 diff --git a/app/src/main/kotlin/net/metacircular/engpad/ui/navigation/NavGraph.kt b/app/src/main/kotlin/net/metacircular/engpad/ui/navigation/NavGraph.kt index 58c8978..c8ca01a 100644 --- a/app/src/main/kotlin/net/metacircular/engpad/ui/navigation/NavGraph.kt +++ b/app/src/main/kotlin/net/metacircular/engpad/ui/navigation/NavGraph.kt @@ -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) { - initialPageId = selectedPageId - savedState["selectedPageId"] = 0L - } + val selectedPageId = savedState.get("selectedPageId") + if (selectedPageId != null && selectedPageId > 0) { + initialPageId = selectedPageId + savedState.remove("selectedPageId") } val ps = pageSize