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:
@@ -108,7 +108,8 @@ class EditorViewModel(
|
|||||||
if (nextIndex < _pages.value.size) {
|
if (nextIndex < _pages.value.size) {
|
||||||
navigateToPage(nextIndex)
|
navigateToPage(nextIndex)
|
||||||
} else {
|
} else {
|
||||||
// Add a new page and navigate to it
|
// Only add a new page if the current page has strokes
|
||||||
|
if (_strokes.value.isNotEmpty()) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
pageRepository.addPage(notebookId)
|
pageRepository.addPage(notebookId)
|
||||||
loadPages()
|
loadPages()
|
||||||
@@ -116,6 +117,7 @@ class EditorViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun navigatePrev() {
|
fun navigatePrev() {
|
||||||
val prevIndex = _currentPageIndex.value - 1
|
val prevIndex = _currentPageIndex.value - 1
|
||||||
|
|||||||
@@ -195,7 +195,11 @@ class PadCanvasView(context: Context) : View(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
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 ---
|
// --- Public API ---
|
||||||
@@ -235,7 +239,8 @@ class PadCanvasView(context: Context) : View(context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas) {
|
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
|
// Draw page background in canonical space
|
||||||
canvas.withMatrix(viewMatrix) {
|
canvas.withMatrix(viewMatrix) {
|
||||||
|
|||||||
Reference in New Issue
Block a user