NavGraph
-
Cmn
open class NavGraph : NavDestination, Iterable
DynamicGraphNavigator.DynamicNavGraph |
The |
NavGraph is a collection of NavDestination nodes fetchable by ID.
A NavGraph serves as a 'virtual' destination: while the NavGraph itself will not appear on the back stack, navigating to the NavGraph will cause the starting destination to be added to the back stack.
Construct a new NavGraph. This NavGraph is not valid until you add a destination and set the starting destination.
Summary
Public companion functions |
||
|---|---|---|
NavDestination |
Finds the actual start destination of the graph, handling cases where the graph's starting destination is itself a NavGraph. |
Cmn
android
|
Public functions |
||
|---|---|---|
Unit |
Add all destinations from another collection to this one. |
Cmn
android
|
Unit |
addDestination(node: NavDestination)Adds a destination to this NavGraph. |
Cmn
android
|
Unit |
addDestinations(nodes: Collection<NavDestination?>)Adds multiple destinations to this NavGraph. |
Cmn
android
|
Unit |
addDestinations(vararg nodes: NavDestination)Adds multiple destinations to this NavGraph. |
Cmn
android
|
Unit |
clear()Clear all destinations from this navigation graph. |
Cmn
android
|
open operator Boolean |
android
|
|
open operator Boolean |
android
|
|
inline NavDestination? |
Finds a destination in the collection by route from |
Cmn
android
|
NavDestination? |
Finds a destination in the collection by ID. |
android
|
NavDestination? |
Finds a destination in the collection by route from |
Cmn
android
|
NavDestination? |
Finds a destination in the collection by route from Object. |
Cmn
android
|
NavDestination? |
Finds a destination in the collection by route. |
Cmn
android
|
NavDestination? |
findNodeComprehensive(Searches all children and parents recursively. |
Cmn
|
@IdRes Int |
This function is deprecated. Use getStartDestinationId instead. |
android
|
open Int |
hashCode() |
android
|
open Int |
hashCode() |
android
|
final operator MutableIterator<NavDestination> |
iterator() |
Cmn
android
|
open Unit |
onInflate(context: Context, attrs: AttributeSet)Called when inflating a destination from a resource. |
android
|
Unit |
remove(node: NavDestination)Remove a given destination from this NavGraph |
Cmn
android
|
inline Unit |
<T : Any> setStartDestination()Sets the starting destination for this NavGraph. |
Cmn
android
|
Unit |
setStartDestination(startDestId: Int)Sets the starting destination for this NavGraph. |
android
|
Unit |
<T : Any> setStartDestination(startDestRoute: KClass<T>)Sets the starting destination for this NavGraph. |
Cmn
android
|
Unit |
<T : Any> setStartDestination(startDestRoute: T)Sets the starting destination for this NavGraph. |
Cmn
android
|
Unit |
setStartDestination(startDestRoute: String)Sets the starting destination for this NavGraph. |
Cmn
android
|
open String |
toString() |
android
|
open String |
toString() |
android
|
Public properties |
||
|---|---|---|
open String |
Cmn
|
|
String |
Cmn
|
|
Int |
The starting destination id for this NavGraph. |
Cmn
android
|
String? |
The route for the starting destination for this NavGraph. |
Cmn
android
|
Extension functions |
||
|---|---|---|
operator Boolean |
Returns |
android
|
inline operator Boolean |
Returns |
Cmn
|
operator Boolean |
Returns |
Cmn
|
operator Boolean |
Returns |
Cmn
|
inline operator NavDestination |
Returns the destination with |
android
|
inline operator NavDestination |
Returns the destination with |
Cmn
|
inline operator NavDestination |
Returns the destination with |
Cmn
|
inline operator NavDestination |
Returns the destination with |
Cmn
|
inline operator Unit |
NavGraph.minusAssign(node: NavDestination)Removes |
Cmn
|
inline operator Unit |
NavGraph.plusAssign(node: NavDestination)Adds a destination to this NavGraph. |
Cmn
|
inline operator Unit |
NavGraph.plusAssign(other: NavGraph)Add all destinations from another collection to this one. |
Cmn
|
Inherited functions |
||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||
|
Inherited properties |
||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public companion functions
NavGraph.findStartDestination
fun NavGraph.findStartDestination(): NavDestination
Finds the actual start destination of the graph, handling cases where the graph's starting destination is itself a NavGraph.
| Returns | |
|---|---|
NavDestination |
the actual startDestination of the given graph. |
Public constructors
NavGraph
NavGraph(navGraphNavigator: Navigator<NavGraph>)
| Parameters | |
|---|---|
navGraphNavigator: Navigator<NavGraph> |
The |
Public functions
addAll
fun addAll(other: NavGraph): Unit
Add all destinations from another collection to this one. As each destination has at most one parent, the destinations will be removed from the given NavGraph.
| Parameters | |
|---|---|
other: NavGraph |
collection of destinations to add. All destinations will be removed from this graph after being added to this graph. |
addDestination
fun addDestination(node: NavDestination): Unit
Adds a destination to this NavGraph. The destination must have an NavDestination.id id} set.
The destination must not have a parent set. If the destination is already part of a navigation graph, call remove before calling this method.
| Parameters | |
|---|---|
node: NavDestination |
destination to add |
| Throws | |
|---|---|
IllegalArgumentException |
if destination does not have an id, the destination has the same id as the graph, or the destination already has a parent. |
addDestinations
fun addDestinations(nodes: Collection<NavDestination?>): Unit
Adds multiple destinations to this NavGraph. Each destination must have an NavDestination.id id} set.
Each destination must not have a parent set. If any destination is already part of a navigation graph, call remove before calling this method.
| Parameters | |
|---|---|
nodes: Collection<NavDestination?> |
destinations to add |
addDestinations
fun addDestinations(vararg nodes: NavDestination): Unit
Adds multiple destinations to this NavGraph. Each destination must have an NavDestination.id id} set.
Each destination must not have a parent set. If any destination is already part of a navigation graph, call remove before calling this method.
| Parameters | |
|---|---|
vararg nodes: NavDestination |
destinations to add |
findNode
inline fun <T : Any?> findNode(): NavDestination?
Finds a destination in the collection by route from KClass. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.
| Returns | |
|---|---|
NavDestination? |
the node with route - the node must have been created with a route from |
findNode
fun findNode(resId: @IdRes Int): NavDestination?
Finds a destination in the collection by ID. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.
| Returns | |
|---|---|
NavDestination? |
the node with ID resId |
findNode
fun findNode(route: KClass<*>): NavDestination?
Finds a destination in the collection by route from KClass. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.
| Returns | |
|---|---|
NavDestination? |
the node with route - the node must have been created with a route from |
findNode
fun <T : Any?> findNode(route: T?): NavDestination?
Finds a destination in the collection by route from Object. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.
| Parameters | |
|---|---|
route: T? |
Route to locate |
| Returns | |
|---|---|
NavDestination? |
the node with route - the node must have been created with a route from |
findNode
fun findNode(route: String?): NavDestination?
Finds a destination in the collection by route. This will recursively check the parent of this navigation graph if node is not found in this navigation graph.
| Parameters | |
|---|---|
route: String? |
Route to locate |
| Returns | |
|---|---|
NavDestination? |
the node with route |
findNodeComprehensive
fun findNodeComprehensive(
resId: Int,
lastVisited: NavDestination?,
searchChildren: Boolean,
matchingDest: NavDestination? = null
): NavDestination?
Searches all children and parents recursively.
Does not revisit graphs (whether it's a child or parent) if it has already been visited.
| Parameters | |
|---|---|
resId: Int |
|
lastVisited: NavDestination? |
the previously visited node |
searchChildren: Boolean |
searches the graph's children for the node when true |
matchingDest: NavDestination? = null |
an optional NavDestination that the node should match with. This is because |
getStartDestination
fungetStartDestination(): @IdRes Int
Gets the starting destination for this NavGraph. When navigating to the NavGraph, this destination is the one the user will initially see.
iterator
final operator fun iterator(): MutableIterator<NavDestination>
| Throws | |
|---|---|
NoSuchElementException |
if there no more elements |
onInflate
open fun onInflate(context: Context, attrs: AttributeSet): Unit
Called when inflating a destination from a resource.
| Parameters | |
|---|---|
context: Context |
local context performing inflation |
attrs: AttributeSet |
attrs to parse during inflation |
remove
fun remove(node: NavDestination): Unit
Remove a given destination from this NavGraph
| Parameters | |
|---|---|
node: NavDestination |
the destination to remove. |
setStartDestination
inline fun <T : Any> setStartDestination(): Unit
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId
setStartDestination
fun setStartDestination(startDestId: Int): Unit
Sets the starting destination for this NavGraph.
This will clear any previously set startDestinationRoute.
| Parameters | |
|---|---|
startDestId: Int |
The id of the destination to be shown when navigating to this NavGraph. |
setStartDestination
fun <T : Any> setStartDestination(startDestRoute: KClass<T>): Unit
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId
setStartDestination
fun <T : Any> setStartDestination(startDestRoute: T): Unit
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId
| Parameters | |
|---|---|
startDestRoute: T |
The route of the destination as an object to be shown when navigating to this NavGraph. |
setStartDestination
fun setStartDestination(startDestRoute: String): Unit
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId
| Parameters | |
|---|---|
startDestRoute: String |
The route of the destination to be shown when navigating to this NavGraph. |
Public properties
startDestinationId
val startDestinationId: Int
The starting destination id for this NavGraph. When navigating to the NavGraph, the destination represented by this id is the one the user will initially see.
startDestinationRoute
val startDestinationRoute: String?
The route for the starting destination for this NavGraph. When navigating to the NavGraph, the destination represented by this route is the one the user will initially see.
Extension functions
NavGraph.contains
operator fun NavGraph.contains(id: @IdRes Int): Boolean
Returns true if a destination with id is found in this navigation graph.
NavGraph.contains
inline operator fun <T : Any> NavGraph.contains(route: KClass<T>): Boolean
Returns true if a destination with route is found in this navigation graph.
NavGraph.contains
operator fun NavGraph.contains(route: String): Boolean
Returns true if a destination with route is found in this navigation graph.
NavGraph.contains
operator fun <T : Any> NavGraph.contains(route: T): Boolean
Returns true if a destination with route is found in this navigation graph.
NavGraph.get
inline operator fun NavGraph.get(id: @IdRes Int): NavDestination
Returns the destination with id.
| Throws | |
|---|---|
IllegalArgumentException |
if no destination is found with that id. |
NavGraph.get
inline operator fun <T : Any> NavGraph.get(route: KClass<T>): NavDestination
Returns the destination with route from KClass.
| Throws | |
|---|---|
IllegalArgumentException |
if no destination is found with that route. |
NavGraph.get
inline operator fun NavGraph.get(route: String): NavDestination
Returns the destination with route.
| Throws | |
|---|---|
IllegalArgumentException |
if no destination is found with that route. |
NavGraph.get
inline operator fun <T : Any> NavGraph.get(route: T): NavDestination
Returns the destination with route from an Object.
| Throws | |
|---|---|
IllegalArgumentException |
if no destination is found with that route. |
NavGraph.minusAssign
inline operator fun NavGraph.minusAssign(node: NavDestination): Unit
Removes node from this navigation graph.
NavGraph.plusAssign
inline operator fun NavGraph.plusAssign(node: NavDestination): Unit
Adds a destination to this NavGraph. The destination must have an id set.
The destination must not have a parent set. If the destination is already part of a NavGraph, call NavGraph.remove before calling this method.
| Parameters | |
|---|---|
node: NavDestination |
destination to add |
NavGraph.plusAssign
inline operator fun NavGraph.plusAssign(other: NavGraph): Unit
Add all destinations from another collection to this one. As each destination has at most one parent, the destinations will be removed from the given NavGraph.
| Parameters | |
|---|---|
other: NavGraph |
collection of destinations to add. All destinations will be removed from the parameter graph after being added to this graph. |