Created
August 15, 2021 11:09
-
-
Save theapache64/71cb64c03575904fd0075e8f3150409a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Screen(val route: String) { | |
object A : Screen("A") | |
object B : Screen("B") // bottomSheet | |
object C : Screen("C") // bottomSheet | |
object D : Screen("D") | |
} | |
@OptIn(ExperimentalMaterialNavigationApi::class) | |
@Composable | |
private fun AppNavigation() { | |
val navController = rememberNavController() | |
val bottomSheetNavigator = rememberBottomSheetNavigator() | |
navController.navigatorProvider += bottomSheetNavigator | |
ModalBottomSheetLayout( | |
bottomSheetNavigator = bottomSheetNavigator, | |
) { | |
NavHost(navController = navController, startDestination = Screen.A.route) { // Open 'A' | |
composable(Screen.A.route) { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.Red) | |
) { | |
Text(text = "I am A") | |
Counter() | |
Button(onClick = { | |
navController.navigate(Screen.B.route) // Open BottomSheet B | |
}) { | |
Text(text = "GO TO BS") | |
} | |
} | |
} | |
bottomSheet(Screen.B.route) { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.Green) | |
) { | |
Text(text = "I am B") | |
Counter() | |
Button(onClick = { | |
navController.navigate(Screen.C.route) // Open BottomSheet C | |
}) { | |
Text(text = "GO TO CS") | |
} | |
} | |
} | |
bottomSheet(Screen.C.route) { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.Blue) | |
) { | |
Text(text = "I am C") | |
Counter() | |
Button(onClick = { | |
navController.navigate(Screen.D.route) // Open D | |
}) { | |
Text(text = "GO TO D") | |
} | |
} | |
} | |
composable(Screen.D.route) { | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.Black) | |
) { | |
Text(text = "I am D") | |
Counter() | |
Button(onClick = { | |
navController.popBackStack() // GO BACK | |
}) { | |
Text(text = "GO BACK") | |
} | |
} | |
} | |
} | |
} | |
} | |
@Composable | |
fun Counter() { | |
var count by rememberSaveable { | |
mutableStateOf(0) | |
} | |
Button(onClick = { count++ }) { | |
Text(text = "Count : $count") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment