Compose-navigation - Set of utils to help with integrating Jetpack Compose and Jetpack's Navigation

Overview

Jetpack Compose Navigation

Set of utils to help with integrating Jetpack Compose and Jetpack's Navigation

Right now it depends quite heavily on Hilt / Dagger to work. I'm also using jetpack and accompanist from unstable channel, because their features make lots of stuff more convenient. I'll switch over to stable versions once updates are released.

Please keep in mind that this is still in early stage. If you're willing to use it in your project, then please remember that the API is still not set in stone

I'm doing refactors / changes almost every day currently, in hopes that I'll be able to simplify the API even more, so please keep that in mind :)

Releases

Current releases can be found at https://github.com/AdamKobus/compose-navigation/releases

repositories {
    mavenCentral()
}

dependencies {
    implementation "com.adamkobus:compose-navigation:0.1.0"
}

Snapshots

You can find current releases at Sonatype Snapshots Repository

repositories {
    maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
}

dependencies {
    implementation "com.adamkobus:compose-navigation:0.1.0-SNAPSHOT"
}

Features

  • Navigation destinations | Demo

  • Navigation actions | Demo

  • Processing navigation actions | Demo

  • Producing navigation actions in ViewModel | Demo

  • NavGraphBuilder extension | Demo

  • Multi-module project support | Demo

  • Detecting and dismissing duplicate navigation actions | Demo

  • NavAction operator overloads for more convenient actions declaration | Demo

  • Tracking current destination | Demo TBD with settings module

  • Support for dialog | Demo

Links

License

MIT License

Copyright (c) 2022 Adam Kobus

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.
Comments
  • Make it possible to have NavAction that has from and to destinations from different nav hosts

    Make it possible to have NavAction that has from and to destinations from different nav hosts

    It's perfectly find for an action to originate from one navhost and modify the state in different one.

    Example:

    • NavHost1 that has a nested NavHost2 inside it, rendered inside a screen that is part of the NavHost1
    • Screen rendered in NavHost2 wants to change a location in the application to a different one that is part of NavHost1, i.e. because of the way NavIntent was resolved (for example session expiry is detected in nested NavHost2. This produces a NavIntent that redirects the user to sign in screen which is part of NavHost1.
    enhancement 
    opened by AdamKobus 2
  • Add navIntent to `NavGraph`

    Add navIntent to `NavGraph`

    1. navIntent should produce a special type of destination
    2. infix / operator functions on source destination and navIntent should produce special type of NavAction that accepts no navigate nor navigateWithController
    3. Introduce new interface NavIntentMapper. Implementation(s) should be responsible for translating navigation intent into actual NavAction
    4. NavActionConsumerImpl should use NavIntentMappers to translate NavIntents into actual NavActionss. It should throw an exception if mapping failed.
    5. NavIntent should support arguments.
    6. Current tab host navigation handling should be replaced with NavIntent. Reasoning: navigation with this component requires checking the current back stack state.
    7. Change the name of NavActionConsumer to NavigationConsumer
    8. Change the name of NavActionConsumerImpl to NavigationConsumerImpl
    enhancement 
    opened by AdamKobus 2
  • Updated dependencies. 0.3.0 release

    Updated dependencies. 0.3.0 release

    Changes

    Updated AGP to 7.2.2 Other dependencies updates.

    Testing

    Manual testing.

    Checklist

    General

    • [x] PR targets the develop branch
    • [ ] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [ ] New code is covered by unit tests
    • [ ] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    configuration 
    opened by AdamKobus 1
  • Resolves #105 Improvements to TabBarIntentResolver

    Resolves #105 Improvements to TabBarIntentResolver

    Changes

    TabBarIntentResolver now supports popOptions

    Testing

    Demo app

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [ ] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [ ] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [ ] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Resolves #95 Refactor of multi navhostcontroller handling

    Resolves #95 Refactor of multi navhostcontroller handling

    Changes

    Simplified navaction / intent processing. After those changes:

    • each navintent is resolved only once
    • each navaction is verified only once
    • NavigationProcessor selects pending action dispatchers that are suitable for the resolved action.
    • Made it possible to process actions with source and target destinations that belong to different graphs (#97 )

    Testing

    Demo apps.

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [x] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Resolves #101 Added support for more arg types

    Resolves #101 Added support for more arg types

    Changes

    Added support for Long, Float, Double and Boolean arguments.

    Testing

    Unit tests + checking if apps work properly

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [x] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Resolves #100 Added better error messages

    Resolves #100 Added better error messages

    Changes

    Added better error messages to NavStackEntry

    Testing

    Unit tests + manual testing

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [x] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Fixes #96 - NavStackEntry is no longer nullable in composableDestination

    Fixes #96 - NavStackEntry is no longer nullable in composableDestination

    Changes

    NavStackEntry is no longer nullable in composableDestination

    Testing

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [ ] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Resolves #15 Added dev menu demo

    Resolves #15 Added dev menu demo

    Changes

    • Added dev menu demo
    • NavState now has a list of NavControllerStates which gives access to information about all used NavHosts
    • NavIntent has an additional field now which is called navigationId. It's just for informational purpose and doesn't influence the intents processing.
    • Added signing config so that it's possible to test the apps in release build type.

    Testing

    In demo app by tapping the middle of the app bar twice. It will open the dev menu. Tapping the app bar like that in release build type should do nothing.

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [ ] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Resolves #90 Made sure that it's possible to use infix functions as a builder

    Resolves #90 Made sure that it's possible to use infix functions as a builder

    Changes

    Made sure that it's possible to use infix functions as a builder pattern instead. Added setNavOptions method to make builder approach more convenient.

    Testing

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [x] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Resolves #84 Demo for multiple nav hosts

    Resolves #84 Demo for multiple nav hosts

    Changes

    Added support for nested nav hosts

    Testing

    Using the newly added proof of concept app

    Checklist

    General

    • [x] PR targets the develop branch
    • [x] PR is linked to the GitHub issue it resolves

    Source code and docs

    • [x] Changelog is updated (fixes section for a bug, changes for anything that has been added / modified/ removed)
    • [ ] New code is covered by unit tests
    • [x] Added ktdoc and updated README.md if API has changed
    • [x] Made sure that unit tests pass
    • [x] Made sure that ktlintCheck and detekt tasks produce no issues
    • [x] Updated demo app if needed

    Reviewer Checklist

    • [x] Library builds
    • [x] Demo app works
    • [x] Changes work as expected
    • [x] Changelog and documentation updates reflect the modification made in this PR
    opened by AdamKobus 1
  • Make it possible to deliver an action or intent to a NavHost explicitly

    Make it possible to deliver an action or intent to a NavHost explicitly

    Add an optional argument navigationId: NavigationId to all offer methods.

    When present, this navigationId should be used by the library to select a specific NavigationProcessor to process offered action or intent.

    enhancement 
    opened by AdamKobus 0
  • Provide a way to declare @Composable element provider inside NavDestination

    Provide a way to declare @Composable element provider inside NavDestination

    Goal is to remove the need for NavGraphBuilder extension declaration. Instead, NavGraphBuilder have only one generic extension that populates the graph based on provided NavGraph.

    Some more details have already been described in #63

    enhancement on hold 
    opened by AdamKobus 0
  • Investigate the possibility to move arguments from NavAction to INavDestination

    Investigate the possibility to move arguments from NavAction to INavDestination

    Reasoning is that destinations need args to render properly, always. NavAction's role is to simply deliver them to the new destination.

    Once arguments become part of destination, it will be possible to do something like this:

    // could be serialized using Gson
    data class DetailScreenArgs(
        @SerializedName("itemId")
        val itemId: Int
    )
    
    object MyGraph : NavGraph("myGraph") {
    
        val List = navDestination("list") { ListScreen() }
    
        val Detail = List.nextWithArgs<DetailScreenArgs> {
            param("itemId")
        } { args -> DetailScreen(args) }
    }
    

    This way destination would declare both, the type of the used args and how it renders in one place. This could potentially make it possible to automatically build a graph with NavGraphBuilder. NavGraph methods like navDestination could remember created destiantions. This will simplify the graphs definition by a lot

    Also, args should be part of the information about back stack. Currently, there is no real way to tell apart 2 instances of the same destination, even if they are launched with different set of arguments.

    Potential issues:

    1. How should the destination like the one below work:
      val ListDetail = List.nextWithArgs<DetailScreenArgs> {
          param("itemId")
      } { args -> DetailScreen(args) }
      
      val PicturePreview = Detail .nextWithArgs<PicturePreivewArgs> {
         path("picture")
         param("pictureId")
      } { args -> PicturePreviewScreen(args) }
      

      Args would need to carry both, "itemId" and "pictureId" fields. Should "pictureId" and "itemId" constants be defined in common module then?

    enhancement on hold 
    opened by AdamKobus 0
  • Demo of versioned feature modules

    Demo of versioned feature modules

    Demonstrate how to achieve different versions of same feature in this app using Settings screen as an example. Goal is to have demo-ui-settings-v1 and demo-ui-settings-v2 in the project (plus demo-ui-settings-common for shared components). It should be possible to configure which version of the feature is included in the build (i.e. using project properties).

    demo 
    opened by AdamKobus 0
Releases(0.3.0)
  • 0.3.0(Aug 12, 2022)

    Changes

    • Added NavDestination.popUpTo which is equivalent of NavHostController.popBackStack(route, saveState, inclusive)
    • NavRoute and NavRouteBuilder no longer accept custom path separators. Separator is now hardcoded to '/'
    • Added ComposeNavHost. It is now a recommended way to declare NavHost
    • Introduced NavigationId which should be used to differentiate separate NavHostControllers / NavHosts.
    • ComposeNavigation.getNavigationStateSource() now requires NavigationId param
    • Tasks processing now has a configurable timeout. By default it's set to 1000ms. You can change it to your own value via ComposeNavigation.setNavigationProcessingTimeout
    • Improved stability of navigation processor initialization logic.
    • Added ComposeNavigation.setIoDispatcher
    • Added support for nested Nav Hosts
    • NavState now has a list of NavControllerStates which gives access to information about all used NavHosts
    • NavIntent has an additional field now which is called navigationId. It's just for informational purpose and it doesn't influence the intents processing.
    • #96 NavStackEntry is no longer nullable in composableDestination lambda
    • Improved error messages when reading NavStackEntry arguments
    • Added support for Long, Float, Double and Boolean navigation arguments
    • updated AGP to 7.2.2, updated other dependencies
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Feb 17, 2022)

    Fixes

    • #26 NavDestinationManager.currentDestination change to the first visible screen happens instantly on app launch now.

    Changes

    • Updated dependencies
    • NavActionVerifier now returns VerifyResult enum instead of Boolean
    • Improved the current destination evaluation code
    • Prepared the code for handling nested / multiple NavHosts
    • INavAction name was changed to NavAction and it now has 2 different implementations: NavigateAction and PopAction
    • INavDestination now has 4 different implementations: NavGraph, ScreenDestination, DialogDestination and PopDestination. This makes it easy to determine which type of action should be performed and provides more info about back stack.
    • NavActionWrapper is now an abstract class so that there is less boilerplate code in NavActions declarations using sealed classes.
    • NavGraph is now an abstract class that requires name to be passed in constructor
    • NavGraph now has abstract method startDestination()
    • NavGraphBuilder.composableNavigation no longer accepts startDestination as a param.
    • NavComposable now accepts vararg observedGraphs: NavGraph. If any NavGraph is provided, then received actions will be filtered only to those with fromDestination belonging to provided graph(s)
    • Added NavLogger
    • Added NavDestinationManager - it provides information about current destination and back stack queue
    • Added ComposeNavigation which should be used to configure the library and get access to its state
    • Moved documentation to docs
    • Names starting with double underscore (i.e. __myGraph) are now reserved for internal usage. Trying to declare graph, path or param name like this will now result in ReservedNameError being thrown. This behaviour can be disabled using ComposeNavigation.disableRestrictedNamesCheck()
    • NavActionConsumer interface name was changed to NavigationConsumer
    • Removed all + operators and changed the name of to infix function to goTo and pop. Using to was annoying sometimes because Kotlin would try to interpret it as map in some circumstances.
    • Added NavIntent, NavIntentResolver and ResolveResult
    • ComposeNavigation now has addNavIntentResolvers() method which you can use to register your own NavIntentResolvers
    • Added TabBarIntentResolver - an implementation of NavIntentResolver which handles many edge cases related to tab bar navigation.
    • NavAction now has asResult method which produces ResolveResult - a class that indicates the processing result by NavIntentResolver
    • All of the infix functions related to building NavigateAction and PopAction were moved to NavDestination class.
    • Removed dependency on Hilt. ComposeNavigation object is now responsible for providing all of the dependencies.
    • Added NavOptionsBuilder.popUpTo extensions
    • Updated Jetpack compose to 1.2.0-alpha03
    • Updated Accompanist to 0.24.2-alpha
    • NavGraph no longer has navDestination method. From now on you should use screenDestination and dialogDestination instead.
    • removed com.adamkobus.compose.navigation.data package. Classes were moved to .action, .destination and .intent packages.
    • CurrentDestination class was replaced by NavState. Also added NavStackEntry class which holds both destination and the arguments with which it was launched.
    • NavGraphBuilder.composableDestination and NavGraphBuilder.composableDialog content lambda now accepts NavStackEntry instead of NavBackStackEntry
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Feb 3, 2022)

Owner
Adam Kobus
Adam Kobus
android project themplate including network(retrofit), utils(image, permission, etc), etc

Template-Android When starting a new Android project, it is boring to write some codes such as permission verification, network interface creation, wh

null 2 Oct 29, 2022
Android Jetpack is a set of components, tools and guidance to make great Android apps.

Android Jetpack is a set of components, tools and guidance to make great Android apps. They bring together the existing Support Library and Architecture Components and arrange them into four categories.

Atik Faysal 0 Dec 8, 2021
A library that enables Safe Navigation for you Composable destinations when using Jetpack Compose Navigation

A library that enables Safe Navigation for you Composable destinations when using Jetpack Compose Navigation

Roman Levinzon 59 Oct 19, 2022
Compose-buttons - A set of Loading animations used in Buttons to convey a "loading" state after the button is clicked.

Loading Buttons A set of Loading animations used in Buttons to convey a "loading" state after the button is clicked. A simple demo application that sh

Brad Ball 16 Jul 5, 2022
Field state manager and basic set of validation, fields

Compose Forms Field state manager and basic set of validation, fields

Vitaliy Zarubin 9 Jan 4, 2022
A Simple Blog App using Jetpack Compose, Flow, Navigation Compose, Room and Firebase

BlogCompose A Simple Blog App using Jetpack Compose, Flow, Navigation Compose, Room and Firebase Instructions Download your Firebase configuration fil

null 4 Oct 10, 2022
Navigation-Compose - A sample to showcase Kotlin, MVVM, Hilt, Coroutines, StateFlow, Jetpack compose

Navigation-Compose A sample to showcase Kotlin, MVVM, Hilt, Coroutines, StateFlo

Mohammadali Rezaei 6 Jul 13, 2022
Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cached data by Room

Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cached data by Room

Yogi Dewansyah 13 Aug 31, 2022
Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cached data by Room

Mobile Banking Android App made by Jetpack Compose Components with Kotlin, MVVM Pattern, Multi Module, Navigation, Hilt, Coroutines, Retrofit and cach

Yogi Dewansyah 13 Aug 31, 2022
A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose

Authentication A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose Scree

Felix Kariuki 5 Dec 29, 2022
This repos one of the ways hows how to use Jetpack Compose Navigation along with Dagger 2

Dagger 2 and Jetpack Compose Integration This repository is about a way how to use Dagger 2 for projects which using Jetpack Compose. Here is an artic

Alexey Glukharev 10 Nov 16, 2022
Create Bottom Navigation Bar with Jetpack Compose

BottomNavigationBarComposeExample Create Bottom Navigation Bar with Jetpack Compose https://johncodeos.com/how-to-create-bottom-navigation-bar-with-je

JohnCodeos.com 31 Dec 24, 2022
Small Android project demonstrating some navigation components for Jetpack Compose.

Small Android project demonstrating some navigation components for Jetpack Compose. Created this for presenting about this topic for a GDG meetup.

Parshav 3 Sep 15, 2021
Small code generating library for safe Jetpack Compose navigation with no boilerplate.

Compose Destinations A KSP library to use alongside compose navigation. It reduces boilerplate code and is less error-prone since passing arguments be

Rafael Costa 1.9k Jan 5, 2023
Kotlin, MVVM, Navigation Component, Hilt, Jetpack Compose, Retrofit2

What is this project? This course will replace my old java mvvm introduction: https://codingwithmitch.com/courses/rest-api-mvvm-retrofit2/. Watch the

Mitch Tabian 452 Jan 1, 2023
[Tutorial] D-pad navigation in Jetpack Compose

dpad-compose D-pad navigation in Jetpack Compose The problem While Android is mostly used on touch devices, the operating system can also be used with

Walter Berggren 34 Nov 4, 2022
Android Sample Kotlin+ MVI + Jetpack compose + Coroutines + Retrofit + Hilt + Room + Navigation component

MVIComposeSample Android Sample app to show user latest movies implementing MVI + Clean Architecture using kotlin & Jetpack compose following solid an

Ahmed Atwa 10 Dec 28, 2022
Model-driven navigation for Jetpack Compose

Model-driven navigation for Jetpack Compose

null 588 Dec 27, 2022
An app for Android that uses quizzes to help you learn more about computer science.

Quiz App An app for Android that uses quizzes to help you learn more about computer science. ?? Screenshots No screenshot available yet ?? Tech Stack

Ivan Ramos 2 Nov 8, 2022