TestNavigatorState


class TestNavigatorState : NavigatorState


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 functions

open NavBackStackEntry
createBackStackEntry(destination: NavDestination, arguments: Bundle?)
open Unit
open Unit
pop(popUpTo: NavBackStackEntry, saveState: Boolean)
open Unit
open Unit
open Unit
push(backStackEntry: NavBackStackEntry)
NavBackStackEntry

Restore a previously saved NavBackStackEntry.

Public constructors

TestNavigatorState

Added in 2.4.0
TestNavigatorState(
    context: Context? = null,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main.immediate
)

Public functions

createBackStackEntry

Added in 2.4.0
open fun createBackStackEntry(destination: NavDestination, arguments: Bundle?): NavBackStackEntry

markTransitionComplete

open fun markTransitionComplete(entry: NavBackStackEntry): Unit

pop

open fun pop(popUpTo: NavBackStackEntry, saveState: Boolean): Unit

popWithTransition

open fun popWithTransition(popUpTo: NavBackStackEntry, saveState: Boolean): Unit

prepareForTransition

open fun prepareForTransition(entry: NavBackStackEntry): Unit

push

open fun push(backStackEntry: NavBackStackEntry): Unit

restoreBackStackEntry

Added in 2.4.0
fun restoreBackStackEntry(previouslySavedEntry: NavBackStackEntry): NavBackStackEntry

Restore a previously saved NavBackStackEntry. You must have previously called pop with previouslySavedEntry and true.