NavDestinationBuilder


@NavDestinationDsl
public class NavDestinationBuilder<D extends NavDestination>

Known indirect subclasses

DSL for constructing a new NavDestination

Summary

Public constructors

<D extends NavDestination> NavDestinationBuilder(
    @NonNull Navigator<@NonNull D> navigator,
    @IdRes int id
)

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

<D extends NavDestination> NavDestinationBuilder(
    @NonNull Navigator<@NonNull D> navigator,
    String route
)

DSL for constructing a new NavDestination with a unique route.

<D extends NavDestination> NavDestinationBuilder(
    @NonNull Navigator<@NonNull D> navigator,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap
)

DSL for constructing a new NavDestination with a serializable KClass.

Public methods

final void
action(
    int actionId,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavActionBuilderUnit> actionBuilder
)

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

final void
argument(
    @NonNull String name,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavArgumentBuilderUnit> argumentBuilder
)

Add a NavArgument to this destination.

final void

Add a NavArgument to this destination.

@NonNull D

Build the NavDestination by calling Navigator.createDestination.

final void

Add a deep link to this destination.

final void

Add a deep link to this destination.

final void
deepLink(@NonNull String uriPattern)

Add a deep link to this destination.

final void
<T extends Object> deepLink(
    @NonNull String basePath,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink
)

Add a deep link to this destination.

final void
<T extends Object> deepLink(
    @NonNull KClass<@NonNull T> route,
    @NonNull String basePath,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink
)

Add a deep link to this destination.

final void
<T extends Object> deepLinkSafeArgs(@NonNull String basePath)

Add a deep link to this destination.

final int

The destination's unique ID.

final CharSequence

The descriptive label of the destination

final String

The destination's unique route.

final void

The descriptive label of the destination

Protected methods

final @NonNull Navigator<@NonNull D>

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

@NonNull D

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

Public constructors

public <D extends NavDestination> NavDestinationBuilder(
    @NonNull Navigator<@NonNull D> navigator,
    @IdRes int id
)

DSL for constructing a new NavDestination with a unique id.

This sets the destination's route to null.

Parameters
@NonNull Navigator<@NonNull D> navigator

navigator used to create the destination

@IdRes int id

the destination's unique id

Returns
NavDestinationBuilder<@NonNull D>

the newly constructed NavDestination

public <D extends NavDestination> NavDestinationBuilder(
    @NonNull Navigator<@NonNull D> navigator,
    String route
)

DSL for constructing a new NavDestination with a unique route.

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

Parameters
@NonNull Navigator<@NonNull D> navigator

navigator used to create the destination

String route

the destination's unique route

Returns
NavDestinationBuilder<@NonNull D>

the newly constructed NavDestination

public <D extends NavDestination> NavDestinationBuilder(
    @NonNull Navigator<@NonNull D> navigator,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap
)

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
@NonNull Navigator<@NonNull D> navigator

navigator used to create the destination

KClass<@NonNull ?> route

the KClass of the destination

@NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap

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

Returns
NavDestinationBuilder<@NonNull D>

the newly constructed NavDestination

Public methods

action

Added in 1.0.0
public final void action(
    int actionId,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavActionBuilderUnit> actionBuilder
)

Adds a new NavAction to the destination

argument

Added in 1.0.0
public final void argument(
    @NonNull String name,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavArgumentBuilderUnit> argumentBuilder
)

Add a NavArgument to this destination.

argument

public final void argument(@NonNull String name, @NonNull NavArgument argument)

Add a NavArgument to this destination.

build

Added in 1.0.0
public @NonNullbuild()

Build the NavDestination by calling Navigator.createDestination.

deepLink

Added in 2.3.0
public final void deepLink(
    @ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink
)

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
@ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink

the NavDeepLink to be added to this destination

deepLink

public final void deepLink(@NonNull NavDeepLink navDeepLink)

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
@NonNull NavDeepLink navDeepLink

the NavDeepLink to be added to this destination

deepLink

Added in 1.0.0
public final void deepLink(@NonNull String uriPattern)

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
@NonNull String uriPattern

The uri pattern to add as a deep link

See also
deepLink

deepLink

public final void <T extends Object> deepLink(
    @NonNull String basePath,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink
)

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 extends Object>

The deepLink KClass to extract arguments from

@NonNull String basePath

The base uri path to append arguments onto

@ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink

the NavDeepLink to be added to this destination

See also
setUriPattern

for the final uriPattern's generation logic.

deepLink

public final void <T extends Object> deepLink(
    @NonNull KClass<@NonNull T> route,
    @NonNull String basePath,
    @ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink
)

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
@NonNull KClass<@NonNull T> route

The deepLink KClass to extract arguments from

@NonNull String basePath

The base uri path to append arguments onto

@ExtensionFunctionType @NonNull Function1<@NonNull NavDeepLinkDslBuilderUnit> navDeepLink

the NavDeepLink to be added to this destination

See also
setUriPattern

for the final uriPattern's generation logic.

deepLinkSafeArgs

public final void <T extends Object> deepLinkSafeArgs(@NonNull String basePath)

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 extends Object>

The deepLink KClass to extract arguments from

@NonNull String basePath

The base uri path to append arguments onto

See also
setUriPattern

for the final uriPattern's generation logic.

getId

Added in 1.0.0
public final int getId()

The destination's unique ID.

getLabel

Added in 1.0.0
public final CharSequence getLabel()

The descriptive label of the destination

getRoute

public final String getRoute()

The destination's unique route.

setLabel

Added in 1.0.0
public final void setLabel(CharSequence label)

The descriptive label of the destination

Protected methods

getNavigator

Added in 1.0.0
protected final @NonNull Navigator<@NonNull D> getNavigator()

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

instantiateDestination

protected @NonNullinstantiateDestination()

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.