11package com.jobik.gameoflife.screens.Game
22
3+ import android.util.Log
4+ import androidx.activity.compose.BackHandler
35import androidx.compose.animation.animateColorAsState
46import androidx.compose.animation.core.animateDpAsState
57import androidx.compose.foundation.background
@@ -18,12 +20,14 @@ import androidx.compose.ui.unit.dp
1820import com.jobik.gameoflife.gameOfLife.GameOfLife
1921import com.jobik.gameoflife.screens.Game.actions.GameActions
2022import com.jobik.gameoflife.ui.helpers.*
23+ import kotlinx.coroutines.launch
2124
2225@OptIn(ExperimentalMaterialApi ::class )
2326@Composable
2427fun GameScreen (
2528 viewModel : GameScreenViewModel = androidx.lifecycle.viewmodel.compose.viewModel()
2629) {
30+ val scope = rememberCoroutineScope()
2731 // Get local density from composable
2832 val backdropScaffoldState = rememberBackdropScaffoldState(BackdropValue .Revealed )
2933
@@ -35,11 +39,19 @@ fun GameScreen(
3539 }
3640 val containerColor by animateColorAsState(targetValue = containerColorTarget, label = " containerColor" )
3741
38- LaunchedEffect (backdropScaffoldState.currentValue ) {
39- if (backdropScaffoldState.currentValue == BackdropValue . Concealed )
42+ LaunchedEffect (backdropScaffoldState.progress ) {
43+ if (backdropScaffoldState.progress.fraction > 0f )
4044 viewModel.turnOffSimulation()
4145 }
4246
47+ BackHandler (enabled = backdropScaffoldState.currentValue == BackdropValue .Concealed ) {
48+ scope.launch { backdropScaffoldState.reveal() }
49+ }
50+
51+ BackHandler (enabled = viewModel.states.value.isSimulationRunning) {
52+ viewModel.turnOffSimulation()
53+ }
54+
4355 when (currentWidthSizeClass()) {
4456 WindowWidthSizeClass .Compact , WindowWidthSizeClass .Medium -> {
4557 CompactGameScreen (
0 commit comments