ViewModelStoreNavEntryDecorator


public final class ViewModelStoreNavEntryDecorator<T extends Object> extends NavEntryDecorator


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

This requires the usage of androidx.navigation3.runtime.SaveableStateHolderNavEntryDecorator to ensure that the NavEntry scoped ViewModels can properly provide access to androidx.lifecycle.SavedStateHandles

See also
onPop

for more details on when this callback is invoked

Summary

Public constructors

<T extends Object> ViewModelStoreNavEntryDecorator(
    @NonNull ViewModelStore viewModelStore,
    @NonNull Function0<@NonNull Boolean> removeViewModelStoreOnPop
)

Public constructors

ViewModelStoreNavEntryDecorator

public <T extends Object> ViewModelStoreNavEntryDecorator(
    @NonNull ViewModelStore viewModelStore,
    @NonNull Function0<@NonNull Boolean> removeViewModelStoreOnPop
)
Parameters
@NonNull ViewModelStore viewModelStore

The ViewModelStore that provides to NavEntries

@NonNull Function0<@NonNull Boolean> removeViewModelStoreOnPop

A lambda that returns a Boolean for whether the store for a NavEntry should be cleared when the NavEntry is popped from the backStack. If true, the entry's ViewModelStore will be removed.