Skip to content

Extensions for Jetpack Navigation Compose: Material 3 BottomSheet, custom ModalSheet, Results and more.

License

Notifications You must be signed in to change notification settings

hrach/navigation-compose-ext

Folders and files

NameName
Last commit message
Last commit date
Sep 29, 2024
Oct 4, 2024
Sep 29, 2024
Oct 23, 2024
Mar 17, 2025
Oct 23, 2024
May 17, 2024
Sep 29, 2024
May 17, 2024
Sep 24, 2024
Mar 3, 2025
Nov 4, 2024
Mar 10, 2025
Jul 22, 2024
May 17, 2024
Jul 14, 2024
May 21, 2024

Repository files navigation

Extensions for Navigation Compose

CI Build GitHub release

See demo module.

Use Maven Central and these dependencies:

dependencies {
	implementation("dev.hrach.navigation:bottomsheet:<version>")
	implementation("dev.hrach.navigation:modalsheet:<version>")
	implementation("dev.hrach.navigation:results:<version>")
}

Components:

  • BottomSheet - Connects the official Material 3 BottomSheet with Jetpack Navigation.
  • ModalSheet - A custom destination type for Jetpack Navigation that brings fullscreen content with modal animation.
  • Results - Passing a result simply between destinations.

Quick setup:

val modalSheetNavigator = remember { ModalSheetNavigator() }
val bottomSheetNavigator = remember { BottomSheetNavigator() }
val navController = rememberNavController(modalSheetNavigator, bottomSheetNavigator)

NavHost(
	navController = navController,
	startDestination = Destinations.Home,
) {
	composable<Destinations.Home> { Home(navController) }
	modalSheet<Destinations.Modal> { Modal(navController) }
	bottomSheet<Destinations.BottomSheet> { BottomSheet(navController) }
}
ModalSheetHost(modalSheetNavigator, containerColor = MaterialTheme.colorScheme.background)
BottomSheetHost(bottomSheetNavigator)

Results sharing:

object Destinations {
	@Serializable
	data object BottomSheet {
		@Serializable
		data class Result(
			val id: Int,
		)
	}
}

@Composable
fun Home(navController: NavController) {
	NavigationResultEffect<Destinations.BottomSheet.Result>(
		backStackEntry = remember(navController) { navController.getBackStackEntry<Destinations.Home>() },
		navController = navController,
	) { result ->
		// process result -
	}
}

@Composable
fun BottomSheet(navController: NavController) {
	OutlineButton(onClick = { navController.setResult(Destinations.BottomSheet.Result(42)) }) {
		Text("Close")
	}
}