From 3bdaf2ae5904a5dcd2058dfb85dd5659c07330a5 Mon Sep 17 00:00:00 2001 From: Moe Hamade <69801237+moehamade@users.noreply.github.com> Date: Tue, 8 Sep 2026 21:54:48 +0300 Subject: [PATCH] fix(ui): forward Back when the handler's enabled state is stale BackHandler's enabled flag trails the state it is derived from by a dispatch and a recomposition, so a second quick press after the last overlay closes still reaches this handler. handleBackPressed then finds nothing to unwind and returns false, and dropping that result swallowed the press instead of leaving the chat screen. The result is now forwarded: pop a route if one is beneath, and otherwise finish, which is what the press would have done had the handler already been disabled. This mirrors the guard the callback carried before the Navigation 3 host replaced it. Not covered by a test. The condition is a race between input dispatch and recomposition inside a composed hierarchy, and this project cannot host a Compose unit test yet: isIncludeAndroidResources fails 24 existing tests with "targetSdkVersion=37 > maxSdkVersion=35", and pinning Robolectric to sdk 35 fails 109. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01LgmKvwg6yjo1cEmagppK9m --- app/src/main/java/com/bitchat/android/MainActivity.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/bitchat/android/MainActivity.kt b/app/src/main/java/com/bitchat/android/MainActivity.kt index 8b547f40..b0e56485 100644 --- a/app/src/main/java/com/bitchat/android/MainActivity.kt +++ b/app/src/main/java/com/bitchat/android/MainActivity.kt @@ -220,7 +220,11 @@ class MainActivity : OrientationAwareActivity() { BackHandler( enabled = navigator.backStack.lastOrNull() == ChatRoute && canHandleBack ) { - chatViewModel.handleBackPressed() + // enabled trails the state by a dispatch and a recomposition, so a + // second quick press can arrive with nothing left to unwind. Forward + // it rather than swallowing it: pop a route if there is one, and + // otherwise leave, which is what the press would have done anyway. + if (!chatViewModel.handleBackPressed() && !navigator.goBack()) finish() } } }