NavigatorState

public abstract class NavigatorState

Known direct subclasses
TestNavigatorState

An implementation of NavigatorState that allows testing a androidx.navigation.Navigator in isolation (i.e., without requiring a androidx.navigation.NavController).


The NavigatorState encapsulates the state shared between the Navigator and the NavController.

Summary

Nested types

NavigatorState.OnTransitionCompleteListener

OnTransitionCompleteListener receives a callback when a destination transition is complete.

Public fields

final @NonNull StateFlow<@NonNull List<@NonNull NavBackStackEntry>>

While the NavController is responsible for the combined back stack across all Navigators, this back stack is specifically the set of destinations associated with this Navigator.

final @NonNull StateFlow<@NonNull Map<@NonNull NavBackStackEntry, @NonNull NavigatorState.OnTransitionCompleteListener>>

This is the map of currently running transitions to their individual OnTransitionCompleteListeners.

Public constructors

Public methods

abstract @NonNull NavBackStackEntry
createBackStackEntry(
    @NonNull NavDestination destination,
    @Nullable Bundle arguments
)

Create a new NavBackStackEntry from a given destination and arguments.

void
pop(@NonNull NavBackStackEntry popUpTo, boolean saveState)

Pop all destinations up to and including popUpTo.

@NonNull NavigatorState.OnTransitionCompleteListener
popWithTransition(@NonNull NavBackStackEntry popUpTo, boolean saveState)

Provides listener that once activated, Pops all destinations up to and including popUpTo.

void
push(@NonNull NavBackStackEntry backStackEntry)

Adds the given backStackEntry to the backStack.

@NonNull NavigatorState.OnTransitionCompleteListener

Provides listener that once activated, adds the given backStackEntry to the backStack.

Public fields

backStack

@NonNull
public final @NonNull StateFlow<@NonNull List<@NonNull NavBackStackEntry>> backStack

While the NavController is responsible for the combined back stack across all Navigators, this back stack is specifically the set of destinations associated with this Navigator.

Changing the back stack must be done via push and pop.

transitionsInProgress

@NonNull
public final @NonNull StateFlow<@NonNull Map<@NonNull NavBackStackEntry, @NonNull NavigatorState.OnTransitionCompleteListener>> transitionsInProgress

This is the map of currently running transitions to their individual OnTransitionCompleteListeners. Use this map to retrieve the listener and execute the callback once the transition is complete.

Public constructors

public final NavigatorState()

Public methods

createBackStackEntry

@NonNull
public abstract NavBackStackEntry createBackStackEntry(
    @NonNull NavDestination destination,
    @Nullable Bundle arguments
)

Create a new NavBackStackEntry from a given destination and arguments.

pop

@NonNull
public void pop(@NonNull NavBackStackEntry popUpTo, boolean saveState)

Pop all destinations up to and including popUpTo. This will remove those destinations from the backStack, saving their state if saveState is true.

popWithTransition

@NonNull
public NavigatorState.OnTransitionCompleteListener popWithTransition(@NonNull NavBackStackEntry popUpTo, boolean saveState)

Provides listener that once activated, Pops all destinations up to and including popUpTo.

This will remove those destinations from the backStack, saving their state if saveState is true.

push

@NonNull
public void push(@NonNull NavBackStackEntry backStackEntry)

Adds the given backStackEntry to the backStack.

pushWithTransition

@NonNull
public NavigatorState.OnTransitionCompleteListener pushWithTransition(@NonNull NavBackStackEntry backStackEntry)

Provides listener that once activated, adds the given backStackEntry to the backStack.