Skip to content

Instantly share code, notes, and snippets.

@theapache64
Created August 15, 2021 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theapache64/581b13679b0bb9182629784dac44d4fc to your computer and use it in GitHub Desktop.
Save theapache64/581b13679b0bb9182629784dac44d4fc to your computer and use it in GitHub Desktop.
@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("d") {
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