Created
April 3, 2022 06:16
-
-
Save Sal7one/01f24d2416df664e0bce3b7a02421faf to your computer and use it in GitHub Desktop.
Loading SVGs from a URL with COIL on Jetpack compose (inline imageLoader)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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