/navigation

A Conductor integration for the Navigation Architecture Component.

Primary LanguageKotlin

Navigation Component for Conductor

The Android Architecture Navigation Component’s documentation has a section that suggests it is possible to add “new destination types” outside of Activities and Fragments.

Add support for new destination types

NavControllers rely on one or more Navigator objects to perform the navigation operation. To be able to navigate to any other type of destination, one or more additional Navigator objects must be added to the NavController. For example, when using fragments as destinations, the NavHostFragment automatically adds the FragmentNavigator class to its NavController.

The same was suggested on episode 92 of the Android Developers Backstage podcast and at Google IO 2018. There is no shortage of libraries or frameworks utilizing Views as the basis for navigation. Assuming the implementation of the Navigation Architecture Component is generic enough, could it be possible to integrate one of these View-based frameworks with Navigation Component? So far, one has stood above the rest (if Github stars are any indication of success), Conductor.

This library is an attempt to implement a Conductor integration for the Navigation Architecture Component. More details about the implementation are in Navigating Conductor and the Navigation Architecture Component. If this is your first introduction to the Navigation Architecture Component, I would recommend reading the excellent A problem like Navigation series by Maria Neumayer or Android Navigation Components by Dario Mungoi

Usage

res/layout/activity.xml

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
  
    <com.prolificinteractive.conductor.archnavigation.NavHostLayout
        android:id="@+id/controller_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:navGraph="@navigation/graph"/>

</FrameLayout>
res/navigation/graph.xml

<navigation 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    app:startDestination="@+id/firstController">

    <controller
        android:id="@+id/firstController"
        android:name="com.prolificinteractive.conductornav.DemoController"
        android:label="DemoController"
        tools:layout="@layout/controller_navigation_demo">
        <argument
            android:name="index"
            android:defaultValue="0"
            app:type="integer" />
        <argument
            android:name="displayUpMode"
            android:defaultValue="0"
            app:type="integer" />
    </controller>
</navigation>

Installation

Step 1. Add the JitPack repository to your build file

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

Step 2. Add the dependency

dependencies {
    implementation 'com.github.prolificinteractive.navigation:navigation-conductor:0.1.0'
}

Contributing to navigation-conductor

To report a bug or enhancement request, feel free to file an issue under the respective heading.

If you wish to contribute to the project, fork this repo and submit a pull request. Code contributions should follow the standards specified in the Prolific Android Style Guide.

License

prolific

geocoder is Copyright (c) 2018 Prolific Interactive. It may be redistributed under the terms specified in the LICENSE file.