SimpleNavigationViewModel

open class SimpleNavigationViewModel @Inject constructor(navigator: Navigator, savedStateHandle: SavedStateHandle) : ViewModel, Navigator

A ViewModel that provides methods to get the parameter of the current destination.

This is a helper view model. You may inject the Navigator directly into your view model instead.

To get an instance of this view model use:

val vm: SimpleNavigationViewModel = hiltViewModel()

Constructors

Link copied to clipboard
@Inject
constructor(navigator: Navigator, savedStateHandle: SavedStateHandle)

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
open override fun currentDestination(): StateFlow<DestinationId<*, *>?>

Current destination as flow.

Link copied to clipboard
Link copied to clipboard
open override fun isInHierarchy(destination: DestinationId<*, *>): StateFlow<Boolean>

Checks whether the given destination is in the back stack.

Link copied to clipboard
open override fun navigateTo(to: DestinationId<Unit, *>, navOptions: NavOptions?)
open override fun navigateTo(to: DestinationId<Unit, *>, builder: NavOptionsBuilder.() -> Unit)

Requests navigation to the given destination which takes no input parameter.

open override fun <A> navigateTo(to: DestinationId<A, *>, args: A, navOptions: NavOptions?)
open override fun <A> navigateTo(to: DestinationId<A, *>, args: A, builder: NavOptionsBuilder.() -> Unit)

Requests navigation to the given destination. An required parameter must be passed.

Link copied to clipboard
open override fun navigateUp()

Navigates up to previous destination, or finishes the Activity.

Link copied to clipboard
open override fun <R> navigateUpWithResult(from: DestinationId<*, R>, result: R)

Navigates up to previous destination passing the given result, or finishes the Activity.

Link copied to clipboard
fun <A> nullableParameterOf(destinationId: DestinationId<A?, *>): A?

Returns the parameter of the current destination, or null, if hasn't been set.

Link copied to clipboard
open override fun open(link: Uri)

Opens the given link in a browser.

Link copied to clipboard
fun <A> parameterOf(destinationId: DestinationId<A & Any, *>): A
fun parameterOf(destinationId: DestinationId<Unit, *>): Nothing

Returns the parameter of the current destination, or null, if hasn't been set.

Link copied to clipboard
open override fun <R> resultFrom(from: DestinationId<*, R>): Flow<NavigationResult<R>>

Creates a flow that will emit the results of the navigation from the given destination.