Skip to content

Commit

Permalink
modify showIndicator definition position to hide indicator when back.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniokrait committed Jul 24, 2023
1 parent 1613fe9 commit 3f1236f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package io.github.aniokrait.androidtoybox.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost
Expand All @@ -25,7 +27,9 @@ fun MyNavigationCompose(modifier: Modifier = Modifier) {
val vm: TransitSourceViewModel = hiltViewModel()
//Activityが破棄されても保持し続けるためにrememberではなくrememberSaveableで定義
val isLoadCompleted = rememberSaveable { mutableStateOf(false) }
var showIndicator = rememberSaveable { mutableStateOf(false) }
TransitSourceScreen(
showIndicator = showIndicator,
transit = {
//navController.navigateではなく、BooleanのMutableStateを渡す
vm.fetchSomeData(isLoadCompleted)
Expand All @@ -34,7 +38,9 @@ fun MyNavigationCompose(modifier: Modifier = Modifier) {
//isLoadCompletedがtrueになったら画面遷移を行う。
LaunchedEffect(isLoadCompleted.value) {
if (isLoadCompleted.value) {
showIndicator.value = false
navController.navigate("transitTarget")
isLoadCompleted.value = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
Expand All @@ -18,19 +19,19 @@ import androidx.compose.ui.graphics.Color

@Composable
fun TransitSourceScreen(
showIndicator: MutableState<Boolean>,
transit: () -> Unit
) {
var showIndicator by rememberSaveable { mutableStateOf(false) }

Column {
Button(onClick = {
showIndicator = true
showIndicator.value = true
transit()
}) {
Text("遷移する")
}
}
if(showIndicator) {
if(showIndicator.value) {
Box(modifier = Modifier
.fillMaxSize()
.background(color = Color.Black.copy(alpha = 0.3f))
Expand Down

0 comments on commit 3f1236f

Please sign in to comment.