Package dev.chrisbanes.accompanist.coil

Types

ErrorResult
Link copied to clipboard
typealias ErrorResult = ImageLoadState.Error
RequestResult
Link copied to clipboard
typealias RequestResult = ImageLoadState
SuccessResult
Link copied to clipboard
typealias SuccessResult = ImageLoadState.Success

Functions

CoilImage
Link copied to clipboard

Creates a composable that will attempt to load the given request using Coil, and provides complete content of how the current state is displayed:

CoilImage(
request = ImageRequest.Builder(context).data(...).build(),
) { imageState ->
when (imageState) {
is ImageLoadState.Success -> // TODO
is ImageLoadState.Error -> // TODO
ImageLoadState.Loading -> // TODO
ImageLoadState.Empty -> // TODO
}
}

@Composable()
fun CoilImage(request: ImageRequest, modifier: Modifier, requestBuilder: ImageRequest.Builder.(IntSize) -> ImageRequest.Builder?, imageLoader: ImageLoader, shouldRefetchOnSizeChange: (ImageLoadState, IntSize) -> Boolean, onRequestCompleted: (ImageLoadState) -> Unit, content: (ImageLoadState) -> Unit)

Creates a composable that will attempt to load the given data using Coil, and provides complete content of how the current state is displayed:

CoilImage(
data = "https://www.image.url",
) { imageState ->
when (imageState) {
is ImageLoadState.Success -> // TODO
is ImageLoadState.Error -> // TODO
ImageLoadState.Loading -> // TODO
ImageLoadState.Empty -> // TODO
}
}

@Composable()
fun CoilImage(data: Any, modifier: Modifier, requestBuilder: ImageRequest.Builder.(IntSize) -> ImageRequest.Builder?, imageLoader: ImageLoader, shouldRefetchOnSizeChange: (ImageLoadState, IntSize) -> Boolean, onRequestCompleted: (ImageLoadState) -> Unit, content: (ImageLoadState) -> Unit)

Creates a composable that will attempt to load the given request using Coil, and then display the result in an Image.

This version of the function is more opinionated, providing:

  • Support for displaying alternative content while the request is 'loading'. See the loading parameter.

  • Support for displaying alternative content if the request was unsuccessful. See the error parameter.

  • Support for automatically fading-in the image once loaded. See the fadeIn parameter.

CoilImage(
request = ImageRequest.Builder(context).data(...).build(),
fadeIn = true,
loading = {
Stack(Modifier.fillMaxSize()) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
}
}
)

@Composable()
fun CoilImage(request: ImageRequest, modifier: Modifier, alignment: Alignment, contentScale: ContentScale, colorFilter: ColorFilter?, fadeIn: Boolean, requestBuilder: ImageRequest.Builder.(IntSize) -> ImageRequest.Builder?, imageLoader: ImageLoader, shouldRefetchOnSizeChange: (ImageLoadState, IntSize) -> Boolean, onRequestCompleted: (ImageLoadState) -> Unit, error: (ImageLoadState.Error) -> Unit?, loading: () -> Unit?)

Creates a composable that will attempt to load the given data using Coil, and then display the result in an Image.

This version of the function is more opinionated, providing:

  • Support for displaying alternative content while the request is 'loading'. See the loading parameter.

  • Support for displaying alternative content if the request was unsuccessful. See the error parameter.

  • Support for automatically fading-in the image once loaded. See the fadeIn parameter.

CoilImage(
data = "https://www.image.url",
fadeIn = true,
loading = {
Stack(Modifier.fillMaxSize()) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
}
}
)

@Composable()
fun CoilImage(data: Any, modifier: Modifier, alignment: Alignment, contentScale: ContentScale, colorFilter: ColorFilter?, fadeIn: Boolean, requestBuilder: ImageRequest.Builder.(IntSize) -> ImageRequest.Builder?, imageLoader: ImageLoader, shouldRefetchOnSizeChange: (ImageLoadState, IntSize) -> Boolean, onRequestCompleted: (ImageLoadState) -> Unit, error: (ImageLoadState.Error) -> Unit?, loading: () -> Unit?)
CoilImageWithCrossfade
Link copied to clipboard
@Composable()
fun CoilImageWithCrossfade(request: ImageRequest, modifier: Modifier, alignment: Alignment, contentScale: ContentScale, crossfadeDuration: Int, imageLoader: ImageLoader, shouldRefetchOnSizeChange: (ImageLoadState, IntSize) -> Boolean, onRequestCompleted: (ImageLoadState) -> Unit, error: (ImageLoadState.Error) -> Unit?, loading: () -> Unit?)
@Composable()
fun CoilImageWithCrossfade(data: Any, modifier: Modifier, alignment: Alignment, contentScale: ContentScale, crossfadeDuration: Int, imageLoader: ImageLoader, shouldRefetchOnSizeChange: (ImageLoadState, IntSize) -> Boolean, onRequestCompleted: (ImageLoadState) -> Unit, error: (ImageLoadState.Error) -> Unit?, loading: () -> Unit?)