androidx.navigation


Interfaces

FloatingWindow

A marker interface for NavDestination subclasses that float above the view of other destinations (i.e. androidx.navigation.fragment.DialogFragmentNavigator.Destination).

Cmn
NavArgs

An interface marking generated Args classes.

android
NavController.OnDestinationChangedListener

OnDestinationChangedListener receives a callback when the currentDestination or its arguments change.

Cmn
android
NavDirections

An interface that describes a navigation operation: action's id and arguments

android
NavHost

A host is a single context or container for navigation via a NavController.

Cmn
Navigator.Extras

Interface indicating that this class should be passed to its respective Navigator to enable Navigator specific behavior.

Cmn
android
SupportingPane

A marker interface for NavDestination subclasses that sit alongside the view of other destinations.

Cmn

Classes

ActionOnlyNavDirections

An implementation of NavDirections without any arguments.

android
ActivityNavigator

ActivityNavigator implements cross-activity navigation.

android
ActivityNavigator.Destination

NavDestination for activity navigation

android
ActivityNavigator.Extras

Extras that can be passed to ActivityNavigator to customize what ActivityOptionsCompat and flags are passed through to the call to ActivityCompat.startActivity.

android
ActivityNavigator.Extras.Builder

Builder for constructing new Extras instances.

android
ActivityNavigatorDestinationBuilder

DSL for constructing a new ActivityNavigator.Destination

android
AnimBuilder

DSL for setting custom Animation or Animator resources on a NavOptionsBuilder

android
CollectionNavType

A NavType for Collection such as arrays, lists, maps.

Cmn
NamedNavArgument

Construct a named NavArgument by using the navArgument method.

Cmn
NavAction

Navigation actions provide a level of indirection between your navigation code and the underlying destinations.

android
NavActionBuilder

DSL for building a NavAction.

android
NavArgsLazy

An implementation of Lazy used by android.app.Activity.navArgs and androidx.fragment.app.Fragment.navArgs.

android
NavArgument

NavArgument denotes an argument that is supported by a NavDestination.

Cmn
NavArgument.Builder

A builder for constructing NavArgument instances.

Cmn
NavArgumentBuilder

DSL for constructing a new NavArgument

Cmn
NavBackStackEntry

Representation of an entry in the back stack of a androidx.navigation.NavController.

Cmn
android
NavController

NavController manages app navigation within a NavHost.

Cmn
android
NavDeepLink

NavDeepLink encapsulates the parsing and matching of a navigation deep link.

Cmn
NavDeepLink.Builder

A builder for constructing NavDeepLink instances.

Cmn
NavDeepLinkBuilder

Class used to construct deep links to a particular destination in a NavGraph.

android
NavDeepLinkDslBuilder

DSL for constructing a new NavDeepLink

Cmn
NavDeepLinkRequest

A request for a deep link in a NavDestination.

Cmn
android
NavDeepLinkRequest.Builder

A builder for constructing NavDeepLinkRequest instances.

Cmn
android
NavDestination

NavDestination represents one node within an overall navigation graph.

Cmn
android
NavDestinationBuilder

DSL for constructing a new NavDestination

Cmn
android
NavGraph

NavGraph is a collection of NavDestination nodes fetchable by ID.

Cmn
android
NavGraphBuilder

DSL for constructing a new NavGraph

Cmn
android
NavGraphNavigator

A Navigator built specifically for NavGraph elements.

Cmn
android
NavHostController

Subclass of NavController that offers additional APIs for use by a NavHost to connect the NavController to external dependencies.

Cmn
android
NavInflater

Class which translates a navigation XML file into a NavGraph

android
NavOptions

NavOptions stores special options for navigate actions

Cmn
android
NavOptions.Builder

Builder for constructing new instances of NavOptions.

Cmn
android
NavOptionsBuilder

DSL for constructing a new NavOptions

Cmn
android
NavType

NavType denotes the type that can be used in a NavArgument.

Cmn
android
NavUri
Cmn
android
Navigator

Navigator defines a mechanism for navigating within an app.

Cmn
android
NavigatorProvider

A NavigationProvider stores a set of Navigators that are valid ways to navigate to a destination.

Cmn
android
NavigatorState

The NavigatorState encapsulates the state shared between the Navigator and the NavController.

Cmn
PopUpToBuilder

DSL for customizing NavOptionsBuilder.popUpTo operations.

Cmn

Objects

Navigation

Entry point for navigation operations.

Cmn
android

Annotations

Type aliases

NavUri
android

Top-level functions summary

ActivityNavigator.Extras
ActivityNavigatorExtras(
    activityOptions: ActivityOptionsCompat?,
    flags: Int
)

Create a new ActivityNavigator.Extras instance with a specific ActivityOptionsCompat instance and/or any Intent.FLAG_ACTIVITY_ flags.

android
NamedNavArgument
navArgument(name: String, builder: NavArgumentBuilder.() -> Unit)

Construct a new NavArgument

Cmn
NavDeepLink
navDeepLink(deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit)

Construct a new NavDeepLink

Cmn
inline NavDeepLink
<T : Any> navDeepLink(
    basePath: String,
    typeMap: Map<KTypeNavType<*>>,
    noinline deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit
)

Construct a new NavDeepLink

Cmn
NavDeepLink
<T : Any> navDeepLink(
    route: KClass<T>,
    basePath: String,
    typeMap: Map<KTypeNavType<*>>,
    deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit
)

Construct a new NavDeepLink

Cmn
NavOptions
navOptions(optionsBuilder: NavOptionsBuilder.() -> Unit)

Construct a new NavOptions

Cmn

Extension functions summary

inline Unit

This function is deprecated. Use routes to build your ActivityDestination instead

android
inline Unit

Construct a new ActivityNavigator.Destination

android
inline Unit
<T : Any> NavGraphBuilder.activity(
    typeMap: Map<KTypeNavType<*>>,
    builder: ActivityNavigatorDestinationBuilder.() -> Unit
)

Construct a new ActivityNavigator.Destination

android
operator Boolean

Returns true if a destination with id is found in this navigation graph.

android
inline operator Boolean
<T : Any> NavGraph.contains(route: KClass<T>)

Returns true if a destination with route is found in this navigation graph.

Cmn
operator Boolean

Returns true if a destination with route is found in this navigation graph.

Cmn
operator Boolean
<T : Any> NavGraph.contains(route: T)

Returns true if a destination with route is found in this navigation graph.

Cmn
inline NavGraph
NavController.createGraph(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to create your NavGraph instead

android
inline NavGraph
NavHost.createGraph(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to create your NavGraph instead

android
inline NavGraph
NavController.createGraph(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline NavGraph
NavHost.createGraph(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline NavGraph
NavController.createGraph(
    startDestination: Any,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline NavGraph
NavHost.createGraph(
    startDestination: Any,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline NavGraph
NavController.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline NavGraph
NavHost.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
NavController

Find a NavController associated with a View.

android
NavController

Find a NavController given the id of a View and its containing Activity.

android
inline operator T

Retrieves a registered Navigator using the name provided by the Navigator.Name.

Cmn
android
inline operator NavDestination

Returns the destination with id.

android
inline operator T

Retrieves a registered Navigator by name.

Cmn
inline operator NavDestination
<T : Any> NavGraph.get(route: KClass<T>)

Returns the destination with route from KClass.

Cmn
inline operator NavDestination

Returns the destination with route.

Cmn
inline operator NavDestination
<T : Any> NavGraph.get(route: T)

Returns the destination with route from an Object.

Cmn
inline operator Unit

Removes node from this navigation graph.

Cmn
inline NavArgsLazy<Args>

Returns a Lazy delegate to access the Activity's extras as an Args instance.

android
inline Lazy<VM>
@MainThread
<VM : ViewModel> Fragment.navGraphViewModels(
    navGraphId: @IdRes Int,
    noinline extrasProducer: (() -> CreationExtras)?,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)?
)

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

android
inline Lazy<VM>
@MainThread
<VM : ViewModel> Fragment.navGraphViewModels(
    navGraphRoute: String,
    noinline extrasProducer: (() -> CreationExtras)?,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)?
)

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

android
inline NavGraph
NavigatorProvider.navigation(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to build your NavGraph instead

android
inline Unit
NavGraphBuilder.navigation(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
)

This function is deprecated. Use routes to build your nested NavGraph instead

android
inline Unit
<T : Any> NavGraphBuilder.navigation(
    startDestination: Any,
    typeMap: Map<KTypeNavType<*>>,
    noinline builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

Cmn
inline Unit
<T : Any> NavGraphBuilder.navigation(
    startDestination: KClass<*>,
    typeMap: Map<KTypeNavType<*>>,
    noinline builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

Cmn
inline NavGraph
NavigatorProvider.navigation(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline Unit
NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

Cmn
Unit
<T : Any> NavGraphBuilder.navigation(
    route: KClass<T>,
    startDestination: Any,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

Cmn
Unit
<T : Any> NavGraphBuilder.navigation(
    route: KClass<T>,
    startDestination: KClass<*>,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

Cmn
inline NavGraph
NavigatorProvider.navigation(
    startDestination: Any,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline NavGraph
NavigatorProvider.navigation(
    startDestination: KClass<*>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new NavGraph

Cmn
inline operator Unit

Register a navigator using the name provided by the Navigator.Name.

Cmn
inline operator Unit

Adds a destination to this NavGraph.

Cmn
inline operator Unit

Add all destinations from another collection to this one.

Cmn
inline operator Navigator<NavDestination>?
NavigatorProvider.set(
    name: String,
    navigator: Navigator<NavDestination>
)

Register a Navigator by name.

Cmn
inline T

Returns route as an object of type T

Cmn
T
<T : Any?> NavBackStackEntry.toRoute(route: KClass<*>)

Returns route as an object of type T

Cmn
inline T
<T : Any> SavedStateHandle.toRoute(typeMap: Map<KTypeNavType<*>>)

Returns route as an object of type T

Cmn
T
<T : Any> SavedStateHandle.toRoute(
    route: KClass<T>,
    typeMap: Map<KTypeNavType<*>>
)

Returns route as an object of type T

Cmn

Top-level functions

ActivityNavigatorExtras

fun ActivityNavigatorExtras(
    activityOptions: ActivityOptionsCompat? = null,
    flags: Int = 0
): ActivityNavigator.Extras

Create a new ActivityNavigator.Extras instance with a specific ActivityOptionsCompat instance and/or any Intent.FLAG_ACTIVITY_ flags.

Parameters
activityOptions: ActivityOptionsCompat? = null

Optional ActivityOptionsCompat to pass through to androidx.core.app.ActivityCompat.startActivity.

flags: Int = 0

Intent.FLAG_ACTIVITY_ flags to add to the Intent.

fun navArgument(name: String, builder: NavArgumentBuilder.() -> Unit): NamedNavArgument

Construct a new NavArgument

fun navDeepLink(deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit): NavDeepLink

Construct a new NavDeepLink

Parameters
deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit

the builder used to construct the deeplink

inline fun <T : Any> navDeepLink(
    basePath: String,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    noinline deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit = {}
): NavDeepLink

Construct a new NavDeepLink

Extracts deeplink arguments from T and appends it to the basePath. The base path & generated arguments form the final uri pattern for the deeplink.

See docs on the safe args version of NavDeepLink.Builder.setUriPattern for the final uriPattern's generation logic.

Parameters
<T : Any>

The deepLink KClass to extract arguments from

basePath: String

The base uri path to append arguments onto

typeMap: Map<KTypeNavType<*>> = emptyMap()

map of destination arguments' kotlin type KType to its respective custom NavType. May be empty if T does not use custom NavTypes.

noinline deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit = {}

the builder used to construct the deeplink

fun <T : Any> navDeepLink(
    route: KClass<T>,
    basePath: String,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit
): NavDeepLink

Construct a new NavDeepLink

Extracts deeplink arguments from T and appends it to the basePath. The base path & generated arguments form the final uri pattern for the deeplink.

See docs on the safe args version of NavDeepLink.Builder.setUriPattern for the final uriPattern's generation logic.

Parameters
route: KClass<T>

The deepLink KClass to extract arguments from

basePath: String

The base uri path to append arguments onto

typeMap: Map<KTypeNavType<*>> = emptyMap()

map of destination arguments' kotlin type KType to its respective custom NavType. May be empty if route does not use custom NavTypes.

deepLinkBuilder: NavDeepLinkDslBuilder.() -> Unit

the builder used to construct the deeplink

fun navOptions(optionsBuilder: NavOptionsBuilder.() -> Unit): NavOptions

Construct a new NavOptions

Extension functions

activity

inline fun NavGraphBuilder.activity(id: @IdRes Int, builder: ActivityNavigatorDestinationBuilder.() -> Unit): Unit

Construct a new ActivityNavigator.Destination

activity

inline fun NavGraphBuilder.activity(route: String, builder: ActivityNavigatorDestinationBuilder.() -> Unit): Unit

Construct a new ActivityNavigator.Destination

inline fun <T : Any> NavGraphBuilder.activity(
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: ActivityNavigatorDestinationBuilder.() -> Unit
): Unit

Construct a new ActivityNavigator.Destination

Parameters
<T : Any>

destination's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

map of destination arguments' kotlin type KType to its respective custom NavType. May be empty if T does not use custom NavTypes.

builder: ActivityNavigatorDestinationBuilder.() -> Unit

the builder used to construct the fragment destination

contains

operator fun NavGraph.contains(id: @IdRes Int): Boolean

Returns true if a destination with id is found in this navigation graph.

inline operator fun <T : Any> NavGraph.contains(route: KClass<T>): Boolean

Returns true if a destination with route is found in this navigation graph.

contains

operator fun NavGraph.contains(route: String): Boolean

Returns true if a destination with route is found in this navigation graph.

contains

operator fun <T : Any> NavGraph.contains(route: T): Boolean

Returns true if a destination with route is found in this navigation graph.

createGraph

inline fun NavController.createGraph(
    id: @IdRes Int = 0,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
id: @IdRes Int = 0

the graph's unique id

startDestination: @IdRes Int

the route for the start destination

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

createGraph

inline fun NavHost.createGraph(
    id: @IdRes Int = 0,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

createGraph

inline fun NavController.createGraph(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: String

the route for the start destination

route: String? = null

the route for the graph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

createGraph

inline fun NavHost.createGraph(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

createGraph

inline fun NavController.createGraph(
    startDestination: Any,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: Any

the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added as a KClass in order to match.

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

createGraph

inline fun NavHost.createGraph(
    startDestination: Any,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: Any

the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added as a KClass in order to match.

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

createGraph

inline fun NavController.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: KClass<*>

the starting destination's route from a KClass for this NavGraph. The respective NavDestination must be added as a KClass in order to match.

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

createGraph

inline fun NavHost.createGraph(
    startDestination: KClass<*>,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: KClass<*>

the starting destination's route from a KClass for this NavGraph. The respective NavDestination must be added as a KClass in order to match.

route: KClass<*>? = null

the graph's unique route from a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

findNavController

fun View.findNavController(): NavController

Find a NavController associated with a View.

Calling this on a View not within a NavHost will result in an IllegalStateException

findNavController

fun Activity.findNavController(viewId: @IdRes Int): NavController

Find a NavController given the id of a View and its containing Activity.

Calling this on a View that is not a NavHost or within a NavHost will result in an IllegalStateException

get

inline operator fun <T : Navigator<NavDestination>> NavigatorProvider.get(clazz: KClass<T>): T

Retrieves a registered Navigator using the name provided by the Navigator.Name.

Throws
kotlin.IllegalStateException

if the Navigator has not been added

inline operator fun NavGraph.get(id: @IdRes Int): NavDestination

Returns the destination with id.

Throws
kotlin.IllegalArgumentException

if no destination is found with that id.

inline operator fun <T : Navigator<NavDestination>> NavigatorProvider.get(name: String): T

Retrieves a registered Navigator by name.

Throws
kotlin.IllegalStateException

if the Navigator has not been added

inline operator fun <T : Any> NavGraph.get(route: KClass<T>): NavDestination

Returns the destination with route from KClass.

Throws
kotlin.IllegalArgumentException

if no destination is found with that route.

inline operator fun NavGraph.get(route: String): NavDestination

Returns the destination with route.

Throws
kotlin.IllegalArgumentException

if no destination is found with that route.

inline operator fun <T : Any> NavGraph.get(route: T): NavDestination

Returns the destination with route from an Object.

Throws
kotlin.IllegalArgumentException

if no destination is found with that route.

minusAssign

inline operator fun NavGraph.minusAssign(node: NavDestination): Unit

Removes node from this navigation graph.

@MainThread
inline fun <Args : NavArgs> Activity.navArgs(): NavArgsLazy<Args>

Returns a Lazy delegate to access the Activity's extras as an Args instance.

It is strongly recommended that this method only be used when the Activity is started by androidx.navigation.NavController.navigate with the corresponding androidx.navigation.NavDirections object, which ensures that the required arguments are present.

class MyActivity : Activity() {
val args: MyActivityArgs by navArgs()
}

This property can be accessed only after the Activity is attached to the Application, and access prior to that will result in IllegalStateException.

navGraphViewModels

@MainThread
inline fun <VM : ViewModel> Fragment.navGraphViewModels(
    navGraphId: @IdRes Int,
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

class MyFragment : Fragment() {
val viewmodel: MainViewModel by navGraphViewModels(R.id.main)
}

Custom ViewModelProvider.Factory can be defined via factoryProducer parameter, factory returned by it will be used to create ViewModel:

class MyFragment : Fragment() {
val viewmodel: MainViewModel by navGraphViewModels(R.id.main) { myFactory }
}

This property can be accessed only after this NavGraph is on the NavController back stack, and an attempt access prior to that will result in an IllegalArgumentException.

Parameters
navGraphId: @IdRes Int

ID of a NavGraph that exists on the NavController back stack

noinline extrasProducer: (() -> CreationExtras)? = null

lambda that will be called during initialization to return CreationExtras. If none is provided, this will use the extras from the NavBackStackEntry referenced by the navGraphId.

noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null

lambda that will be called during initialization to return ViewModelProvider.Factory. If none is provided, this will use the factory from the NavBackStackEntry referenced by the navGraphId.

navGraphViewModels

@MainThread
inline fun <VM : ViewModel> Fragment.navGraphViewModels(
    navGraphRoute: String,
    noinline extrasProducer: (() -> CreationExtras)? = null,
    noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null
): Lazy<VM>

Returns a property delegate to access a ViewModel scoped to a navigation graph present on the NavController back stack:

class MyFragment : Fragment() {
val viewModel: MainViewModel by navGraphViewModels("main")
}

Custom ViewModelProvider.Factory can be defined via factoryProducer parameter, factory returned by it will be used to create ViewModel:

class MyFragment : Fragment() {
val viewModel: MainViewModel by navGraphViewModels("main") { myFactory }
}

This property can be accessed only after this NavGraph is on the NavController back stack, and an attempt access prior to that will result in an IllegalArgumentException.

Parameters
navGraphRoute: String

NavDestination.route of a NavGraph that exists on the NavController back stack. If a NavDestination with the given route does not exist on the back stack, an IllegalArgumentException will be thrown.

noinline extrasProducer: (() -> CreationExtras)? = null

lambda that will be called during initialization to return CreationExtras. If none is provided, this will use the extras from the NavBackStackEntry referenced by the navGraphRoute.

noinline factoryProducer: (() -> ViewModelProvider.Factory)? = null

lambda that will be called during initialization to return ViewModelProvider.Factory. If none is provided, this will use the factory from the NavBackStackEntry referenced by the navGraphRoute.

navigation

inline fun NavigatorProvider.navigation(
    id: @IdRes Int = 0,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
id: @IdRes Int = 0

the destination's unique id

startDestination: @IdRes Int

the starting destination for this NavGraph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
NavGraph

the newly constructed NavGraph

navigation

inline fun NavGraphBuilder.navigation(
    id: @IdRes Int,
    startDestination: @IdRes Int,
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
id: @IdRes Int

the destination's unique id

startDestination: @IdRes Int

the starting destination for this NavGraph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

inline fun <T : Any> NavGraphBuilder.navigation(
    startDestination: Any,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    noinline builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
<T : Any>

the graph's unique route from a KClass

startDestination: Any

the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added with route from a KClass in order to match.

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the T. May be empty if T does not use custom NavTypes.

noinline builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

inline fun <T : Any> NavGraphBuilder.navigation(
    startDestination: KClass<*>,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    noinline builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
<T : Any>

the graph's unique route from a KClass

startDestination: KClass<*>

the starting destination's route from a KClass for this NavGraph. The respective NavDestination must be added with route from a KClass in order to match.

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the T. May be empty if T does not use custom NavTypes.

noinline builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

navigation

inline fun NavigatorProvider.navigation(
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: String

the starting destination's route for this NavGraph

route: String? = null

the destination's unique route

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
NavGraph

the newly constructed NavGraph

navigation

inline fun NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
startDestination: String

the starting destination's route for this NavGraph

route: String

the destination's unique route

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

fun <T : Any> NavGraphBuilder.navigation(
    route: KClass<T>,
    startDestination: Any,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
route: KClass<T>

the graph's unique route from a KClass

startDestination: Any

the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added with route from a KClass in order to match.

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

fun <T : Any> NavGraphBuilder.navigation(
    route: KClass<T>,
    startDestination: KClass<*>,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

Parameters
route: KClass<T>

the graph's unique route from KClass

startDestination: KClass<*>

the starting destination's route from a KClass for this NavGraph. The respective NavDestination must be added with route from a KClass in order to match.

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph

navigation

inline fun NavigatorProvider.navigation(
    startDestination: Any,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: Any

the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added with route from a KClass in order to match.

route: KClass<*>? = null

the graph's unique route as a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
NavGraph

the newly constructed NavGraph

navigation

inline fun NavigatorProvider.navigation(
    startDestination: KClass<*>,
    route: KClass<*>? = null,
    typeMap: Map<KTypeNavType<*>> = emptyMap(),
    builder: NavGraphBuilder.() -> Unit
): NavGraph

Construct a new NavGraph

Parameters
startDestination: KClass<*>

the starting destination's route from a KClass for this NavGraph. The respective NavDestination must be added with route from a KClass in order to match.

route: KClass<*>? = null

the graph's unique route as a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in the route. May be empty if route does not use custom NavTypes.

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
NavGraph

the newly constructed NavGraph

plusAssign

inline operator fun NavigatorProvider.plusAssign(navigator: Navigator<NavDestination>): Unit

Register a navigator using the name provided by the Navigator.Name.

plusAssign

inline operator fun NavGraph.plusAssign(node: NavDestination): Unit

Adds a destination to this NavGraph. The destination must have an NavDestination.id set.

The destination must not have a parent set. If the destination is already part of a NavGraph, call NavGraph.remove before calling this method.

Parameters
node: NavDestination

destination to add

plusAssign

inline operator fun NavGraph.plusAssign(other: NavGraph): Unit

Add all destinations from another collection to this one. As each destination has at most one parent, the destinations will be removed from the given NavGraph.

Parameters
other: NavGraph

collection of destinations to add. All destinations will be removed from the parameter graph after being added to this graph.

inline operator fun NavigatorProvider.set(
    name: String,
    navigator: Navigator<NavDestination>
): Navigator<NavDestination>?

Register a Navigator by name. If a navigator by this name is already registered, this new navigator will replace it.

Returns
Navigator<NavDestination>?

the previously added Navigator for the given name, if any

inline fun <T : Any?> NavBackStackEntry.toRoute(): T

Returns route as an object of type T

Extrapolates arguments from NavBackStackEntry.arguments and recreates object T

Parameters
<T : Any?>

the entry's NavDestination.route as a KClass

Returns
T

A new instance of this entry's NavDestination.route as an object of type T

fun <T : Any?> NavBackStackEntry.toRoute(route: KClass<*>): T

Returns route as an object of type T

Extrapolates arguments from NavBackStackEntry.arguments and recreates object T

Parameters
route: KClass<*>

the entry's NavDestination.route as a KClass

Returns
T

A new instance of this entry's NavDestination.route as an object of type T

inline fun <T : Any> SavedStateHandle.toRoute(
    typeMap: Map<KTypeNavType<*>> = emptyMap()
): T

Returns route as an object of type T

Extrapolates arguments from SavedStateHandle and recreates object T

Parameters
<T : Any>

the entry's NavDestination.route as a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in T. May be empty if T does not use custom NavTypes.

Returns
T

A new instance of this entry's NavDestination.route as an object of type T

fun <T : Any> SavedStateHandle.toRoute(
    route: KClass<T>,
    typeMap: Map<KTypeNavType<*>> = emptyMap()
): T

Returns route as an object of type T

Extrapolates arguments from SavedStateHandle and recreates object T

Parameters
route: KClass<T>

the entry's NavDestination.route as a KClass

typeMap: Map<KTypeNavType<*>> = emptyMap()

A mapping of KType to custom NavType<*> in T. May be empty if T does not use custom NavTypes.

Returns
T

A new instance of this entry's NavDestination.route as an object of type T