Skip to content

Instantly share code, notes, and snippets.

@Sal7one
Created April 3, 2022 06:16
Show Gist options
  • Save Sal7one/01f24d2416df664e0bce3b7a02421faf to your computer and use it in GitHub Desktop.
Save Sal7one/01f24d2416df664e0bce3b7a02421faf to your computer and use it in GitHub Desktop.
Loading SVGs from a URL with COIL on Jetpack compose (inline imageLoader)
// By Sal7one - 3/4/2022
// Inline ImageLoader if you have a diffrenet need than your ImageLoader Singlton
//
// Since LocalImageLoader is deprecated
//
// Coil Version
// implementation("io.coil-kt:coil-compose:2.0.0-rc02")
// implementation("io.coil-kt:coil-svg:2.0.0-rc02")
//
//
// This composable will return an Image with the flag of Saudi Arabia SVG
@Composable
fun Flag() {
val context = LocalContext.current
val svgLink = "https://upload.wikimedia.org/wikipedia/commons/0/0d/Flag_of_Saudi_Arabia.svg"
val imageLoader = ImageLoader.Builder(context)
.components {
add(SvgDecoder.Factory())
}
.build()
val svgPainter = rememberAsyncImagePainter(svgLink, imageLoader = imageLoader)
Image(
painter = svgPainter,
contentDescription = "SVG Image",
contentScale = ContentScale.FillBounds
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment