Skip to content

MobileAct/NavigationExtensions

Repository files navigation

NavigationExtensions

navex is extension for AndroidX Navigation.

This repository is not published to Maven. It may be released if there are many requests.

Summary

navex provides some extensions

package description tested
navext-activity-request launching activity navigator, call Activity.startActivityForResult
navext-activity-result pop activity navigator, call Activity.setResult & Activity.finish
navext-fragment-styled navigation graph based style navigator, extension for FragmentNavigator
navext-fragment hosting some navigator Fragment

Usage

navext-fragment-styled

FragmentStyledNavigatior is extension for define different resource and transition on navigation graph.

  1. add attributes, res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Screen">
        <attr format="string" name="title"/>
        <attr format="string" name="description"/>
    </declare-styleable>
</resources>
  1. add style, res/values
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Screen">
        <item name="title"/>
        <item name="description"/>
    </style>

    <style name="Screen.Route1.First" parent="Screen">
        <item name="title">Route1 First</item>
        <item name="description">Rout1 First Description</item>
    </style>

    <style name="Screen.Route1.Second" parent="Screen">
        <item name="title">Route1 Second</item>
        <item name="description">Rout1 Second Description</item>
    </style>
</resources>
  1. add fragment
    styledNavNextId() and styledNavArg() value is injected on NavigationGraph
class ScreenFragment : Fragment() {

    private val nextId by styledNavNextId()
    private val argumentTitle by styledNavArg(R.attr.title) { getString() }
    private val argumentDescription by styledNavArg(R.attr.description) { getString() }
}
  1. add navigation graph, res/navigation
<?xml version="1.0" encoding="utf-8"?>
<navigation android:id="@+id/navigation_main"
            app:startDestination="@id/startFragment"
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto">

    <fragment
        android:id="@+id/startFragment"
        android:name="navext.app.StartFragment">
        <action
            android:id="@+id/transitionToRoute1First"
            app:destination="@+id/route1First"/>
        <action
            android:id="@+id/transitionToRoute2First"
            app:destination="@id/route2First"/>
    </fragment>

    <fragment-styled
        android:id="@+id/route1First"
        android:name="navext.app.ScreenFragment"
        app:nextId="@id/transitionToRoute1Second"
        app:style="@style/Screen.Route1.First">
        <action
            android:id="@+id/transitionToRoute1Second"
            app:destination="@+id/route1Second"/>
    </fragment-styled>

    <fragment-styled
        android:id="@+id/route1Second"
        android:name="navext.app.ScreenFragment"
        app:nextId="@id/transitionToRoute1Third"
        app:style="@style/Screen.Route1.Second">
        <action
            android:id="@+id/transitionToRoute1Third"
            app:destination="@id/route1Third"/>
    </fragment-styled>
  
    <!-- etc... -->
</navigation>

License

This library is under MIT License

Extension

Sample

Other

Author: @MeilCli

About

navex is extension for AndroidX Navigation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages