Skip to content

Commit 2355e89

Browse files
Chore: Isolate the MainActivity composable content from onCreate (#7051)
1 parent 38045c9 commit 2355e89

1 file changed

Lines changed: 42 additions & 29 deletions

File tree

app/src/main/kotlin/com/x8bit/bitwarden/MainActivity.kt

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import androidx.browser.auth.AuthTabIntent
1515
import androidx.compose.foundation.background
1616
import androidx.compose.runtime.Composable
1717
import androidx.compose.runtime.getValue
18-
import androidx.compose.runtime.remember
1918
import androidx.compose.ui.Modifier
2019
import androidx.core.app.ActivityCompat
2120
import androidx.core.os.LocaleListCompat
2221
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
2322
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2423
import androidx.navigation.NavController
24+
import androidx.navigation.NavHostController
2525
import androidx.navigation.compose.NavHost
2626
import com.bitwarden.annotation.OmitFromCoverage
2727
import com.bitwarden.ui.platform.base.util.EventsEffect
@@ -126,35 +126,13 @@ class MainActivity : AppCompatActivity() {
126126
SetupEventsEffect(navController = navController)
127127
val state by mainViewModel.stateFlow.collectAsStateWithLifecycle()
128128
updateScreenCapture(isScreenCaptureAllowed = state.isScreenCaptureAllowed)
129-
LocalManagerProvider(
130-
featureFlagsState = state.featureFlagsState,
129+
MainActivityContent(
130+
state = state,
131131
authTabLaunchers = authTabLaunchers,
132-
) {
133-
ObserveScreenDataEffect(
134-
onDataUpdate = remember(mainViewModel) {
135-
{ mainViewModel.trySendAction(MainAction.ResumeScreenDataReceived(it)) }
136-
},
137-
)
138-
BitwardenTheme(
139-
theme = state.theme,
140-
dynamicColor = state.isDynamicColorsEnabled,
141-
) {
142-
NavHost(
143-
navController = navController,
144-
startDestination = OverlayNavRoute,
145-
modifier = Modifier
146-
.background(color = BitwardenTheme.colorScheme.background.primary),
147-
) {
148-
// The OverlayNav and Debug destinations are the only UIs that can be
149-
// displayed here, everything else should be inside the OverlayNav.
150-
overlayNavDestination { shouldShowSplashScreen = false }
151-
debugMenuDestination(
152-
onNavigateBack = { navController.popBackStack() },
153-
onSplashScreenRemoved = { shouldShowSplashScreen = false },
154-
)
155-
}
156-
}
157-
}
132+
navController = navController,
133+
sendAction = mainViewModel::trySendAction,
134+
onSplashScreenRemoved = { shouldShowSplashScreen = false },
135+
)
158136
}
159137
}
160138

@@ -278,3 +256,38 @@ class MainActivity : AppCompatActivity() {
278256
}
279257
}
280258
}
259+
260+
@OmitFromCoverage
261+
@Composable
262+
private fun MainActivityContent(
263+
state: MainState,
264+
authTabLaunchers: AuthTabLaunchers,
265+
navController: NavHostController,
266+
sendAction: (MainAction) -> Unit,
267+
onSplashScreenRemoved: () -> Unit,
268+
) {
269+
LocalManagerProvider(
270+
featureFlagsState = state.featureFlagsState,
271+
authTabLaunchers = authTabLaunchers,
272+
) {
273+
ObserveScreenDataEffect { sendAction(MainAction.ResumeScreenDataReceived(it)) }
274+
BitwardenTheme(
275+
theme = state.theme,
276+
dynamicColor = state.isDynamicColorsEnabled,
277+
) {
278+
NavHost(
279+
navController = navController,
280+
startDestination = OverlayNavRoute,
281+
modifier = Modifier.background(BitwardenTheme.colorScheme.background.primary),
282+
) {
283+
// The OverlayNav and Debug destinations are the only UIs that can be
284+
// displayed here, everything else should be inside the OverlayNav.
285+
overlayNavDestination(onSplashScreenRemoved = onSplashScreenRemoved)
286+
debugMenuDestination(
287+
onNavigateBack = { navController.popBackStack() },
288+
onSplashScreenRemoved = onSplashScreenRemoved,
289+
)
290+
}
291+
}
292+
}
293+
}

0 commit comments

Comments
 (0)