CoilImage

@Composable()
fun CoilImage(imageModel: Any, modifier: Modifier = Modifier, context: Context = LocalContext.current, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, imageLoader: ImageLoader = LocalCoilProvider.getCoilImageLoader(), alignment: Alignment = Alignment.Center, alpha: Float = DefaultAlpha, contentScale: ContentScale = ContentScale.Crop, contentDescription: String? = null, circularRevealedEnabled: Boolean = false, circularRevealedDuration: Int = DefaultCircularRevealedDuration, colorFilter: ColorFilter? = null, shimmerParams: ShimmerParams, bitmapPalette: BitmapPalette? = null, error: Any? = null)

Requests loading an image with a loading placeholder and error image resource (ImageBitmap, ImageVector, Painter).

CoilImage(
imageModel = imageModel,
shimmerParams = ShimmerParams (
baseColor = backgroundColor,
highlightColor = highlightColor
),
error = ImageBitmap.imageResource(R.drawable.error)
)

or we can use ImageVector or custom Painter like the below.

error = ImageVector.vectorResource(R.drawable.error)

Parameters

imageModel

The data model to request image. See ImageRequest.Builder.data for types allowed.

modifier

Modifier used to adjust the layout or drawing content.

context

The context for creating the ImageRequest.Builder.

lifecycleOwner

The LifecycleOwner for constructing the ImageRequest.Builder.

imageLoader

The ImageLoader to use when requesting the image. Defaults to LocalCoilProvider.getCoilImageLoader.

alignment

The alignment parameter used to place the loaded ImageBitmap in the image container.

alpha

The alpha parameter used to apply for the image when it is rendered onscreen.

contentScale

The scale parameter used to determine the aspect ratio scaling to be used for the loaded ImageBitmap.

contentDescription

The content description used to provide accessibility to describe the image.

circularRevealedEnabled

Whether to run a circular reveal animation when images are successfully loaded.

circularRevealedDuration

The duration of the circular reveal animation.

colorFilter

The colorFilter parameter used to apply for the image when it is rendered onscreen.

shimmerParams

The shimmer related parameter used to determine constructions of the Shimmer.

bitmapPalette

A Palette generator for extracting major (theme) colors from images.

error

An ImageBitmap, ImageVector, or Painter for showing instead of the target image when images are failed to load.

@Composable()
fun CoilImage(imageModel: Any, modifier: Modifier = Modifier, context: Context = LocalContext.current, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, imageLoader: ImageLoader = LocalCoilProvider.getCoilImageLoader(), alignment: Alignment = Alignment.Center, alpha: Float = DefaultAlpha, contentScale: ContentScale = ContentScale.Crop, contentDescription: String? = null, circularRevealedEnabled: Boolean = false, circularRevealedDuration: Int = DefaultCircularRevealedDuration, bitmapPalette: BitmapPalette? = null, colorFilter: ColorFilter? = null, placeHolder: Any? = null, error: Any? = null)

Requests loading an image with a loading placeholder and error image resource (ImageBitmap, ImageVector, Painter).

CoilImage(
imageModel = imageModel,
placeHolder = ImageBitmap.imageResource(R.drawable.placeholder),
error = ImageBitmap.imageResource(R.drawable.error)
)

or we can use ImageVector or custom Painter like the below.

placeHolder = ImageVector.vectorResource(R.drawable.placeholder)
error = ImageVector.vectorResource(R.drawable.error)

Parameters

imageModel

The data model to request image. See ImageRequest.Builder.data for types allowed.

modifier

Modifier used to adjust the layout or drawing content.

context

The context for creating the ImageRequest.Builder.

lifecycleOwner

The LifecycleOwner for constructing the ImageRequest.Builder.

imageLoader

The ImageLoader to use when requesting the image. Defaults to LocalCoilProvider.getCoilImageLoader.

alignment

The alignment parameter used to place the loaded ImageBitmap in the image container.

alpha

The alpha parameter used to apply for the image when it is rendered onscreen.

contentScale

The scale parameter used to determine the aspect ratio scaling to be used for the loaded ImageBitmap.

contentDescription

The content description used to provide accessibility to describe the image.

circularRevealedEnabled

Whether to run a circular reveal animation when images are successfully loaded.

circularRevealedDuration

The duration of the circular reveal animation.

bitmapPalette

A Palette generator for extracting major (theme) colors from images.

colorFilter

The colorFilter parameter used to apply for the image when it is rendered onscreen.

placeHolder

An ImageBitmap, ImageVector, or Painter to be displayed when the request is in progress.

error

An ImageBitmap, ImageVector, or Painter for showing instead of the target image when images are failed to load.

@Composable()
fun CoilImage(imageModel: Any, modifier: Modifier = Modifier, context: Context = LocalContext.current, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, imageLoader: ImageLoader = LocalCoilProvider.getCoilImageLoader(), alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Crop, contentDescription: String? = null, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, circularRevealedEnabled: Boolean = false, circularRevealedDuration: Int = DefaultCircularRevealedDuration, shimmerParams: ShimmerParams, bitmapPalette: BitmapPalette? = null, success: @Composable() (imageState: CoilImageState.Success) -> Unit? = null, failure: @Composable() (imageState: CoilImageState.Failure) -> Unit? = null)

Requests loading an image and create some composables based on CoilImageState.

CoilImage(
imageModel = imageModel,
modifier = modifier,
shimmerParams = ShimmerParams (
baseColor = backgroundColor,
highlightColor = highlightColor
),
failure = {
Text(text = "image request failed.")
})

Parameters

imageModel

The data model to request image. See ImageRequest.Builder.data for types allowed.

modifier

Modifier used to adjust the layout or drawing content.

context

The context for creating the ImageRequest.Builder.

lifecycleOwner

The LifecycleOwner for constructing the ImageRequest.Builder.

imageLoader

The ImageLoader to use when requesting the image. Defaults to LocalCoilProvider.getCoilImageLoader.

alignment

The alignment parameter used to place the loaded ImageBitmap in the image container.

alpha

The alpha parameter used to apply for the image when it is rendered onscreen.

contentScale

The scale parameter used to determine the aspect ratio scaling to be used for the loaded ImageBitmap.

contentDescription

The content description used to provide accessibility to describe the image.

circularRevealedEnabled

Whether to run a circular reveal animation when images are successfully loaded.

circularRevealedDuration

The duration of the circular reveal animation.

bitmapPalette

A Palette generator for extracting major (theme) colors from images.

colorFilter

The colorFilter parameter used to apply for the image when it is rendered onscreen.

success

Content to be displayed when the request is succeeded.

failure

Content to be displayed when the request is failed.

@Composable()
fun CoilImage(imageModel: Any, modifier: Modifier = Modifier, context: Context = LocalContext.current, lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, imageLoader: ImageLoader = LocalCoilProvider.getCoilImageLoader(), alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Crop, contentDescription: String? = null, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, circularRevealedEnabled: Boolean = false, circularRevealedDuration: Int = DefaultCircularRevealedDuration, bitmapPalette: BitmapPalette? = null, loading: @Composable() (imageState: CoilImageState.Loading) -> Unit? = null, success: @Composable() (imageState: CoilImageState.Success) -> Unit? = null, failure: @Composable() (imageState: CoilImageState.Failure) -> Unit? = null)

Requests loading an image and create some composables based on CoilImageState.

CoilImage(
imageModel = imageModel,
modifier = modifier,
loading = {
ConstraintLayout(
modifier = Modifier.fillMaxSize()
) {
val indicator = createRef()
CircularProgressIndicator(
modifier = Modifier.constrainAs(indicator) {
top.linkTo(parent.top)
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
)
}
},
failure = {
Text(text = "image request failed.")
})

Parameters

imageModel

The data model to request image. See ImageRequest.Builder.data for types allowed.

modifier

Modifier used to adjust the layout or drawing content.

context

The context for creating the ImageRequest.Builder.

lifecycleOwner

The LifecycleOwner for constructing the ImageRequest.Builder.

imageLoader

The ImageLoader to use when requesting the image. Defaults to LocalCoilProvider.getCoilImageLoader.

alignment

The alignment parameter used to place the loaded ImageBitmap in the image container.

alpha

The alpha parameter used to apply for the image when it is rendered onscreen.

contentScale

The scale parameter used to determine the aspect ratio scaling to be used for the loaded ImageBitmap.

contentDescription

The content description used to provide accessibility to describe the image.

circularRevealedEnabled

Whether to run a circular reveal animation when images are successfully loaded.

circularRevealedDuration

The duration of the circular reveal animation.

bitmapPalette

A Palette generator for extracting major (theme) colors from images.

colorFilter

The colorFilter parameter used to apply for the image when it is rendered onscreen.

loading

Content to be displayed when the request is in progress.

success

Content to be displayed when the request is succeeded.

failure

Content to be displayed when the request is failed.

@Composable()
fun CoilImage(imageRequest: ImageRequest, modifier: Modifier = Modifier, imageLoader: ImageLoader = LocalCoilProvider.getCoilImageLoader(), alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Crop, contentDescription: String? = null, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, circularRevealedEnabled: Boolean = false, circularRevealedDuration: Int = DefaultCircularRevealedDuration, shimmerParams: ShimmerParams, bitmapPalette: BitmapPalette? = null, success: @Composable() (imageState: CoilImageState.Success) -> Unit? = null, failure: @Composable() (imageState: CoilImageState.Failure) -> Unit? = null)

Requests loading an image and create some composables based on CoilImageState.

CoilImage(
imageRequest = ImageRequest.Builder(context)
.data(imageModel)
.lifecycle(lifecycleOwner)
.build(),
modifier = modifier,
shimmerParams = ShimmerParams (
baseColor = backgroundColor,
highlightColor = highlightColor
),
failure = {
Text(text = "image request failed.")
})

Parameters

imageRequest

The request to execute.

modifier

Modifier used to adjust the layout or drawing content.

imageLoader

The ImageLoader to use when requesting the image. Defaults to LocalCoilProvider.getCoilImageLoader.

alignment

The alignment parameter used to place the loaded ImageBitmap in the image container.

alpha

The alpha parameter used to apply for the image when it is rendered onscreen.

contentScale

The scale parameter used to determine the aspect ratio scaling to be used for the loaded ImageBitmap.

contentDescription

The content description used to provide accessibility to describe the image.

circularRevealedEnabled

Whether to run a circular reveal animation when images are successfully loaded.

circularRevealedDuration

The duration of the circular reveal animation.

bitmapPalette

A Palette generator for extracting major (theme) colors from images.

colorFilter

The colorFilter parameter used to apply for the image when it is rendered onscreen.

success

Content to be displayed when the request is succeeded.

failure

Content to be displayed when the request is failed.

@Composable()
fun CoilImage(imageRequest: ImageRequest, modifier: Modifier = Modifier, imageLoader: ImageLoader = LocalCoilProvider.getCoilImageLoader(), alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Crop, contentDescription: String? = null, alpha: Float = DefaultAlpha, colorFilter: ColorFilter? = null, circularRevealedEnabled: Boolean = false, circularRevealedDuration: Int = DefaultCircularRevealedDuration, bitmapPalette: BitmapPalette? = null, loading: @Composable() (imageState: CoilImageState.Loading) -> Unit? = null, success: @Composable() (imageState: CoilImageState.Success) -> Unit? = null, failure: @Composable() (imageState: CoilImageState.Failure) -> Unit? = null)

Requests loading an image and create some composables based on CoilImageState.

CoilImage(
imageRequest = ImageRequest.Builder(context)
.data(imageModel)
.lifecycle(lifecycleOwner)
.build(),
modifier = modifier,
loading = {
ConstraintLayout(
modifier = Modifier.fillMaxSize()
) {
val indicator = createRef()
CircularProgressIndicator(
modifier = Modifier.constrainAs(indicator) {
top.linkTo(parent.top)
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
end.linkTo(parent.end)
}
)
}
},
failure = {
Text(text = "image request failed.")
})

Parameters

imageRequest

The request to execute.

modifier

Modifier used to adjust the layout or drawing content.

imageLoader

The ImageLoader to use when requesting the image. Defaults to LocalCoilProvider.getCoilImageLoader.

alignment

The alignment parameter used to place the loaded ImageBitmap in the image container.

alpha

The alpha parameter used to apply for the image when it is rendered onscreen.

contentScale

The scale parameter used to determine the aspect ratio scaling to be used for the loaded ImageBitmap.

contentDescription

The content description used to provide accessibility to describe the image.

circularRevealedEnabled

Whether to run a circular reveal animation when images are successfully loaded.

circularRevealedDuration

The duration of the circular reveal animation.

bitmapPalette

A Palette generator for extracting major (theme) colors from images.

colorFilter

The colorFilter parameter used to apply for the image when it is rendered onscreen.

loading

Content to be displayed when the request is in progress.

success

Content to be displayed when the request is succeeded.

failure

Content to be displayed when the request is failed.