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:
- Target.getImageOptions()
- SketchImageView.imageOptions
- rememberAsyncImageState(ImageOptions)
- ImageRequest.Builder.merge(ImageOptions)/default(ImageOptions)
- Sketch.Builder.globalImageOptions(ImageOptions)
The final priority of the same properties when constructing the ImageRequest is:
- ImageRequest.Builder
- Target.getImageOptions()
- ImageRequest.Builder.default(ImageOptions)
- Sketch.globalImageOptions
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,
)