Known direct subclasses
SaveableStateHolderNavEntryDecorator

Wraps the content of a NavEntry with a SaveableStateHolder.SaveableStateProvider to ensure that calls to rememberSaveable within the content work properly and that state can be saved.

ViewModelStoreNavEntryDecorator

Provides the content of a NavEntry with a ViewModelStoreOwner and provides that ViewModelStoreOwner as a LocalViewModelStoreOwner so that it is available within the content.


Decorate the NavEntrys that are integrated with a rememberDecoratedNavEntries.

HOW TO USE Primary usages include but are not limited to:

  1. provide information to entries with androidx.compose.runtime.CompositionLocal, i.e.

val decorator = NavEntryDecorator<Any> { entry ->
...
CompositionLocalProvider(LocalMyStateProvider provides myState) {
entry.content.invoke(entry.key)
}
}
  1. Wrap entry content with other composable content

val decorator = NavEntryDecorator<Any> { entry ->
...
MyComposableFunction {
entry.content.invoke(entry.key)
}
}

REUSABILITY To enhance reusability, the NavEntryDecorator can be returned by a function or subclassed:

// a reusable function
fun <T : Any> myDecorator(val myState: MyState): NavEntryDecorator<T> =
NavEntryDecorator(onPop = { contentKey -> myState.clear(contentKey) }) { entry ->
myState.storeState(entry.contentKey)
entry.Content()
}

// or subclass NavEntryDecorator
class MyDecorator(
val myState: MyState
): NavEntryDecorator(
onPop = { contentKey -> myState.clear(contentKey) },
decorate = { entry ->
myState.storeState(entry.contentKey)
entry.Content()
}
)
Parameters
<T : Any>

the type of the backStack key

See also
contentKey

Summary

Public constructors

<T : Any> NavEntryDecorator(
    onPop: (key: Any) -> Unit,
    decorate: @Composable (entry: NavEntry<T>) -> Unit
)
Cmn

Public constructors

<T : Any> NavEntryDecorator(
    onPop: (key: Any) -> Unit = {},
    decorate: @Composable (entry: NavEntry<T>) -> Unit
)
Parameters
<T : Any>

the type of the backStack key

onPop: (key: Any) -> Unit = {}

the callback to clean up the decorator state associated with a NavEntry.contentKey when the last NavEntry with that contentKey has been popped from the backStack. It provides the NavEntry.contentKey of the popped entry as input. This callback is invoked if and only if all these conditions are met: 1. A NavEntry has been popped from the backStack 2. The NavEntry that has been popped is the last entry on the backStack with that particular NavEntry.contentKey 3. The NavEntry.content of the popped NavEntry has left composition

decorate: @Composable (entry: NavEntry<T>) -> Unit

the composable function to decorate a NavEntry. Note that this function only gets invoked for NavEntries that are actually getting rendered (i.e. by invoking the NavEntry.content.)