Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moallemi/multinavhost
Separate back stack history for each tab in Bottom Navigation View using Android Navigation Architecture Component
https://github.com/moallemi/multinavhost
android bottom-navigation-view navigation-component
Last synced: 6 days ago
JSON representation
Separate back stack history for each tab in Bottom Navigation View using Android Navigation Architecture Component
- Host: GitHub
- URL: https://github.com/moallemi/multinavhost
- Owner: moallemi
- Created: 2018-09-23T07:52:46.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-22T05:56:51.000Z (over 4 years ago)
- Last Synced: 2024-05-02T01:43:14.436Z (7 months ago)
- Topics: android, bottom-navigation-view, navigation-component
- Language: Kotlin
- Homepage:
- Size: 2.9 MB
- Stars: 231
- Watchers: 12
- Forks: 27
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MultiNavHost
This sample provides an approach to separate back stack history for each tab in Bottom Navigation View using Android Navigation Architecture ComponentBottom Navigation View gives the user quick access to 3-5 top-level destinations in an Android app. The common architectural approach for such a top level navigation which is provided by the Android navigation component is that activity only knows one backstack.
But in some cases you need to have different back stack history for each tab in bottom navigation view like Instagram app.This sample app shows the usage of the new Navigation Architecture Component in collaboration with the Bottom Navigation view with separate back stack history for each tab.
As you know when you are using Android Navigation Component you have to use a NavHostFragment as a container for your fragments:
```xml
```
Because `Navigation` class in navigation components use just one back stack for each graph, you have to use multiple `NavHostFragment` with a **single** navigation graph. So your main xml layout should look like this:
```xml
```
To avoid creating multiple navigation_graph.xml files, we use only `navigation_graph_main` file and every destination and action must be defined here.
```xml
```
There is no need to define the `app:startDestination` in the navigation graph. We need
different start destination for each tab. So we handle start destination in `TabManager` class.```kotlin
private val startDestinations = mapOf(
R.id.navigation_home to R.id.homeFragment,
R.id.navigation_dashboard to R.id.dashboardFragment,
R.id.navigation_notifications to R.id.notificationsFragment
)
```For further information please review the sample app code.