app: never pop the root navigation entry

A screen's back button stays clickable while the screen slides out, so
tapping it twice quickly called Navigator.pop() twice. The second call
removed Route.Main, and NavDisplay crashed the app because its back
stack must not be empty.

Make pop() a no-op on the root entry. Leaving the app from the root is
handled by the system, not by popping the last entry.

Assisted-by: Claude Opus 5.5
This commit is contained in:
topjohnwu
2026-10-24 13:01:45 -07:00
committed by John Wu
parent 008a7bff80
commit 747f5196ad
@@ -16,7 +16,11 @@ class Navigator(val backStack: NavBackStack<NavKey>) {
} }
fun pop(): Boolean { fun pop(): Boolean {
return backStack.removeLastOrNull() != null // Never remove the root: NavDisplay requires a non-empty back stack, and a screen's
// back button stays clickable during its exit animation, so it can be tapped again
if (backStack.size <= 1) return false
backStack.removeAt(backStack.lastIndex)
return true
} }
fun current(): NavKey? = backStack.lastOrNull() fun current(): NavKey? = backStack.lastOrNull()