Skip to content

Commit

Permalink
fix: Add compose lifecycle for crash screen
Browse files Browse the repository at this point in the history
Change-Id: Icb6853fed02a6f1b19582126d1fc1358f1fd0f29
  • Loading branch information
XayahSuSuSu committed Jul 15, 2024
1 parent 35e6f0b commit 689d27e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
1 change: 1 addition & 0 deletions source/feature/crash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
// Core
implementation(project(":core:common"))
implementation(project(":core:ui"))
implementation(project(":core:data"))
implementation(project(":core:util"))

// Compose Navigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.material.icons.rounded.Warning
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -46,39 +47,44 @@ class MainActivity : AppCompatActivity() {

setContent {
DataBackupTheme {
val viewModel = hiltViewModel<IndexViewModel>()
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
CompositionLocalProvider(
androidx.lifecycle.compose.LocalLifecycleOwner provides androidx.compose.ui.platform.LocalLifecycleOwner.current,
) {

LaunchedEffect(null) {
viewModel.emitState(uiState.copy(text = crashInfo))
}
val viewModel = hiltViewModel<IndexViewModel>()
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

Scaffold { innerPadding ->
Column(
modifier = Modifier
.fillMaxWidth()
.paddingHorizontal(PaddingTokens.Level4)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(PaddingTokens.Level4)
) {
InnerTopSpacer(innerPadding = innerPadding)
LaunchedEffect(null) {
viewModel.emitState(uiState.copy(text = crashInfo))
}

// TopBar
Icon(
imageVector = Icons.Rounded.Warning,
contentDescription = null,
tint = ColorSchemeKeyTokens.OnSurfaceVariant.toColor(),
Scaffold { innerPadding ->
Column(
modifier = Modifier
.size(PaddingTokens.Level7)
.paddingBottom(PaddingTokens.Level2)
)
TopBarTitle(text = stringResource(id = R.string.app_crashed))
.fillMaxWidth()
.paddingHorizontal(PaddingTokens.Level4)
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(PaddingTokens.Level4)
) {
InnerTopSpacer(innerPadding = innerPadding)

// TopBar
Icon(
imageVector = Icons.Rounded.Warning,
contentDescription = null,
tint = ColorSchemeKeyTokens.OnSurfaceVariant.toColor(),
modifier = Modifier
.size(PaddingTokens.Level7)
.paddingBottom(PaddingTokens.Level2)
)
TopBarTitle(text = stringResource(id = R.string.app_crashed))

// Content
LabelSmallText(text = uiState.text, fontFamily = JetbrainsMonoFamily)
// Content
LabelSmallText(text = uiState.text, fontFamily = JetbrainsMonoFamily)

InnerBottomSpacer(innerPadding = innerPadding)
InnerBottomSpacer(innerPadding = innerPadding)
}
}
}
}
Expand Down

0 comments on commit 689d27e

Please sign in to comment.