NavEntryDecoratorKt

Added in 1.0.0-alpha10

public final class NavEntryDecoratorKt


Summary

Public methods

static final @NonNull NavEntryDecorator<@NonNull T>
<T extends Object> navEntryDecorator(
    @NonNull Function1<@NonNull ObjectUnit> onPop,
    @Composable @NonNull Function1<@NonNull NavEntry<@NonNull T>, Unit> decorator
)

Function to decorate the NavEntry that are integrated with a rememberDecoratedNavEntries.

Public methods

public static final @NonNull NavEntryDecorator<@NonNull T> <T extends Object> navEntryDecorator(
    @NonNull Function1<@NonNull ObjectUnit> onPop,
    @Composable @NonNull Function1<@NonNull NavEntry<@NonNull T>, Unit> decorator
)

Function to decorate the NavEntry that are integrated with a rememberDecoratedNavEntries.

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)
}
}
Parameters
<T extends Object>

the type of the backStack key

@NonNull Function1<@NonNull ObjectUnit> onPop

the callback to clean up the decorator state for a NavEntry when the entry is popped from the backstack and is leaving composition.The lambda provides the NavEntry.contentKey of the popped entry as input.

@Composable @NonNull Function1<@NonNull NavEntry<@NonNull T>, Unit> decorator

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.)