Skip to content

Commit 323cef0

Browse files
committed
updated behaviour BackHandler when sheet concealed and game running
1 parent f96e2b9 commit 323cef0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/src/main/java/com/jobik/gameoflife/screens/Game/GameScreen.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.jobik.gameoflife.screens.Game
22

3+
import android.util.Log
4+
import androidx.activity.compose.BackHandler
35
import androidx.compose.animation.animateColorAsState
46
import androidx.compose.animation.core.animateDpAsState
57
import androidx.compose.foundation.background
@@ -18,12 +20,14 @@ import androidx.compose.ui.unit.dp
1820
import com.jobik.gameoflife.gameOfLife.GameOfLife
1921
import com.jobik.gameoflife.screens.Game.actions.GameActions
2022
import com.jobik.gameoflife.ui.helpers.*
23+
import kotlinx.coroutines.launch
2124

2225
@OptIn(ExperimentalMaterialApi::class)
2326
@Composable
2427
fun 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

Comments
 (0)