BIT-147: Improve splash screen handling for all OS levels (#72)

This commit is contained in:
Brian Yencho
2023-09-28 14:18:03 -05:00
committed by Álison Fernandes
parent a223e2fed5
commit 5fc78afa0a
17 changed files with 38 additions and 31 deletions

View File

@@ -3,6 +3,7 @@ package com.x8bit.bitwarden
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.x8bit.bitwarden.ui.platform.feature.rootnav.RootNavScreen
import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
import dagger.hilt.android.AndroidEntryPoint
@@ -13,10 +14,14 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
var shouldShowSplashScreen = true
installSplashScreen().setKeepOnScreenCondition { shouldShowSplashScreen }
super.onCreate(savedInstanceState)
setContent {
BitwardenTheme {
RootNavScreen()
RootNavScreen(
onSplashScreenRemoved = { shouldShowSplashScreen = false },
)
}
}
}

View File

@@ -4,6 +4,7 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
@@ -42,6 +43,7 @@ fun LoginScreen(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(12.dp),
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background)
.padding(horizontal = 16.dp, vertical = 32.dp),
) {

View File

@@ -1,6 +1,7 @@
package com.x8bit.bitwarden.ui.platform.feature.rootnav
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -23,9 +24,15 @@ import com.x8bit.bitwarden.ui.platform.feature.vaultunlocked.vaultUnlockedDestin
fun RootNavScreen(
viewModel: RootNavViewModel = hiltViewModel(),
navController: NavHostController = rememberNavController(),
onSplashScreenRemoved: () -> Unit = {},
) {
val state by viewModel.stateFlow.collectAsStateWithLifecycle()
val isNotSplashScreen = state != RootNavState.Splash
LaunchedEffect(isNotSplashScreen) {
if (isNotSplashScreen) onSplashScreenRemoved()
}
NavHost(
navController = navController,
startDestination = SPLASH_ROUTE,