NavigatorProvider


open class NavigatorProvider


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

Summary

Public constructors

Public functions

Navigator<NavDestination>?

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

open Navigator<NavDestination>?

Register a navigator by name.

open T

Retrieves a registered Navigator by name.

T
<T : Navigator<*>> getNavigator(navigatorClass: Class<T>)

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

Extension functions

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

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

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

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 NavGraph
NavigatorProvider.navigation(
    startDestination: String,
    route: String?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a new 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 T

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

inline operator T

Retrieves a registered Navigator by name.

inline operator Unit

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

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

Register a Navigator by name.

Public constructors

Added in 1.0.0
NavigatorProvider()

Public functions

addNavigator

Added in 1.0.0
fun addNavigator(navigator: Navigator<NavDestination>): Navigator<NavDestination>?

Register a navigator using the name provided by the Navigator.Name annotation. destinations may refer to any registered navigator by name for inflation. If a navigator by this name is already registered, this new navigator will replace it.

Parameters
navigator: Navigator<NavDestination>

navigator to add

Returns
Navigator<NavDestination>?

the previously added Navigator for the name provided by the Navigator.Name annotation, if any

addNavigator

Added in 1.0.0
@CallSuper
open fun addNavigator(name: String, navigator: Navigator<NavDestination>): Navigator<NavDestination>?

Register a navigator by name. destinations may refer to any registered navigator by name for inflation. If a navigator by this name is already registered, this new navigator will replace it.

Parameters
name: String

name for this navigator

navigator: Navigator<NavDestination>

navigator to add

Returns
Navigator<NavDestination>?

the previously added Navigator for the given name, if any

getNavigator

Added in 1.0.0
@CallSuper
open fun <T : Navigator<*>> getNavigator(name: String): T

Retrieves a registered Navigator by name.

Parameters
name: String

name of the navigator to return

Returns
T

the registered navigator with the given name

Throws
kotlin.IllegalStateException

if the Navigator has not been added

See also
addNavigator

getNavigator

Added in 1.0.0
fun <T : Navigator<*>> getNavigator(navigatorClass: Class<T>): T

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

Parameters
navigatorClass: Class<T>

class of the navigator to return

Returns
T

the registered navigator with the given Navigator.Name

Throws
kotlin.IllegalArgumentException

if the Navigator does not have a Navigator.Name annotation

kotlin.IllegalStateException

if the Navigator has not been added

See also
addNavigator

Extension functions

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

Parameters
id: @IdRes Int = 0

NavGraph id.

startDestination: @IdRes Int

Id start destination in the graph

builder: DynamicNavGraphBuilder.() -> Unit

Another builder for chaining.

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

Parameters
startDestination: String

route start destination in the graph

route: String? = null

NavGraph route.

builder: DynamicNavGraphBuilder.() -> Unit

Another builder for chaining.

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

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: DynamicNavGraphBuilder.() -> Unit

Another builder for chaining.

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

Construct a new DynamicGraphNavigator.DynamicNavGraph

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: DynamicNavGraphBuilder.() -> Unit

Another builder for chaining.

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 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 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 <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 <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 NavigatorProvider.plusAssign(navigator: Navigator<NavDestination>): Unit

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

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