NavGraphBuilder

@NavDestinationDsl
open class NavGraphBuilder : NavDestinationBuilder

Known direct subclasses

DSL for constructing a new NavGraph

Summary

Public constructors

NavGraphBuilder(
    provider: NavigatorProvider,
    id: @IdRes Int,
    startDestination: @IdRes Int
)

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

NavGraphBuilder(
    provider: NavigatorProvider,
    startDestination: String,
    route: String?
)

DSL for constructing a new NavGraph

Public functions

Unit

Add the destination to the NavGraphBuilder

open NavGraph

Build the NavDestination by calling Navigator.createDestination.

Unit
<D : NavDestination> destination(navDestination: NavDestinationBuilder<D>)

Build and add a new destination to the NavGraphBuilder

operator Unit

Adds this destination to the NavGraphBuilder

Extension functions

inline Unit

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

inline Unit

Construct a new ActivityNavigator.Destination

inline Unit

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

inline Unit

Construct a new DialogFragmentNavigator.Destination

inline Unit

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

inline Unit

Construct a new DialogFragmentNavigator.Destination

inline Unit

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

inline Unit

Construct a new FragmentNavigator.Destination

inline Unit

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

inline Unit

Construct a new FragmentNavigator.Destination

Unit
NavGraphBuilder.composable(
    route: String,
    arguments: List<NamedNavArgument>,
    deepLinks: List<NavDeepLink>,
    content: @Composable (NavBackStackEntry) -> Unit
)

Utility function for building Wear Compose navigation graphs.

Unit
NavGraphBuilder.composable(
    route: String,
    arguments: List<NamedNavArgument>,
    deepLinks: List<NavDeepLink>,
    enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)?,
    exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)?,
    popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)?,
    popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)?,
    sizeTransform: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform)?,
    content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit
)

Add the Composable to the NavGraphBuilder

Unit
NavGraphBuilder.dialog(
    route: String,
    arguments: List<NamedNavArgument>,
    deepLinks: List<NavDeepLink>,
    dialogProperties: DialogProperties,
    content: @Composable (NavBackStackEntry) -> Unit
)

Add the Composable to the NavGraphBuilder that will be hosted within a androidx.compose.ui.window.Dialog.

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

Construct a nested NavGraph

Unit
NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    arguments: List<NamedNavArgument>,
    deepLinks: List<NavDeepLink>,
    enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)?,
    exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)?,
    popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)?,
    popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)?,
    sizeTransform: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform)?,
    builder: NavGraphBuilder.() -> Unit
)

Construct a nested NavGraph

Inherited functions

From androidx.navigation.NavDestinationBuilder
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.

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

Add a NavArgument to this destination.

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

Add a deep link to this destination.

Unit
deepLink(uriPattern: String)

Add a deep link to this destination.

Inherited properties

From androidx.navigation.NavDestinationBuilder
Int

The destination's unique ID.

CharSequence?

The descriptive label of the destination

Navigator<NavGraph>

The navigator the destination was created from

String?

The destination's unique route.

Public constructors

Added in 1.0.0
NavGraphBuilder(
    provider: NavigatorProvider,
    id: @IdRes Int,
    startDestination: @IdRes Int
)

DSL for constructing a new NavGraph

Parameters
provider: NavigatorProvider

navigator used to create the destination

id: @IdRes Int

the graph's unique id

startDestination: @IdRes Int

the starting destination for this NavGraph

Returns
NavGraphBuilder

the newly created NavGraph

NavGraphBuilder(
    provider: NavigatorProvider,
    startDestination: String,
    route: String?
)

DSL for constructing a new NavGraph

Parameters
provider: NavigatorProvider

navigator used to create the destination

startDestination: String

the starting destination's route for this NavGraph

route: String?

the graph's unique route

Returns
NavGraphBuilder

the newly created NavGraph

Public functions

addDestination

Added in 1.0.0
fun addDestination(destination: NavDestination): Unit

Add the destination to the NavGraphBuilder

build

open fun build(): NavGraph

Build the NavDestination by calling Navigator.createDestination.

destination

fun <D : NavDestination> destination(navDestination: NavDestinationBuilder<D>): Unit

Build and add a new destination to the NavGraphBuilder

operator fun NavDestination.unaryPlus(): Unit

Adds this destination to the NavGraphBuilder

Public properties

Extension functions

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

Construct a new ActivityNavigator.Destination

inline fun <F : DialogFragment> NavGraphBuilder.dialog(id: @IdRes Int): Unit

Construct a new DialogFragmentNavigator.Destination

Parameters
id: @IdRes Int

the destination's unique id

inline fun <F : DialogFragment> NavGraphBuilder.dialog(route: String): Unit

Construct a new DialogFragmentNavigator.Destination

Parameters
route: String

the destination's unique route

inline fun <F : DialogFragment> NavGraphBuilder.dialog(
    id: @IdRes Int,
    builder: DialogFragmentNavigatorDestinationBuilder.() -> Unit
): Unit

Construct a new DialogFragmentNavigator.Destination

Parameters
id: @IdRes Int

the destination's unique id

builder: DialogFragmentNavigatorDestinationBuilder.() -> Unit

the builder used to construct the fragment destination

inline fun <F : DialogFragment> NavGraphBuilder.dialog(
    route: String,
    builder: DialogFragmentNavigatorDestinationBuilder.() -> Unit
): Unit

Construct a new DialogFragmentNavigator.Destination

Parameters
route: String

the destination's unique route

builder: DialogFragmentNavigatorDestinationBuilder.() -> Unit

the builder used to construct the fragment destination

inline fun <F : Fragment> NavGraphBuilder.fragment(id: @IdRes Int): Unit

Construct a new FragmentNavigator.Destination

Parameters
id: @IdRes Int

the destination's unique id

inline fun <F : Fragment> NavGraphBuilder.fragment(route: String): Unit

Construct a new FragmentNavigator.Destination

Parameters
route: String

the destination's unique route

inline fun <F : Fragment> NavGraphBuilder.fragment(id: @IdRes Int, builder: FragmentNavigatorDestinationBuilder.() -> Unit): Unit

Construct a new FragmentNavigator.Destination

Parameters
id: @IdRes Int

the destination's unique id

builder: FragmentNavigatorDestinationBuilder.() -> Unit

the builder used to construct the fragment destination

inline fun <F : Fragment> NavGraphBuilder.fragment(route: String, builder: FragmentNavigatorDestinationBuilder.() -> Unit): Unit

Construct a new FragmentNavigator.Destination

Parameters
route: String

the destination's unique route

builder: FragmentNavigatorDestinationBuilder.() -> Unit

the builder used to construct the fragment destination

fun NavGraphBuilder.composable(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    content: @Composable (NavBackStackEntry) -> Unit
): Unit

Utility function for building Wear Compose navigation graphs.

Adds the content composable to the NavGraphBuilder as a WearNavigator.Destination.

Parameters
route: String

route for the destination

arguments: List<NamedNavArgument> = emptyList()

list of arguments to associate with destination

deepLinks: List<NavDeepLink> = emptyList()

list of deep links to associate with the destinations

content: @Composable (NavBackStackEntry) -> Unit

composable for the destination

fun NavGraphBuilder.composable(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = null,
    exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = null,
    popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = enterTransition,
    popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = exitTransition,
    sizeTransform: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform)? = null,
    content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit
): Unit

Add the Composable to the NavGraphBuilder

Parameters
route: String

route for the destination

arguments: List<NamedNavArgument> = emptyList()

list of arguments to associate with destination

deepLinks: List<NavDeepLink> = emptyList()

list of deep links to associate with the destinations

enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = null

callback to determine the destination's enter transition

exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = null

callback to determine the destination's exit transition

popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = enterTransition

callback to determine the destination's popEnter transition

popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = exitTransition

callback to determine the destination's popExit transition

sizeTransform: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform)? = null

callback to determine the destination's sizeTransform.

content: @Composable AnimatedContentScope.(NavBackStackEntry) -> Unit

composable for the destination

fun NavGraphBuilder.dialog(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    dialogProperties: DialogProperties = DialogProperties(),
    content: @Composable (NavBackStackEntry) -> Unit
): Unit

Add the Composable to the NavGraphBuilder that will be hosted within a androidx.compose.ui.window.Dialog. This is suitable only when this dialog represents a separate screen in your app that needs its own lifecycle and saved state, independent of any other destination in your navigation graph. For use cases such as AlertDialog, you should use those APIs directly in the composable destination that wants to show that dialog.

Parameters
route: String

route for the destination

arguments: List<NamedNavArgument> = emptyList()

list of arguments to associate with destination

deepLinks: List<NavDeepLink> = emptyList()

list of deep links to associate with the destinations

dialogProperties: DialogProperties = DialogProperties()

properties that should be passed to androidx.compose.ui.window.Dialog.

content: @Composable (NavBackStackEntry) -> Unit

composable content for the destination that will be hosted within the Dialog

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 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 NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = null,
    exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = null,
    popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = enterTransition,
    popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = exitTransition,
    sizeTransform: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform)? = null,
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph

import androidx.compose.animation.SizeTransform
import androidx.compose.animation.core.keyframes
import androidx.compose.foundation.layout.Box
import androidx.compose.ui.unit.IntSize
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

val navController = rememberNavController()
Box {
    NavHost(navController, startDestination = "collapsed") {
        composable("collapsed",
            enterTransition = { EnterTransition.None },
            exitTransition = { ExitTransition.None },
            sizeTransform = {
                SizeTransform { initialSize, targetSize ->
                    keyframes {
                        durationMillis = 500
                        IntSize(initialSize.width,
                            (initialSize.height + targetSize.height) / 2) at 150
                    }
                }
            }) {
            CollapsedScreen { navController.navigate("expanded") }
        }
        composable("expanded",
            enterTransition = { EnterTransition.None },
            exitTransition = { ExitTransition.None },
            sizeTransform = {
                SizeTransform { initialSize, targetSize ->
                    keyframes {
                        durationMillis = 500
                        IntSize(targetSize.width, initialSize.height + 400) at 150
                    }
                }
            }) {
            ExpandedScreen { navController.popBackStack() }
        }
    }
}
Parameters
startDestination: String

the starting destination's route for this NavGraph

route: String

the destination's unique route

arguments: List<NamedNavArgument> = emptyList()

list of arguments to associate with destination

deepLinks: List<NavDeepLink> = emptyList()

list of deep links to associate with the destinations

enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = null

callback to define enter transitions for destination in this NavGraph

exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = null

callback to define exit transitions for destination in this NavGraph

popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition)? = enterTransition

callback to define pop enter transitions for destination in this NavGraph

popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition)? = exitTransition

callback to define pop exit transitions for destination in this NavGraph

sizeTransform: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> SizeTransform)? = null

callback to define the size transform for destinations in this NavGraph

builder: NavGraphBuilder.() -> Unit

the builder used to construct the graph

Returns
Unit

the newly constructed nested NavGraph