TestNavigatorState

public final class TestNavigatorState extends NavigatorState

Object
   ↳ NavigatorState
     ↳ TestNavigatorState

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

An optional context can be provided to allow for the usages of androidx.lifecycle.AndroidViewModel within the created NavBackStackEntry instances.

The Lifecycle of all NavBackStackEntry instances added to this TestNavigatorState will be updated as they are added and removed from the state. This work is kicked off on the coroutineDispatcher.

Summary

Public constructors

TestNavigatorState(
    Context context,
    CoroutineDispatcher coroutineDispatcher
)

Public methods

@NonNull NavBackStackEntry
createBackStackEntry(NavDestination destination, Bundle arguments)

Create a new NavBackStackEntry from a given destination and arguments.

void

This removes the given NavBackStackEntry from the set of the transitions in progress.

void
pop(NavBackStackEntry popUpTo, boolean saveState)

Pop all destinations up to and including popUpTo.

void
popWithTransition(NavBackStackEntry popUpTo, boolean saveState)

Pops all destinations up to and including popUpTo.

void
push(NavBackStackEntry backStackEntry)

Adds the given backStackEntry to the backStack.

final @NonNull NavBackStackEntry

Restore a previously saved NavBackStackEntry.

Inherited methods

From class NavigatorState
@CallSuper void