mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-09-19 04:59:59 +00:00
fix(ui): forward Back when canHandleBack is momentarily stale
BackHandler's enabled flag trails the state it mirrors by a coroutine dispatch and a recomposition. A second Back press inside that window finds the handler still enabled while handleBackPressed() already has nothing to unwind, and ignoring its result consumed the press instead of letting the system act on it. The callback the handler replaced did forward it. Falls back to finish() on an unhandled press, which is what the dispatcher reached before once no enabled callback consumed it. Reported by Codex review on #912. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MdKgoKZbL5K1wsn1WsES26
This commit is contained in:
parent
78991a289e
commit
68361d949f
@ -318,7 +318,11 @@ class MainActivity : OrientationAwareActivity() {
|
||||
// through to the system, which exits the app.
|
||||
val canHandleBack by chatViewModel.canHandleBack.collectAsState()
|
||||
BackHandler(enabled = canHandleBack) {
|
||||
chatViewModel.handleBackPressed()
|
||||
// enabled reaches this handler a dispatch and a recomposition
|
||||
// after the state changes, so a second press can arrive while
|
||||
// it is still true but there is no longer anything to unwind.
|
||||
// Forward that press instead of swallowing it.
|
||||
if (!chatViewModel.handleBackPressed()) finish()
|
||||
}
|
||||
ChatScreen(viewModel = chatViewModel)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user