Class NavController
The NavController manages navigation within a NavHost. It is responsible for keeping track of the navigation stack and the current destination.
Inherited Members
Namespace: Unity.AppUI.Navigation
Assembly: Unity.AppUI.Navigation.dll
Syntax
public class NavController
Constructors
NavController(NavHost)
Default constructor.
Declaration
public NavController(NavHost navHost)
Parameters
Type | Name | Description |
---|---|---|
NavHost | navHost | The NavHost that this NavController is associated with. |
Properties
canGoBack
Returns true if there is a destination on the back stack that can be popped.
Declaration
public bool canGoBack { get; }
Property Value
Type | Description |
---|---|
bool |
currentBackStackEntry
The last entry on the back stack.
Declaration
public NavBackStackEntry currentBackStackEntry { get; }
Property Value
Type | Description |
---|---|
NavBackStackEntry |
currentDestination
The current destination.
Declaration
public NavDestination currentDestination { get; set; }
Property Value
Type | Description |
---|---|
NavDestination |
graph
The current graph.
Declaration
public NavGraph graph { get; }
Property Value
Type | Description |
---|---|
NavGraph |
Remarks
Can be null if there's no current destination.
graphAsset
The used graph asset.
Declaration
public NavGraphViewAsset graphAsset { get; }
Property Value
Type | Description |
---|---|
NavGraphViewAsset |
Methods
ClearBackStack()
Clear the back stack entirely.
Declaration
public void ClearBackStack()
Remarks
This will not clear the saved states, and the current destination will not be changed.
Navigate(string, params Argument[])
Navigate to the destination with the given name.
Declaration
public bool Navigate(string actionOrDestination, params Argument[] arguments)
Parameters
Type | Name | Description |
---|---|---|
string | actionOrDestination | The name of the destination or action. |
Argument[] | arguments | The arguments to pass to the destination. |
Returns
Type | Description |
---|---|
bool | True if the navigation was successful. |
Navigate(string, NavOptions, params Argument[])
Navigate to the destination with the given name.
Declaration
public bool Navigate(string route, NavOptions options, params Argument[] arguments)
Parameters
Type | Name | Description |
---|---|---|
string | route | The route to the destination. |
NavOptions | options | The options to use for the navigation. |
Argument[] | arguments | The arguments to pass to the destination. |
Returns
Type | Description |
---|---|
bool | True if the navigation was successful. |
Navigate(Uri, NavOptions)
Navigate to the destination with the given DeepLink.
Declaration
public bool Navigate(Uri deepLink, NavOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
Uri | deepLink | The DeepLink to navigate to. |
NavOptions | options | The options to use for the navigation. |
Returns
Type | Description |
---|---|
bool | True if the navigation was successful. |
PopBackStack()
Pop the current destination from the back stack and navigate to the previous destination.
Declaration
public bool PopBackStack()
Returns
Type | Description |
---|---|
bool | True if the back stack was popped, false otherwise. |
PopBackStack(string, bool, bool)
Pop the current destination from the back stack and navigate to the given destination.
Declaration
public bool PopBackStack(string route, bool inclusive = false, bool saveState = false)
Parameters
Type | Name | Description |
---|---|---|
string | route | The route of the destination to navigate to. |
bool | inclusive | Whether to pop the destination with the given route or not. |
bool | saveState | Whether to save the state of the popped destinations or not before popping them. |
Returns
Type | Description |
---|---|
bool | True if the back stack was popped, false otherwise. |
SetGraph(NavGraphViewAsset)
Set the Navigation Graph asset that will be used as navigation definition.
Declaration
public void SetGraph(NavGraphViewAsset navGraphViewAsset)
Parameters
Type | Name | Description |
---|---|---|
NavGraphViewAsset | navGraphViewAsset | The Navigation Graph asset. |
Events
actionTriggered
Event that is invoked when an action is triggered.
Declaration
public static event Action<NavController, NavAction> actionTriggered
Event Type
Type | Description |
---|---|
Action<NavController, NavAction> |
destinationChanged
Event that is invoked when the current destination changes.
Declaration
public static event Action<NavController, NavDestination> destinationChanged
Event Type
Type | Description |
---|---|
Action<NavController, NavDestination> |