NavEntryDecoratorKt

Added in 1.0.0-alpha04

public final class NavEntryDecoratorKt


Summary

Public methods

static final void
@Composable
<T extends Object> DecorateNavEntry(
    @NonNull NavEntry<@NonNull T> entry,
    @NonNull List<@NonNull NavEntryDecorator<@NonNull ?>> entryDecorators
)

Wraps a NavEntry with the list of NavEntryDecorator in the order that the decorators were added to the list and invokes the content of the wrapped entry.

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

Public methods

@Composable
public static final void <T extends Object> DecorateNavEntry(
    @NonNull NavEntry<@NonNull T> entry,
    @NonNull List<@NonNull NavEntryDecorator<@NonNull ?>> entryDecorators
)

Wraps a NavEntry with the list of NavEntryDecorator in the order that the decorators were added to the list and invokes the content of the wrapped entry.

Parameters
<T extends Object>

the type of the backStack key

@NonNull NavEntry<@NonNull T> entry

the NavEntry to wrap

@NonNull List<@NonNull NavEntryDecorator<@NonNull ?>> entryDecorators

the list of decorators to wrap the entry with

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

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