Fix remaining flicker and prevent empty page creation on swipe

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) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 17:10:01 -07:00
parent a10d7febf9
commit 6a628d2435
2 changed files with 14 additions and 7 deletions

View File

@@ -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)
}
}
}
}

View File

@@ -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) {