SkapaImage

This Object provides the necessary properties to build an Skapa Image component

Example of usage


This function uses Coil to create a Skapa Image Component using SkapaImage object

import coil.compose.AsyncImagePainter
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import net.ikea.skapa.ui.components.AspectRatioBox
import net.ikea.skapa.ui.components.SkapaAspectRatio
import net.ikea.skapa.ui.components.SkapaImage

@Composable
@OptIn(ExperimentalSkapaApi::class)
private fun SkapaImageCoilWrapper(imgUrl: String?) {
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current)
.data(imgUrl)
.error(SkapaImage.Error)
.fallback(SkapaImage.Fallback)
.build()
)

val aspectRatioModifier =
if (painter.state is AsyncImagePainter.State.Success) Modifier.aspectRatio(SkapaAspectRatio.Ratio16by9.value) else Modifier

AspectRatioBox(
aspectRatio = SkapaAspectRatio.Ratio16by9,
) {
Image(
painter = painter,
contentScale = ContentScale.Crop,
contentDescription = "coil",
modifier = Modifier
.align(Alignment.Center)
.then(aspectRatioModifier)
)
}

See also

Properties

Link copied to clipboard

Default background recommended to use for Fallback and Error States

Link copied to clipboard
val Error: ERROR CLASS: Unresolved name: ic_image_error_image

Visual placeholder to be used when Image fails to load or when the Image link is broken.

Link copied to clipboard
val Fallback: ERROR CLASS: Unresolved name: ic_image_fallback_image

Visual placeholder to be used as fallback when Image data is missing.