Package icyllis.modernui.lifecycle

# Class ViewTreeLifecycleOwner

java.lang.Object
icyllis.modernui.lifecycle.ViewTreeLifecycleOwner

public class ViewTreeLifecycleOwner extends Object
Accessors for finding a view tree-local `LifecycleOwner` that reports the lifecycle for the given view.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static LifecycleOwner`
  `get(View view)`
  Retrieve the `LifecycleOwner` responsible for managing the given `View`.
  `static void`
  `set(View view, LifecycleOwner lifecycleOwner)`
  Set the `LifecycleOwner` responsible for managing the given `View`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### set

    public static void set(@Nonnull View view, @Nullable LifecycleOwner lifecycleOwner)
    Set the `LifecycleOwner` responsible for managing the given `View`. Calls to `get(View)` from this view or descendants will return `lifecycleOwner`.

    This should only be called by constructs such as activities or fragments that manage a view tree and reflect their own lifecycle through a `LifecycleOwner`. Callers should only set a `LifecycleOwner` that will be stable. The associated lifecycle should report that it is destroyed if the view tree is removed and is not guaranteed to later become reattached to a window.

    Parameters:
      `view` - Root view managed by lifecycleOwner
      `lifecycleOwner` - LifecycleOwner representing the manager of the given view

  - ### get

    @Nullable public static LifecycleOwner get(@Nonnull View view)
    Retrieve the `LifecycleOwner` responsible for managing the given `View`. This may be used to scope work or heavyweight resources associated with the view that may span cycles of the view becoming detached and reattached from a window.
    Parameters:
      `view` - View to fetch a `LifecycleOwner` for
    Returns:
      The `LifecycleOwner` responsible for managing this view and/or some subset of its ancestors