Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.71 KB

lifecycle.md

File metadata and controls

49 lines (36 loc) · 1.71 KB

Lifecycle

Translations: 简体中文

Sketch relies on Lifecycle to monitor the life cycle of the page for the following functions:

  1. When the animation is loaded, it will automatically play if the page has reached the Start state.
  2. Start or stop playing animations when the page reaches Start or Stop state
  3. Stop the request when the page is destroyed function.

Default Value

If Lifecycle is not set when creating the request, Sketch will be obtained in the following order:

  • compose:
    1. Obtained through LocalLifecycleOwner.current.lifecycle API
    2. Use GlobalLifecycle
  • view:
    1. Obtained through view.findViewTreeLifecycleOwner() API
    2. Obtained through view.context (if context implements the LifecycleOwner interface, such as Activity)
    3. Obtained through ImageRequest.Builder.context (if context implements the LifecycleOwner interface, e.g. Activity)
    4. Use GlobalLifecycle

Configuration

If the above Sketch cannot obtain Lifecycle by default or the Lifecycle obtained by default does not meet your needs, ImageRequest.Builder also provides the lifecycle() method for setting lifecycle, as follows:

val lifecycle: Lifecycle = ...
ImageRequest(context, "https://www.example.com/image.gif") {
    lifecycle(lifecycle)
}