rememberNavigationController

fun rememberNavigationController(startDestinations: List<Destination>, onScreenChange: (debugInfo: String) -> Unit = {}, resultTtl: Duration = DEFAULT_RESULT_TTL): NavigationController

Creates a controller with its own ResultStore.

Parameters

startDestinations

The full list of start destinations. For each unique Destination.Args.backstackIndex you must provide a start Destination.

resultTtl

Time-to-live for stored results: unconsumed results are discarded after this duration. Example:

val controller = rememberNavigationController(
startDestinations = listOf(HomeDestination()),
)

fun rememberNavigationController(startDestinations: List<Destination>, onScreenChange: (debugInfo: String) -> Unit = {}, resultSource: ResultSource): NavigationController

Creates a controller backed by the provided resultSource. Pass the same source to application wrappers when they need to observe results independently of the controller.

Parameters

startDestinations

The full list of start destinations. For each unique Destination.Args.backstackIndex you must provide a start Destination.

resultSource

The source shared with the controller. Keep the instance stable and alive for at least as long as the wrappers observing it. Example:

// DI or ViewModel scope
val resultSource = ResultSource.create()
val wrapper = ResultsWrapper(resultSource)

// Composition
val controller = rememberNavigationController(
startDestinations = listOf(HomeDestination()),
resultSource = resultSource,
)