11package dev.hrach.navigation.demo.screens
22
3+ import android.annotation.SuppressLint
34import androidx.compose.foundation.background
45import androidx.compose.foundation.layout.Column
56import androidx.compose.foundation.layout.WindowInsets
@@ -10,24 +11,50 @@ import androidx.compose.material3.MaterialTheme
1011import androidx.compose.material3.OutlinedButton
1112import androidx.compose.material3.Text
1213import androidx.compose.runtime.Composable
14+ import androidx.compose.runtime.getValue
15+ import androidx.compose.runtime.mutableIntStateOf
16+ import androidx.compose.runtime.remember
17+ import androidx.compose.runtime.saveable.rememberSaveable
18+ import androidx.compose.runtime.setValue
1319import androidx.compose.ui.Modifier
1420import androidx.navigation.NavController
1521import dev.hrach.navigation.demo.Destinations
22+ import dev.hrach.navigation.results.NavigationResultEffect
1623
24+ @SuppressLint(" UnrememberedGetBackStackEntry" )
1725@Composable
1826internal fun Modal1 (navController : NavController ) {
27+ var bottomSheetResult by rememberSaveable { mutableIntStateOf(- 1 ) }
28+ NavigationResultEffect <Destinations .BottomSheet .Result >(
29+ backStackEntry = remember(navController) { navController.getBackStackEntry<Destinations .Modal1 >() },
30+ navController = navController,
31+ ) { result ->
32+ bottomSheetResult = result.id
33+ }
34+ Modal1 (
35+ navigate = navController::navigate,
36+ bottomSheetResult = bottomSheetResult,
37+ )
38+ }
39+
40+ @Composable
41+ private fun Modal1 (
42+ navigate : (Any ) -> Unit ,
43+ bottomSheetResult : Int ,
44+ ) {
1945 Column (
2046 Modifier
2147 .fillMaxSize()
2248 .background(MaterialTheme .colorScheme.surface)
2349 .windowInsetsPadding(WindowInsets .systemBars),
2450 ) {
2551 Text (" Modal 1" )
26- OutlinedButton (onClick = { navController. navigate(Destinations .Modal2 ) }) {
52+ OutlinedButton (onClick = { navigate(Destinations .Modal2 ) }) {
2753 Text (" Modal 2" )
2854 }
29- OutlinedButton (onClick = { navController. navigate(Destinations .BottomSheet ) }) {
55+ OutlinedButton (onClick = { navigate(Destinations .BottomSheet ) }) {
3056 Text (" BottomSheet" )
3157 }
58+ Text (" BottomSheetResult: $bottomSheetResult " )
3259 }
3360}
0 commit comments