Package 

Interface NavScopeSpec


  • 
    public interface NavScopeSpec<T extends Object, S extends Object>
    
                        

    Specifies scopes for every destination. This gives you the ability to easily create and access scoped ViewModelStore.

    To do so, you must return a set of desired scopes for each requested destination from getScopes. This information will then be used to associate different entries to specified scopes and keep each scoped ViewModelStoreOwner until any of its associated entries is present in the backstack. When none of the entries are present anymore, the scoped ViewModelStore and all of its ViewModels will be cleared.

    Scoped ViewModelStoreOwner is implemented by ScopedNavHostEntry class. You can acquire all scoped entries associated with the current destination through the ScopingNavHostScope receiver of the contentSelector parameter. To be specific, the map of all scoped entries is accessible through ScopingNavHostScope.scopedHostEntries property. Keys in this map are the same scope objects you've returned from getScopes.

    You may pass then any ScopedNavHostEntry into viewModel method as the viewModelStoreOwner parameter and create shared ViewModels, accessible from different destinations.

    Alternatively, you can access scoped ViewModelStoreOwners through the LocalScopedViewModelStoreOwners composition local.

    • Method Summary

      Modifier and Type Method Description
      abstract Set<S> getScopes(T destination) Returns the set of scopes associated with this destination.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getScopes

         abstract Set<S> getScopes(T destination)

        Returns the set of scopes associated with this destination. Each returned object in the set must be immutable and writable to Parcel - it could be Parcelable, Serializable, string/primitive, or other supported type.