Class ViewTreeViewModelStoreOwner

java.lang.Object
icyllis.modernui.lifecycle.ViewTreeViewModelStoreOwner

public class ViewTreeViewModelStoreOwner extends Object
Accessors for finding a view tree-local ViewModelStoreOwner that allows access to a ViewModelStore for the given view.
  • Method Details

    • set

      public static void set(@Nonnull View view, @Nullable ViewModelStoreOwner viewModelStoreOwner)
      Set the ViewModelStoreOwner associated with the given View. Calls to get(View) from this view or descendants will return viewModelStoreOwner.

      This should only be called by constructs such as activities or fragments that manage a view tree and retain state through a ViewModelStoreOwner. Callers should only set a ViewModelStoreOwner that will be stable. The associated ViewModelStore should be cleared if the view tree is removed and is not guaranteed to later become reattached to a window.

      Parameters:
      view - Root view associated with the viewModelStoreOwner
      viewModelStoreOwner - ViewModelStoreOwner associated with the given view
    • get

      @Nullable public static ViewModelStoreOwner get(@Nonnull View view)
      Retrieve the ViewModelStoreOwner associated with the given View. This may be used to retain state associated with this view across configuration changes.
      Parameters:
      view - View to fetch a ViewModelStoreOwner for
      Returns:
      The ViewModelStoreOwner associated with this view and/or some subset of its ancestors