From 2355e89248eff4694a9bdcfd5bdea8d0ef8d601a Mon Sep 17 00:00:00 2001 From: David Perez Date: Wed, 10 Jun 2026 13:52:23 -0500 Subject: [PATCH] Chore: Isolate the MainActivity composable content from onCreate (#7051) --- .../com/x8bit/bitwarden/MainActivity.kt | 71 +++++++++++-------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/app/src/main/kotlin/com/x8bit/bitwarden/MainActivity.kt b/app/src/main/kotlin/com/x8bit/bitwarden/MainActivity.kt index 3611030100..c4ce626d1c 100644 --- a/app/src/main/kotlin/com/x8bit/bitwarden/MainActivity.kt +++ b/app/src/main/kotlin/com/x8bit/bitwarden/MainActivity.kt @@ -15,13 +15,13 @@ import androidx.browser.auth.AuthTabIntent import androidx.compose.foundation.background import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.core.app.ActivityCompat import androidx.core.os.LocaleListCompat import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.navigation.NavController +import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import com.bitwarden.annotation.OmitFromCoverage import com.bitwarden.ui.platform.base.util.EventsEffect @@ -126,35 +126,13 @@ class MainActivity : AppCompatActivity() { SetupEventsEffect(navController = navController) val state by mainViewModel.stateFlow.collectAsStateWithLifecycle() updateScreenCapture(isScreenCaptureAllowed = state.isScreenCaptureAllowed) - LocalManagerProvider( - featureFlagsState = state.featureFlagsState, + MainActivityContent( + state = state, authTabLaunchers = authTabLaunchers, - ) { - ObserveScreenDataEffect( - onDataUpdate = remember(mainViewModel) { - { mainViewModel.trySendAction(MainAction.ResumeScreenDataReceived(it)) } - }, - ) - BitwardenTheme( - theme = state.theme, - dynamicColor = state.isDynamicColorsEnabled, - ) { - NavHost( - navController = navController, - startDestination = OverlayNavRoute, - modifier = Modifier - .background(color = BitwardenTheme.colorScheme.background.primary), - ) { - // The OverlayNav and Debug destinations are the only UIs that can be - // displayed here, everything else should be inside the OverlayNav. - overlayNavDestination { shouldShowSplashScreen = false } - debugMenuDestination( - onNavigateBack = { navController.popBackStack() }, - onSplashScreenRemoved = { shouldShowSplashScreen = false }, - ) - } - } - } + navController = navController, + sendAction = mainViewModel::trySendAction, + onSplashScreenRemoved = { shouldShowSplashScreen = false }, + ) } } @@ -278,3 +256,38 @@ class MainActivity : AppCompatActivity() { } } } + +@OmitFromCoverage +@Composable +private fun MainActivityContent( + state: MainState, + authTabLaunchers: AuthTabLaunchers, + navController: NavHostController, + sendAction: (MainAction) -> Unit, + onSplashScreenRemoved: () -> Unit, +) { + LocalManagerProvider( + featureFlagsState = state.featureFlagsState, + authTabLaunchers = authTabLaunchers, + ) { + ObserveScreenDataEffect { sendAction(MainAction.ResumeScreenDataReceived(it)) } + BitwardenTheme( + theme = state.theme, + dynamicColor = state.isDynamicColorsEnabled, + ) { + NavHost( + navController = navController, + startDestination = OverlayNavRoute, + modifier = Modifier.background(BitwardenTheme.colorScheme.background.primary), + ) { + // The OverlayNav and Debug destinations are the only UIs that can be + // displayed here, everything else should be inside the OverlayNav. + overlayNavDestination(onSplashScreenRemoved = onSplashScreenRemoved) + debugMenuDestination( + onNavigateBack = { navController.popBackStack() }, + onSplashScreenRemoved = onSplashScreenRemoved, + ) + } + } + } +}