From 6a628d243571a2542bc6e2c6511cbc11ad8fee8b Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 24 Mar 2026 17:10:01 -0700 Subject: [PATCH] Fix remaining flicker and prevent empty page creation on swipe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flicker: removed View background and super.onDraw() call — canvas is filled with white explicitly in onDraw before compositing the backing bitmap, eliminating the clear-then-redraw flash. Empty page: swiping right on the last page only creates a new page if the current page has strokes. Empty pages don't spawn more empties. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../metacircular/engpad/ui/editor/EditorViewModel.kt | 12 +++++++----- .../metacircular/engpad/ui/editor/PadCanvasView.kt | 9 +++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorViewModel.kt b/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorViewModel.kt index 445c45d..45e0097 100644 --- a/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorViewModel.kt +++ b/app/src/main/kotlin/net/metacircular/engpad/ui/editor/EditorViewModel.kt @@ -108,11 +108,13 @@ class EditorViewModel( if (nextIndex < _pages.value.size) { navigateToPage(nextIndex) } else { - // Add a new page and navigate to it - viewModelScope.launch { - pageRepository.addPage(notebookId) - loadPages() - navigateToPage(_pages.value.size - 1) + // Only add a new page if the current page has strokes + if (_strokes.value.isNotEmpty()) { + viewModelScope.launch { + pageRepository.addPage(notebookId) + loadPages() + navigateToPage(_pages.value.size - 1) + } } } } 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 2dd232a..754b7fd 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 @@ -195,7 +195,11 @@ class PadCanvasView(context: Context) : View(context) { } init { - setBackgroundColor(Color.WHITE) + // No background — we draw our own white page rect. + // This avoids the flicker from View clearing to background color + // before onDraw composites the backing bitmap. + background = null + setWillNotDraw(false) } // --- Public API --- @@ -235,7 +239,8 @@ class PadCanvasView(context: Context) : View(context) { } override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) + // Fill entire view with white (no super.onDraw to avoid double-clear flicker) + canvas.drawColor(Color.WHITE) // Draw page background in canonical space canvas.withMatrix(viewMatrix) {