Translations: 简体中文
Sketch relies on Lifecycle to monitor the life cycle of the page for the following functions:
- When the animation is loaded, it will automatically play if the page has reached the Start state.
- Start or stop playing animations when the page reaches Start or Stop state
- Stop the request when the page is destroyed function.
If Lifecycle is not set when creating the request, Sketch will be obtained in the following order:
- compose:
- Obtained through LocalLifecycleOwner.current.lifecycle API
- Use GlobalLifecycle
- view:
- Obtained through view.findViewTreeLifecycleOwner() API
- Obtained through view.context (if context implements the LifecycleOwner interface, such as Activity)
- Obtained through ImageRequest.Builder.context (if context implements the LifecycleOwner interface, e.g. Activity)
- Use GlobalLifecycle
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)
}