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).

NavArgs

An interface marking generated Args classes.

NavController.OnDestinationChangedListener

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

NavDirections

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

NavHost

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

Navigator.Extras

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

SupportingPane

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

Classes

ActionOnlyNavDirections

An implementation of NavDirections without any arguments.

ActivityNavigator

ActivityNavigator implements cross-activity navigation.

ActivityNavigator.Destination

NavDestination for activity navigation

ActivityNavigator.Extras

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

ActivityNavigator.Extras.Builder

Builder for constructing new Extras instances.

ActivityNavigatorDestinationBuilder

DSL for constructing a new ActivityNavigator.Destination

AnimBuilder

DSL for setting custom Animation or Animator resources on a NavOptionsBuilder

CollectionNavType

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

NamedNavArgument

Construct a named NavArgument by using the navArgument method.

NavAction

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

NavActionBuilder

DSL for building a NavAction.

NavArgsLazy

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

NavArgument

NavArgument denotes an argument that is supported by a NavDestination.

NavArgument.Builder

A builder for constructing NavArgument instances.

NavArgumentBuilder

DSL for constructing a new NavArgument

NavBackStackEntry

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

NavController

NavController manages app navigation within a NavHost.

NavDeepLink

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

NavDeepLink.Builder

A builder for constructing NavDeepLink instances.

NavDeepLinkBuilder

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

NavDeepLinkDslBuilder

DSL for constructing a new NavDeepLink

NavDeepLinkRequest

A request for a deep link in a NavDestination.

NavDeepLinkRequest.Builder

A builder for constructing NavDeepLinkRequest instances.

NavDestination

NavDestination represents one node within an overall navigation graph.

NavDestinationBuilder

DSL for constructing a new NavDestination

NavGraph

NavGraph is a collection of NavDestination nodes fetchable by ID.

NavGraphBuilder

DSL for constructing a new NavGraph

NavGraphNavigator

A Navigator built specifically for NavGraph elements.

NavHostController

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

NavInflater

Class which translates a navigation XML file into a NavGraph

NavOptions

NavOptions stores special options for navigate actions

NavOptions.Builder

Builder for constructing new instances of NavOptions.

NavOptionsBuilder

DSL for constructing a new NavOptions

NavType

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

NavType.EnumType

EnumType is used for NavArguments holding enum values.

NavType.ParcelableArrayType

ParcelableArrayType is used for NavArguments which hold arrays of Parcelables.

NavType.ParcelableType

ParcelableType is used for passing Parcelables in NavArguments.

NavType.SerializableArrayType

SerializableArrayType is used for NavArguments that hold arrays of Serializables.

NavType.SerializableType

SerializableType is used for Serializable NavArguments.

Navigator

Navigator defines a mechanism for navigating within an app.

NavigatorProvider

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

NavigatorState

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

PopUpToBuilder

DSL for customizing NavOptionsBuilder.popUpTo operations.

Objects

Navigation

Entry point for navigation operations.

Annotations

NavDeepLinkDsl
NavDeepLinkSaveStateControl
NavDestination.ClassType

This optional annotation allows tooling to offer auto-complete for the android:name attribute.

NavDestinationDsl
NavOptionsDsl
Navigator.Name

This annotation should be added to each Navigator subclass to denote the default name used to register the Navigator with a NavigatorProvider.

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.

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

Construct a new NavArgument

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

Construct a new NavDeepLink

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

Construct a new NavDeepLink

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

Construct a new NavDeepLink

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

Construct a new NavOptions

Extension functions summary

inline Unit

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

inline Unit

Construct a new ActivityNavigator.Destination

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

Construct a new ActivityNavigator.Destination

operator Boolean

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

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

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

operator Boolean

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

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

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

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

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

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

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

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

Construct a new NavGraph

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

Construct a new NavGraph

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

Construct a new NavGraph

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

Construct a new NavGraph

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

Construct a new NavGraph

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

Construct a new NavGraph

NavController

Find a NavController associated with a View.

NavController

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

inline operator T

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

inline operator NavDestination

Returns the destination with id.

inline operator T

Retrieves a registered Navigator by name.

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

Returns the destination with route from KClass.

inline operator NavDestination

Returns the destination with route.

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

Returns the destination with route from an Object.

inline operator Unit

Removes node from this navigation graph.

inline NavArgsLazy<Args>

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

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:

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:

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

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

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

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

Construct a nested NavGraph

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

Construct a nested NavGraph

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

Construct a new NavGraph

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

Construct a nested NavGraph

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

Construct a nested NavGraph

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

Construct a nested NavGraph

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

Construct a new NavGraph

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

Construct a new NavGraph

inline operator Unit

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

inline operator Unit

Adds a destination to this NavGraph.

inline operator Unit

Add all destinations from another collection to this one.

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

Register a Navigator by name.

inline T

Returns route as an object of type T

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

Returns route as an object of type T

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

Returns route as an object of type T

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

Returns route as an object of type T

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

inline fun NavGraphBuilder.activity(id: @IdRes Int, 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

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.

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

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

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

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

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

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

Construct a new NavGraph

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

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

Construct a new NavGraph

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

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

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

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

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

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

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.

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.

@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.

@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.

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

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

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

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

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

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

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

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

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

Adds a destination to this NavGraph. The destination must have an 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

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