https://github.com/stefanoq21/BottomSheetNavigator3
This library provides a navigation solution for Compose projects using Material3 BottomSheets
https://github.com/stefanoq21/BottomSheetNavigator3
android bottomsheet jetpack-compose kotlin navigation
Last synced: 4 months ago
JSON representation
This library provides a navigation solution for Compose projects using Material3 BottomSheets
- Host: GitHub
- URL: https://github.com/stefanoq21/BottomSheetNavigator3
- Owner: stefanoq21
- License: apache-2.0
- Created: 2024-07-05T16:02:30.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-12-12T17:42:12.000Z (5 months ago)
- Last Synced: 2024-12-12T18:28:52.299Z (5 months ago)
- Topics: android, bottomsheet, jetpack-compose, kotlin, navigation
- Language: Kotlin
- Homepage: https://medium.com/@stefanoq21/13f726c13d6b
- Size: 186 KB
- Stars: 29
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-list - stefanoq21/BottomSheetNavigator3 - This library provides a navigation solution for Compose projects using Material3 BottomSheets (Kotlin)
README
# Material3 BottomSheet Navigation
This library provides a navigation solution for Compose projects using Material3 BottomSheets. It allows you to define your BottomSheet as navigation routes, eliminating the need for the `androidx.compose.material.navigation` and ` androidx.compose.material:material` !
libraries. This simplifies your app's dependencies and ensures a consistent Material3 experience.
This library also leverages the new functionality from `androidx.navigation:navigation-compose:2.8.0-beta0X` to allow you to define routes with serialized classes.[](https://central.sonatype.com/artifact/io.github.stefanoq21/material3-navigation)

## Implementation
You can follow the implementation approach used in the [app](https://github.com/stefanoq21/BottomSheetNavigator3/tree/main/app "app") module. Alternatively, you can find a detailed explanation below.
### Dependencies
The library is now available on MavenCentral!!!
Add the dependencies to your `libs.versions.toml`
```
[versions]
...
material3Navigation = "X.X.X" current release version[libraries]
...
material3-navigation = { group = "io.github.stefanoq21", name = "material3-navigation", version.ref = "material3Navigation" }```
In your `build.gradle.kts` implement your dependencies:
```
...
dependencies {
...
implementation(libs.material3.navigation)
```
### Usage
Define your **BottomSheetNavigator**
```
...
val bottomSheetNavigator =
rememberBottomSheetNavigator(skipPartiallyExpanded = true/false)
val navController = rememberNavController(bottomSheetNavigator)
```
Add the **ModalBottomSheetLayout** on top of the **NavHost** component and pass the **bottomSheetNavigator** as parameter:
```
ModalBottomSheetLayout(
modifier = Modifier
.fillMaxSize(),
bottomSheetNavigator = bottomSheetNavigator
) {
NavHost(
navController = navController,
startDestination = Screen.Home
) {
...
```
Define your routes as strings or data class (depend on the compose navigation version you are using):
```
...
bottomSheet {
BSFullScreenLayout()
}
bottomSheet("BottomSheetFullScreen") {
BSFullScreenLayout()
}
...
```
Everything is ready! Just navigate to your new destination as usual:
```
...
Button(onClick = { navController.navigate(Screen.BottomSheetFullScreen) }) {
Text(text = "BottomSheetFullScreen")
}
...
```### Navigating Back from a Bottom Sheet
To implement a back or close button in your bottom sheet, I suggest to use `onBackPressedDispatcher.onBackPressed()`. This because if you use `navController.popBackStack()` the animation will not appear. The animation was disabled, in this case, to avoid problems during the navigation that start from bottomshets.
### Customization
The library currently supports the same customization options of the standard `androidx.compose.material3.ModalBottomSheet`. You can customize the appearance of the all the bottomsheets used in your navigation graph by passing the parameters to the `ModalBottomSheetLayout`.
## Preview
## Contributing
We welcome contributions to this library! If you have bug reports, feature requests, or code improvements, please feel free to create a pull request. I appreciate your help in making this library even better.
## License
Copyright 2024 stefanoq21
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.