From 747f5196adb33c5dd1d939f6f40c512eb360a52b Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 23 Oct 2026 23:00:46 +0000 Subject: [PATCH] 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 --- .../java/com/topjohnwu/magisk/ui/navigation/Navigator.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/navigation/Navigator.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/navigation/Navigator.kt index 6c6b50b12..2e3e40e1a 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/navigation/Navigator.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/navigation/Navigator.kt @@ -16,7 +16,11 @@ class Navigator(val backStack: NavBackStack) { } 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()