NavDestinationBuilder



DSL for constructing a new NavDestination

Summary

Public constructors

<D : NavDestination> NavDestinationBuilder(
    navigator: Navigator<D>,
    id: @IdRes Int
)

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

android
<D : NavDestination> NavDestinationBuilder(
    navigator: Navigator<D>,
    route: String?
)

DSL for constructing a new NavDestination with a unique route.

android
<D : NavDestination> NavDestinationBuilder(
    navigator: Navigator<D>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>
)

DSL for constructing a new NavDestination with a serializable KClass.

android

Public functions

Unit
action(actionId: Int, actionBuilder: NavActionBuilder.() -> Unit)

This function is deprecated. Building NavDestinations using IDs with the Kotlin DSL has been deprecated in favor of using routes.

android
Unit
argument(name: String, argumentBuilder: NavArgumentBuilder.() -> Unit)

Add a NavArgument to this destination.

android
Unit
argument(name: String, argument: NavArgument)

Add a NavArgument to this destination.

android
open D

Build the NavDestination by calling Navigator.createDestination.

android
inline Unit
<T : Any> deepLink(basePath: String)

Add a deep link to this destination.

android
Unit
deepLink(navDeepLink: NavDeepLinkDslBuilder.() -> Unit)

Add a deep link to this destination.

android
Unit
deepLink(navDeepLink: NavDeepLink)

Add a deep link to this destination.

android
Unit
deepLink(uriPattern: String)

Add a deep link to this destination.

android
inline Unit
<T : Any> deepLink(basePath: String, noinline navDeepLink: NavDeepLinkDslBuilder.() -> Unit)

Add a deep link to this destination.

android
Unit
<T : Any> deepLink(route: KClass<T>, basePath: String, navDeepLink: NavDeepLinkDslBuilder.() -> Unit)

Add a deep link to this destination.

android

Protected functions

open D

Instantiate a new instance of D that will be passed to build.

android

Public properties

Int

The destination's unique ID.

android
CharSequence?

The descriptive label of the destination

android
String?

The destination's unique route.

android

Protected properties

Navigator<D>

The navigator the destination that will be used in instantiateDestination to create the destination.

android

Public constructors

<D : NavDestination> NavDestinationBuilder(
    navigator: Navigator<D>,
    id: @IdRes Int
)

DSL for constructing a new NavDestination with a unique id.

This sets the destination's route to null.

Parameters
navigator: Navigator<D>

navigator used to create the destination

id: @IdRes Int

the destination's unique id

Returns
NavDestinationBuilder<D>

the newly constructed NavDestination

<D : NavDestination> NavDestinationBuilder(
    navigator: Navigator<D>,
    route: String?
)

DSL for constructing a new NavDestination with a unique route.

This will also update the id of the destination based on route.

Parameters
navigator: Navigator<D>

navigator used to create the destination

route: String?

the destination's unique route

Returns
NavDestinationBuilder<D>

the newly constructed NavDestination

<D : NavDestination> NavDestinationBuilder(
    navigator: Navigator<D>,
    route: KClass<*>?,
    typeMap: Map<KTypeNavType<*>>
)

DSL for constructing a new NavDestination with a serializable KClass.

This will also update the id of the destination based on KClass's serializer.

Parameters
navigator: Navigator<D>

navigator used to create the destination

route: KClass<*>?

the KClass of the destination

typeMap: Map<KTypeNavType<*>>

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

Returns
NavDestinationBuilder<D>

the newly constructed NavDestination

Public functions

action

fun action(actionId: Int, actionBuilder: NavActionBuilder.() -> Unit): Unit

Adds a new NavAction to the destination

argument

fun argument(name: String, argumentBuilder: NavArgumentBuilder.() -> Unit): Unit

Add a NavArgument to this destination.

argument

fun argument(name: String, argument: NavArgument): Unit

Add a NavArgument to this destination.

build

open fun build(): D

Build the NavDestination by calling Navigator.createDestination.

deepLink

inline fun <T : Any> deepLink(basePath: String): Unit

Add a deep link to this destination.

The arguments in T are expected to be identical (in name and type) to the arguments in the route from KClass that was used to construct this NavDestinationBuilder.

Extracts deeplink arguments from T and appends it to the basePath. See docs on the safe args version of NavDeepLink.Builder.setUriPattern for the final uriPattern's generation logic.

In addition to a direct Uri match, basePaths without a scheme are assumed as http and https. For example, www.example.com will match http://www.example.com and https://www.example.com.

Parameters
<T : Any>

The deepLink KClass to extract arguments from

basePath: String

The base uri path to append arguments onto

See also
setUriPattern

for the final uriPattern's generation logic.

deepLink

fun deepLink(navDeepLink: NavDeepLinkDslBuilder.() -> Unit): Unit

Add a deep link to this destination.

In addition to a direct Uri match, the following features are supported:

  • Uris without a scheme are assumed as http and https. For example, www.example.com will match http://www.example.com and https://www.example.com.

  • Placeholders in the form of {placeholder_name} matches 1 or more characters. The String value of the placeholder will be available in the arguments Bundle with a key of the same name. For example, http://www.example.com/users/{id} will match http://www.example.com/users/4.

  • The .* wildcard can be used to match 0 or more characters.

Parameters
navDeepLink: NavDeepLinkDslBuilder.() -> Unit

the NavDeepLink to be added to this destination

deepLink

fun deepLink(navDeepLink: NavDeepLink): Unit

Add a deep link to this destination.

In addition to a direct Uri match, the following features are supported:

  • Uris without a scheme are assumed as http and https. For example, www.example.com will match http://www.example.com and https://www.example.com.

  • Placeholders in the form of {placeholder_name} matches 1 or more characters. The String value of the placeholder will be available in the arguments Bundle with a key of the same name. For example, http://www.example.com/users/{id} will match http://www.example.com/users/4.

  • The .* wildcard can be used to match 0 or more characters.

Parameters
navDeepLink: NavDeepLink

the NavDeepLink to be added to this destination

deepLink

fun deepLink(uriPattern: String): Unit

Add a deep link to this destination.

In addition to a direct Uri match, the following features are supported:

  • Uris without a scheme are assumed as http and https. For example, www.example.com will match http://www.example.com and https://www.example.com.

  • Placeholders in the form of {placeholder_name} matches 1 or more characters. The String value of the placeholder will be available in the arguments Bundle with a key of the same name. For example, http://www.example.com/users/{id} will match http://www.example.com/users/4.

  • The .* wildcard can be used to match 0 or more characters.

Parameters
uriPattern: String

The uri pattern to add as a deep link

See also
deepLink

deepLink

inline fun <T : Any> deepLink(basePath: String, noinline navDeepLink: NavDeepLinkDslBuilder.() -> Unit): Unit

Add a deep link to this destination.

The arguments in T are expected to be identical (in name and type) to the arguments in the route from KClass that was used to construct this NavDestinationBuilder.

Extracts deeplink arguments from T and appends it to the basePath. See docs on the safe args version of NavDeepLink.Builder.setUriPattern for the final uriPattern's generation logic.

In addition to a direct Uri match, basePaths without a scheme are assumed as http and https. For example, www.example.com will match http://www.example.com and https://www.example.com.

Parameters
<T : Any>

The deepLink KClass to extract arguments from

basePath: String

The base uri path to append arguments onto

noinline navDeepLink: NavDeepLinkDslBuilder.() -> Unit

the NavDeepLink to be added to this destination

See also
setUriPattern

for the final uriPattern's generation logic.

deepLink

fun <T : Any> deepLink(route: KClass<T>, basePath: String, navDeepLink: NavDeepLinkDslBuilder.() -> Unit): Unit

Add a deep link to this destination.

The arguments in route are expected to be identical (in name and type) to the arguments in the NavDestinationBuilder.route that was used to construct this NavDestinationBuilder.

Extracts deeplink arguments from route and appends it to the basePath. See docs on the safe args version of NavDeepLink.Builder.setUriPattern for the final uriPattern's generation logic.

In addition to a direct Uri match, basePaths without a scheme are assumed as http and https. For example, www.example.com will match http://www.example.com and https://www.example.com.

Parameters
route: KClass<T>

The deepLink KClass to extract arguments from

basePath: String

The base uri path to append arguments onto

navDeepLink: NavDeepLinkDslBuilder.() -> Unit

the NavDeepLink to be added to this destination

See also
setUriPattern

for the final uriPattern's generation logic.

Protected functions

instantiateDestination

protected open fun instantiateDestination(): D

Instantiate a new instance of D that will be passed to build.

By default, this calls Navigator.createDestination on navigator, but can be overridden to call a custom constructor, etc.

Public properties

id

val idInt

The destination's unique ID.

label

var labelCharSequence?

The descriptive label of the destination

route

val routeString?

The destination's unique route.

Protected properties

protected val navigatorNavigator<D>

The navigator the destination that will be used in instantiateDestination to create the destination.