Jetpack Navigation Compose Material¶
A library which provides Compose Material support for Jetpack Navigation Compose. This features composable bottom sheet destinations.
Warning
This library is deprecated, with official material-navigation support in androidx.compose.material.navigation. The original documentation is below the migration guide.
Migration¶
The official androidx.compose.material.navigation
version 1.7.0-alpha04+ offers all of the same functionality as Accompanist Navigation Material.
All class names are the same, the only needed changes are import related.
- Replace dependency
com.google.accompanist:accompanist-navigation-material:<version>
withandroidx.compose.material:material-navigation:<version>
- Change import for ModalBottomSheetLayout from
com.google.accompanist.navigation.material.ModalBottomSheetLayout
toandroidx.compose.material.navigation.ModalBottomSheetLayout
- Change import for bottomSheet from
com.google.accompanist.navigation.material.bottomSheet
toandroidx.compose.material.navigation.bottomSheet
- Change import for rememberBottomSheetNavigator from
com.google.accompanist.navigation.material.rememberBottomSheetNavigator
toandroidx.compose.material.navigation.rememberBottomSheetNavigator
- Change import for BottomSheetNavigator from
com.google.accompanist.navigation.material.BottomSheetNavigator
toandroidx.compose.material.navigation.BottomSheetNavigator
- Change import for BottomSheetNavigatorSheetState from
com.google.accompanist.navigation.material.BottomSheetNavigatorSheetState
toandroidx.compose.material.navigation.BottomSheetNavigatorSheetState
Deprecated Guidance for Accompanist Navigation Material¶
The following is the deprecated guide for using Navigation Material in Accompanist. Please see above migration section for how to use the androidx.compose.material.navigation
Material Navigation.
Usage¶
Bottom Sheet Destinations¶
-
Create a
BottomSheetNavigator
and add it to theNavController
:@Composable fun MyApp() { val bottomSheetNavigator = rememberBottomSheetNavigator() val navController = rememberNavController(bottomSheetNavigator) }
-
Wrap your
NavHost
in theModalBottomSheetLayout
composable that accepts aBottomSheetNavigator
.@Composable fun MyApp() { val bottomSheetNavigator = rememberBottomSheetNavigator() val navController = rememberNavController(bottomSheetNavigator) ModalBottomSheetLayout(bottomSheetNavigator) { NavHost(navController, "home") { // We'll define our graph here in a bit! } } }
-
Register a bottom sheet destination
@Composable fun MyApp() { val bottomSheetNavigator = rememberBottomSheetNavigator() val navController = rememberNavController(bottomSheetNavigator) ModalBottomSheetLayout(bottomSheetNavigator) { NavHost(navController, "home") { composable(route = "home") { ... } bottomSheet(route = "sheet") { Text("This is a cool bottom sheet!") } } } }
For more examples, refer to the samples.
Download¶
repositories {
mavenCentral()
}
dependencies {
implementation "com.google.accompanist:accompanist-navigation-material:<version>"
}
Snapshots of the development version are available in Sonatype's snapshots
repository. These are updated on every commit.