Skip to content

Latest commit

 

History

History
88 lines (67 loc) · 2.27 KB

image_options.md

File metadata and controls

88 lines (67 loc) · 2.27 KB

ImageOptions

Translations: 简体中文

ImageOptions is used to define image request configurations in batches and supports all image-related attributes of ImageRequest.

ImageOptions can be used in the following locations:

The final priority of the same properties when constructing the ImageRequest is:

  1. ImageRequest.Builder
  2. Target.getImageOptions()
  3. ImageRequest.Builder.default(ImageOptions)
  4. Sketch.globalImageOptions

Example

Global:

Sketch.Builder(context).apply {
    globalImageOptions(ImageOptions {
        placeholer(R.drawable.placeholder)
        error(R.drawable.error)
        // more ...
    })
}.build()

View:

sketchImageView.imageOptions = ImageOptions {
    placeholer(R.drawable.placeholder)
    // more ...
}

ImageRequest:

ImageRequest(context, "https://example.com/image.jpg") {
    merge(ImageOptions {
        placeholer(R.drawable.placeholder)
        error(R.drawable.error)
        // more ...
    })
    default(ImageOptions {
        placeholer(R.drawable.placeholder)
        error(R.drawable.error)
        // more ...
    })
}

AsyncImageState:

val state = rememberAsyncImageState(ComposableImageOptions {
  placeholer(Res.drawable.placeholder)
  error(Res.drawable.error)
  // more ...
})
AsyncImage(
  uri = "https://example.com/image.jpg",
  contentDescription = "",
  state = state,
)