Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

androidx.navigation.compose

Classes

ComposeNavigator

Navigator that navigates through Composables.

NamedNavArgument

Construct a named NavArgument by using the navArgument method.

Top-level constants summary

const String

The route linked to the current destination.

Top-level functions summary

Unit
NavHost(navController: NavHostController, startDestination: String, route: String? = null, builder: NavGraphBuilder.() -> Unit)

Provides in place in the Compose hierarchy for self contained navigation to occur.

Unit
NavHost(navController: NavHostController, graph: NavGraph)

Provides in place in the Compose hierarchy for self contained navigation to occur.

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

Construct a new NavArgument

NavHostController

Creates a NavHostController that handles the adding of the ComposeNavigator.

Extension functions summary

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

Add the Composable to the NavGraphBuilder

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

Construct a nested NavGraph

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

Construct a new NavGraph

State<NavBackStackEntry?>

Gets the current navigation back stack entry as a MutableState.

Unit
NavController.navigate(route: String, builder: NavOptionsBuilder.() -> Unit = {})

Navigate to a route in the current NavGraph.

For NavOptionsBuilder
Unit
NavOptionsBuilder.popUpTo(route: String, popUpToBuilder: PopUpToBuilder.() -> Unit)

Pop up to a given destination before navigating.

Top-level constants

KEY_ROUTE

const val KEY_ROUTE: String

The route linked to the current destination.

Value: "android-support-nav:controller:route"

Top-level functions

@Composable fun NavHost(
    navController: NavHostController,
    startDestination: String,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
): Unit

Provides in place in the Compose hierarchy for self contained navigation to occur.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The builder passed into this method is remembered. This means that for this NavHost, the contents of the builder cannot be changed.

import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController

val navController = rememberNavController()
NavHost(navController, startDestination = Screen.Profile.route) {
    composable(Screen.Profile.route) { Profile(navController) }
    composable(Screen.Dashboard.route) { Dashboard(navController) }
    composable(Screen.Scrollable.route) { Scrollable(navController) }
}
Parameters
navController: NavHostController the navController for this host
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
@Composable fun NavHost(
    navController: NavHostController,
    graph: NavGraph
): Unit

Provides in place in the Compose hierarchy for self contained navigation to occur.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The graph passed into this method is remembered. This means that for this NavHost, the graph cannot be changed.

Parameters
navController: NavHostController the navController for this host
graph: NavGraph the graph for this host
fun navArgument(
    name: String,
    builder: NavArgumentBuilder.() -> Unit
): NamedNavArgument

Construct a new NavArgument

rememberNavController

@Composable fun rememberNavController(): NavHostController

Creates a NavHostController that handles the adding of the ComposeNavigator.

See Also

Extension functions

composable

fun NavGraphBuilder.composable(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    content: (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
content: (NavBackStackEntry) -> Unit composable for the destination

createGraph

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

Construct a new NavGraph

Parameters
route: String? = null the route for the graph
startDestination: String the route for the start destination
builder: NavGraphBuilder.() -> Unit the builder used to construct the graph

currentBackStackEntryAsState

@Composable fun NavController.currentBackStackEntryAsState(): State<NavBackStackEntry?>

Gets the current navigation back stack entry as a MutableState. When the given navController changes the back stack due to a NavController.navigate or NavController.popBackStack this will trigger a recompose and return the top entry on the back stack.

Return
a mutable state of the current back stack entry
fun NavController.navigate(
    route: String,
    builder: NavOptionsBuilder.() -> Unit = {}
): Unit

Navigate to a route in the current NavGraph.

Parameters
route: String route for the destination
builder: NavOptionsBuilder.() -> Unit = {} DSL for constructing a new NavOptions
fun NavGraphBuilder.navigation(
    startDestination: String,
    route: String,
    builder: NavGraphBuilder.() -> Unit
): Unit

Construct a nested NavGraph


//Unresolved: androidx.navigation.compose.samples.NestedNav

popUpTo

fun NavOptionsBuilder.popUpTo(
    route: String,
    popUpToBuilder: PopUpToBuilder.() -> Unit
): Unit

Pop up to a given destination before navigating. This pops all non-matching destination routes from the back stack until the destination with a matching route is found.

Parameters
route: String route for the destination
popUpToBuilder: PopUpToBuilder.() -> Unit builder used to construct a popUpTo operation