NavGraph
public class NavGraph extends NavDestination implements 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 getStartDestination 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 methods |
|
|---|---|
final void |
Add all destinations from another collection to this one. |
final void |
addDestination(@NonNull NavDestination node)Adds a destination to this NavGraph. |
final void |
addDestinations(@NonNull Collection<NavDestination> nodes)Adds multiple destinations to this NavGraph. |
final void |
addDestinations(@NonNull NavDestination... nodes)Adds multiple destinations to this NavGraph. |
final void |
clear()Clear all destinations from this navigation graph. |
boolean |
|
final NavDestination |
Finds a destination in the collection by route from |
final NavDestination |
Finds a destination in the collection by ID. |
final NavDestination |
Finds a destination in the collection by route from |
final NavDestination |
Finds a destination in the collection by route from Object. |
final NavDestination |
Finds a destination in the collection by route. |
final NavDestination |
findNodeComprehensive(Searches all children and parents recursively. |
static final @NonNull NavDestination |
findStartDestination(@NonNull NavGraph receiver)Finds the actual start destination of the graph, handling cases where the graph's starting destination is itself a NavGraph. |
@NonNull String |
|
final @NonNull String |
|
final @IdRes int |
This method is deprecated. Use getStartDestinationId instead. |
final @IdRes int |
The starting destination id for this NavGraph. |
final String |
The route for the starting destination for this NavGraph. |
int |
hashCode() |
final @NonNull Iterator<@NonNull NavDestination> |
iterator() |
void |
onInflate(@NonNull Context context, @NonNull AttributeSet attrs)Called when inflating a destination from a resource. |
final void |
remove(@NonNull NavDestination node)Remove a given destination from this NavGraph |
final void |
<T extends Object> setStartDestination()Sets the starting destination for this NavGraph. |
final void |
setStartDestination(int startDestId)Sets the starting destination for this NavGraph. |
final void |
setStartDestination(@NonNull String startDestRoute)Sets the starting destination for this NavGraph. |
@NonNull String |
toString() |
Extension functions |
|
|---|---|
final boolean |
NavGraphKt.contains(@NonNull NavGraph receiver, @IdRes int id)Returns |
final boolean |
<T extends Object> NavGraphKt.contains(Returns |
final boolean |
Returns |
final boolean |
Returns |
final @NonNull NavDestination |
NavGraphKt.get(@NonNull NavGraph receiver, @IdRes int id)Returns the destination with |
final @NonNull NavDestination |
Returns the destination with |
final @NonNull NavDestination |
Returns the destination with |
final @NonNull NavDestination |
Returns the destination with |
final void |
NavGraphKt.minusAssign(Removes |
final void |
NavGraphKt.plusAssign(Adds a destination to this NavGraph. |
final void |
NavGraphKt.plusAssign(@NonNull NavGraph receiver, @NonNull NavGraph other)Add all destinations from another collection to this one. |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
NavGraph
public NavGraph(@NonNull Navigator<@NonNull NavGraph> navGraphNavigator)
| Parameters | |
|---|---|
@NonNull Navigator<@NonNull NavGraph> navGraphNavigator |
The |
Public methods
addAll
public final void addAll(@NonNull NavGraph other)
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.
addDestination
public final void addDestination(@NonNull NavDestination node)
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 | |
|---|---|
@NonNull NavDestination node |
destination to add |
| Throws | |
|---|---|
kotlin.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
public final void addDestinations(@NonNull Collection<NavDestination> nodes)
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 | |
|---|---|
@NonNull Collection<NavDestination> nodes |
destinations to add |
addDestinations
public final void addDestinations(@NonNull NavDestination... nodes)
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 | |
|---|---|
@NonNull NavDestination... nodes |
destinations to add |
findNode
public final NavDestination <T extends Object> findNode()
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
public final NavDestination findNode(@IdRes int resId)
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.
| Parameters | |
|---|---|
@IdRes int resId |
ID to locate |
| Returns | |
|---|---|
NavDestination |
the node with ID resId |
findNode
public final NavDestination findNode(@NonNull KClass<@NonNull ?> route)
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
public final NavDestination <T extends Object> findNode(T route)
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 | |
|---|---|
T route |
Route to locate |
| Returns | |
|---|---|
NavDestination |
the node with route - the node must have been created with a route from |
findNode
public final NavDestination findNode(String route)
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 | |
|---|---|
String route |
Route to locate |
| Returns | |
|---|---|
NavDestination |
the node with route |
findNodeComprehensive
public final NavDestination findNodeComprehensive(
int resId,
NavDestination lastVisited,
boolean searchChildren,
NavDestination matchingDest
)
Searches all children and parents recursively.
Does not revisit graphs (whether it's a child or parent) if it has already been visited.
| Parameters | |
|---|---|
int resId |
|
NavDestination lastVisited |
the previously visited node |
boolean searchChildren |
searches the graph's children for the node when true |
NavDestination matchingDest |
an optional NavDestination that the node should match with. This is because |
findStartDestination
public static final @NonNull NavDestination findStartDestination(@NonNull NavGraph receiver)
Finds the actual start destination of the graph, handling cases where the graph's starting destination is itself a NavGraph.
| Returns | |
|---|---|
@NonNull NavDestination |
the actual startDestination of the given graph. |
public final @IdRes intgetStartDestination()
Gets the starting destination for this NavGraph. When navigating to the NavGraph, this destination is the one the user will initially see.
| Returns | |
|---|---|
@IdRes int |
the start destination |
getStartDestinationId
public final @IdRes int getStartDestinationId()
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.
getStartDestinationRoute
public final String getStartDestinationRoute()
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.
iterator
public final @NonNull Iterator<@NonNull NavDestination> iterator()
| Throws | |
|---|---|
kotlin.NoSuchElementException |
if there no more elements |
onInflate
public void onInflate(@NonNull Context context, @NonNull AttributeSet attrs)
Called when inflating a destination from a resource.
| Parameters | |
|---|---|
@NonNull Context context |
local context performing inflation |
@NonNull AttributeSet attrs |
attrs to parse during inflation |
remove
public final void remove(@NonNull NavDestination node)
Remove a given destination from this NavGraph
| Parameters | |
|---|---|
@NonNull NavDestination node |
the destination to remove. |
setStartDestination
public final void <T extends Object> setStartDestination()
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId
setStartDestination
public final void setStartDestination(int startDestId)
Sets the starting destination for this NavGraph.
This will clear any previously set startDestinationRoute.
| Parameters | |
|---|---|
int startDestId |
The id of the destination to be shown when navigating to this NavGraph. |
setStartDestination
public final void setStartDestination(@NonNull String startDestRoute)
Sets the starting destination for this NavGraph.
This will override any previously set startDestinationId
Extension functions
NavGraphKt.contains
public final boolean NavGraphKt.contains(@NonNull NavGraph receiver, @IdRes int id)
Returns true if a destination with id is found in this navigation graph.
NavGraphKt.contains
public final boolean <T extends Object> NavGraphKt.contains(
@NonNull NavGraph receiver,
@NonNull KClass<@NonNull T> route
)
Returns true if a destination with route is found in this navigation graph.
NavGraphKt.contains
public final boolean NavGraphKt.contains(@NonNull NavGraph receiver, @NonNull String route)
Returns true if a destination with route is found in this navigation graph.
NavGraphKt.contains
public final boolean <T extends Object> NavGraphKt.contains(@NonNull NavGraph receiver, @NonNull T route)
Returns true if a destination with route is found in this navigation graph.
NavGraphKt.get
public final @NonNull NavDestination NavGraphKt.get(@NonNull NavGraph receiver, @IdRes int id)
Returns the destination with id.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if no destination is found with that id. |
NavGraphKt.get
public final @NonNull NavDestination <T extends Object> NavGraphKt.get(
@NonNull NavGraph receiver,
@NonNull KClass<@NonNull T> route
)
Returns the destination with route from KClass.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if no destination is found with that route. |
NavGraphKt.get
public final @NonNull NavDestination NavGraphKt.get(@NonNull NavGraph receiver, @NonNull String route)
Returns the destination with route.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if no destination is found with that route. |
NavGraphKt.get
public final @NonNull NavDestination <T extends Object> NavGraphKt.get(@NonNull NavGraph receiver, @NonNull T route)
Returns the destination with route from an Object.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if no destination is found with that route. |
NavGraphKt.minusAssign
public final void NavGraphKt.minusAssign(
@NonNull NavGraph receiver,
@NonNull NavDestination node
)
Removes node from this navigation graph.
NavGraphKt.plusAssign
public final void NavGraphKt.plusAssign(
@NonNull NavGraph receiver,
@NonNull NavDestination node
)
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 | |
|---|---|
@NonNull NavDestination node |
destination to add |
NavGraphKt.plusAssign
public final void NavGraphKt.plusAssign(@NonNull NavGraph receiver, @NonNull NavGraph other)
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.