From 5329629e2210b51c93372f037373a66c470fe8dd Mon Sep 17 00:00:00 2001 From: David Perez Date: Thu, 30 May 2024 16:23:36 -0500 Subject: [PATCH] Clear focus whenever the root navigation changes (#1411) --- .../bitwarden/ui/platform/feature/rootnav/RootNavScreen.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavScreen.kt index a3224bd3b..9bc12e16f 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/rootnav/RootNavScreen.kt @@ -1,10 +1,12 @@ package com.x8bit.bitwarden.ui.platform.feature.rootnav +import android.app.Activity import androidx.compose.animation.AnimatedContentTransitionScope import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalContext import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavBackStackEntry @@ -117,6 +119,10 @@ fun RootNavScreen( } previousStateReference.set(state) + // In some scenarios on an emulator the Activity can leak when recreated + // if we don't first clear focus anytime we change the root destination. + (LocalContext.current as? Activity)?.currentFocus?.clearFocus() + // When state changes, navigate to different root navigation state val rootNavOptions = navOptions { // When changing root navigation state, pop everything else off the back stack: