From ccbaeacbd93f15b655e4d2abde250d2bf8c863df Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 2 Apr 2026 13:02:15 +0000 Subject: [PATCH] fix: prevent call screen from closing before state transitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When initiateCall() runs async (Dispatchers.IO), navigation to the ActiveCall screen happens before CallManager state changes from Idle to Offering. The CallScreen sees Idle and immediately calls onCallEnded() → popBack(), causing the screen to flash and disappear. Fix: CallScreen now waits 500ms on Idle before popping back. If the state transitions to Offering within that window (normal case), the screen stays. If it's still Idle after 500ms (no call in progress), it pops back as before. https://claude.ai/code/session_017hZm7yu7CzmcQgZGSaqSXS --- .../com/vitorpamplona/amethyst/ui/call/CallScreen.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallScreen.kt index b6385b91a..ec962edb2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/call/CallScreen.kt @@ -107,7 +107,14 @@ fun CallScreen( Box(modifier = Modifier.fillMaxSize()) { when (val state = callState) { is CallState.Idle -> { - LaunchedEffect(Unit) { onCallEnded() } + // Wait briefly — initiateCall runs async and state may not have + // transitioned yet when navigating to this screen + LaunchedEffect(Unit) { + delay(500) + if (callManager.state.value is CallState.Idle) { + onCallEnded() + } + } } is CallState.Offering -> {