Android multi-module navigation built on top of Jetpack Navigation Compose

Overview

MultiNavCompose logo

GitHub license ktlint Android API JitPack

Android library for multi-module navigation built on top of Jetpack Navigation Compose.

The goal of this library is to simplify the setup for multi-module navigation with Jetpack Navigation Compose.

Setup

Add jitpack.io url as maven repository:

repositories {  
	...  
	maven { url 'https://jitpack.io' }  
}    

Add dependency into build.gradle:

dependencies {  
    implementation 'com.github.jeziellago:multinavcompose:TAG'  
}  

1. Create a NavComposableModule

Make your composables internal and expose only a NavComposableModule for each module.

// module :posts  
val postsNavModule = NavComposableModule { graph, navController ->  
    graph.composable(POSTS_ROUTE) {  
        PostsScreen(onClick = { postId ->  
            navController.navigate("$POST_DETAIL_ROUTE/$postId")  
        })  
    }  
}  

You also can have nested graphs:

// module :posts  
val postsNavModule = NavComposableModule { graph, navController ->  
	graph.navigation(startDestination = POSTS_ROUTE, route = POSTS) { 
	    composable(POSTS_ROUTE) {  
	        PostsScreen(onClick = { postId ->  
	            navController.navigate("$POST_DETAIL_ROUTE/$postId")  
	        })  
	     }
	     ...
    }
}  

2. Register the NavComposeModule`s

Single NavHost

Call multiNavModules and put all the NavComposeModule's.

For single activity applications (and only a NavHost) you should register the NavComposeModule in onCreate on Application.

class MyApplication : Application() {  
  
    override fun onCreate() {  
        super.onCreate()  
        // Register all NavComposeModules  
        multiNavModules(homeNavModule, postsNavModule, postDetailNavModule)  
    }  
}  

Multiple NavHost's

If you have multiple NavHost's, a key is required on registering each of them:

// feed nav graph
multiNavModules(feedNavModule) { FEED_GRAPH }

// posts nav graph
multiNavModules(postsNavModule, postDetailNavModule) { POST_GRAPH }

3. Setup on NavHost

The loadMultiNavComposables loads the composables into NavHost.

Single NavHost

NavHost(navController = navController, startDestination = HOME) {  
  loadMultiNavComposables(navController)  
}

Multiple NavHost

If you have multiple NavHost's, a key is required too (see POSTS_GRAPH).

NavHost(navController = navController, startDestination = POSTS_ROUTE) {  
  loadMultiNavComposables(navController, POSTS_GRAPH)  
}

License

Copyright (c) 2021 Jeziel Lago  
  
Permission is hereby granted, free of charge, to any person obtaining  
a copy of this software and associated documentation files (the  
"Software"), to deal in the Software without restriction, including  
without limitation the rights to use, copy, modify, merge, publish,  
distribute, sublicense, and/or sell copies of the Software, and to  
permit persons to whom the Software is furnished to do so, subject to  
the following conditions:  
  
The above copyright notice and this permission notice shall be  
included in all copies or substantial portions of the Software.  
  
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,  
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF  
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND  
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE  
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION  
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION  
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  
You might also like...
DSC Moi University session on using Navigation components to simplify creating navigation flow in our apps to use best practices recommended by the Google Android Team

Navigation Components Navigate between destination using safe args How to use the navigation graph and editor How send data between destinations Demo

[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).
[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).

Simple Stack Why do I want this? To make navigation to another screen as simple as backstack.goTo(SomeScreen()), and going back as simple as backstack

Navigation Component: THE BEST WAY to create navigation flows for your app
Navigation Component: THE BEST WAY to create navigation flows for your app

LIVE #017 - Navigation Component: A MELHOR FORMA de criar fluxos de navegação para o seu app! Código fonte do projeto criado na live #017, ensinando c

Navigation Drawer Bottom Navigation View
Navigation Drawer Bottom Navigation View

LIVE #019 - Toolbar, Navigation Drawer e BottomNavigationView com Navigation Com

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps
Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps

Animated Tab Bar is an awesome navigation extension that you can use to add cool, animated and fully customizable tab navigation in your apps. The extension provides handy methods and properties to change the behaviour as well as the appearance of the navigation bar.

A simple, highly customizable compose navigation component for Android & Desktop platform.
A simple, highly customizable compose navigation component for Android & Desktop platform.

介绍 一个简单并提供高度扩展功能的 Compose 导航组件,同时支持 Android 和 Desktop 平台。 常用功能 使用 下载 // Android implementation("io.github.succlz123:compose-screen-android:0.0.1") //

CustomNavigationDrawer - Custom Navigation Drawer with compose
CustomNavigationDrawer - Custom Navigation Drawer with compose

An easy sample to explore navigation component and navigation drawer from Jetpac

Navigation for compose multiplatform

Navigation for compose multiplatform

Jetpack Compose BottomDrawerScaffold (Material Bottom Drawer)
Jetpack Compose BottomDrawerScaffold (Material Bottom Drawer)

BottomDrawerScaffold Current Compose Version: 1.0.2 Compose BottomDrawerScaffold which implements the Material Bottom Drawer https://material.io/compo

Releases(0.1.0)
Owner
Jeziel Lago
Jeziel Lago
🛸Voyager is a pragmatic navigation library built for, and seamlessly integrated with, Jetpack Compose.

Voyager is a pragmatic navigation library built for, and seamlessly integrated with, Jetpack Compose.

Adriel Café 831 Dec 26, 2022
A multi back stack android navigation

Labyrinth A multi back stack android navigation MIT License - Copyright (c) 2020 Abanoub Milad Nassief Hanna [email protected] @Linkedin @Github Scr

Abanoub Milad Nassief Hanna 6 Dec 9, 2022
Annotation processor that provides better navigation on android multi-modules projects 🛳.

FlowNav FlowNav is a mobile library for Android that helps and provider a better way to make multi-modules navigation. The main purpose of this librar

Jeziel Lago 134 Nov 16, 2022
New style for app design simple bottom navigation with side navigation drawer UI made in Jetpack Compose.😉😎

BottomNavWithSideDrawer New style for app design simple bottom navigtaion with side navigation drawer UI made in Jetpack Compose. ?? ?? (Navigation Co

Arvind Meshram 5 Nov 24, 2022
A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

A small navigation library for Android to ease the use of fragment transactions & handling backstack (also available for Jetpack Compose).

Kaustubh Patange 88 Dec 11, 2022
Implementing bottom navigation in jetpack compose

Compose-Bottom-Navigation Implementing bottom navigation in jetpack compose Add the Navigation dependency Open the app's build file, found at app/buil

Steve Chacha 5 Dec 26, 2021
A library that you can use for bottom navigation bar. Written with Jetpack Compose

FancyBottomNavigationBar A library that you can use for bottom navigation bar. W

Alperen Çevlik 3 Jul 27, 2022
A small and simple, yet fully fledged and customizable navigation library for Jetpack Compose

A small and simple, yet fully fledged and customizable navigation library for Jetpack Compose

Vitali Olshevski 290 Dec 29, 2022
A small navigation library for Jetpack Compose with state saving, backstack and animations support.

A small navigation library for Jetpack Compose with state saving, backstack and animations support.

Xinto 5 Dec 27, 2022
Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way.

Alligator Alligator is a modern Android navigation library that will help to organize your navigation code in clean and testable way. Features Any app

Artur Artikov 290 Dec 9, 2022