Nil
0.1.0-alpha05indexedAn image loading library features asynchronous image loading, memory and disk caching, GIF and SVG support, and integrates network authentication. Supports vectors and XML configurations.
An image loading library features asynchronous image loading, memory and disk caching, GIF and SVG support, and integrates network authentication. Supports vectors and XML configurations.
An image loading library for Compose Multiplatform.
Translations: Português
Import the core module, a fetcher, and a decoder to get started.
implementation("com.neoutils.nil:core:0.1.0-alpha05")
implementation("com.neoutils.nil:bitmap-decoder:0.1.0-alpha05")
implementation("com.neoutils.nil:network-fetcher-default:0.1.0-alpha05")
Use asyncPainterResource to load an image asynchronously.
Image(
painter = asyncPainterResource(
Request.network("https://cataas.com/cat")
),
contentDescription = null,
)
Add the dependencies for the desired cache functionalities.
implementation("com.neoutils.nil:memory-cache:0.1.0-alpha05")
implementation("com.neoutils.nil:disk-cache:0.1.0-alpha05")
Use the diskCache and memoryCache extensions to configure.
Image(
painter = asyncPainterResource(...) {
diskCache {
maxSize = 10.mb
}
},
contentDescription = null,
)
For animated image support like GIF and WebP, add the GifDecoder dependency.
implementation("com.neoutils.nil:gif-decoder:0.1.0-alpha05")
And declare it in the configuration.
Image(
painter = asyncPainterResource(
Request.network("https://cataas.com/cat/gif"),
) {
decoders {
gif() // or +GifDecoder()
}
},
contentDescription = null,
)
Use the gif extension for configuration.
Image(
painter = asyncPainterResource(...) {
...
gif {
repeatCount = 2
}
},
contentDescription = null,
)
For SVG image support, add the SVG decoder dependency.
implementation("com.neoutils.nil:svg-decoder:0.1.0-alpha05")
And declare it in the configuration.
Image(
painter = asyncPainterResource(
Request.network("https://example.com/image.svg"),
) {
decoders {
svg() // or +SvgDecoder()
}
},
contentDescription = null,
)
To load images from Compose resources, add the following dependency.
implementation("com.neoutils.nil:resources-fetcher:0.1.0-alpha05")
And use the Request.resource(...) extension.
Image(
painter = syncPainterResource(
Request.resource(Res.drawable.cute_cat),
),
contentDescription = null,
)
For Drawable Image Vector support, add the XML decoder dependency.
implementation("com.neoutils.nil:xml-decoder:0.1.0-alpha05")
And declare it in the configuration.
Image(
painter = syncPainterResource(
Request.resource(Res.drawable.vector_icon),
) {
decoders {
xml() // or +XmlDecoder()
}
},
contentDescription = null,
)
Use the network extension to configure the NetworkFetcher.
Image(
painter = asyncPainterResource(
Request.network(...),
) {
network {
headers = mapOf("Authorization" to "Bearer ...")
}
},
contentDescription = null,
)
Use the network-fetcher dependency instead of network-fetcher-default to manually specify
the Ktor Client.
implementation("com.neoutils.nil:network-fetcher:0.1.0-alpha05")
Configure the client for each target.
kotlin {
sourceSets {
androidMain {
dependencies {
implementation("io.ktor:ktor-client-okhttp:3.1.0")
}
}
iosMain {
dependencies {
implementation("io.ktor:ktor-client-darwin:3.1.0")
}
}
jvmMain {
dependencies {
implementation("io.ktor:ktor-client-java:3.1.0")
}
}
...
}
}
Use the placeholder and failure parameters to display images during loading or in case of failure.
Image(
painter = asyncPainterResource(
request = Request.network("..."),
placeholder = painterResource(Res.drawable.placeholder),
failure = painterResource(Res.drawable.failure),
),
contentDescription = null,
)
Or handle states manually.
val resource = asyncPainterResource(
Request.network("..."),
)
when (resource) {
is PainterResource.Result.Success -> {
Image(
painter = resource,
contentDescription = null,
)
}
is PainterResource.Loading -> {
if (resource.progress != ) {
CircularProgressIndicator(
progress = { resource.progress!! }
)
} {
CircularProgressIndicator()
}
}
PainterResource.Result.Failure -> {
(resource.throwable ResponseException) {
Image(
painter = painterResource(Res.drawable.failure),
contentDescription = ,
)
} {
resource.throwable
}
}
}
Copyright 2025 Irineu A. Silva
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
https:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.
Surfaced from shared tags and platforms — no rankings paid for.