https://github.com/iamatulkumar/compose-image-loader
https://github.com/iamatulkumar/compose-image-loader
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/iamatulkumar/compose-image-loader
- Owner: iamatulkumar
- Created: 2024-04-17T18:56:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-17T19:00:15.000Z (about 2 years ago)
- Last Synced: 2024-04-17T19:58:26.701Z (about 2 years ago)
- Language: Kotlin
- Size: 112 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Heimdal Image Loader
Modern image loading library for Android. Simple by design, powerful under the hood.
- **Kotlin**: Heimdal Image Loader is Kotlin-native and uses no any dependencies
## Demo
Please see the app for library usage example.
## Quick Start
To load an image in jetpack compose
```kotlin
// Initialize SDK in Application
// Sample application
class ImageLoaderApplication : Application() {
override fun onCreate() {
super.onCreate()
imageLoader()
}
}
```
Configured Image request
```kotlin
fetch(
context,
url, // image url
onSuccess = {
// Lamda function
}, onError = {
// Lamda function
},
)
@Composable
fun ImageItem(
data: String = "https://images.unsplash.com/photo-1550973886-796d048c599f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjU4MjM5fQ",
modifier: Modifier = Modifier.aspectRatio(1f),
) {
val context = LocalContext.current
var isLoading by remember {
mutableStateOf(true)
}
var bitMap by remember {
mutableStateOf(null)
}
if(bitMap == null && isLoading) {
fetch(
context,
data,
onSuccess = {
loadBitMap ->
bitMap = loadBitMap
isLoading = false
}, onError = {
isLoading = false
},
)
}
Box(modifier, Alignment.Center) {
if(isLoading) {
CircularProgressIndicator()
} else {
bitMap?.also {loadedBitMap ->
Image(bitmap = loadedBitMap.asImageBitmap(), contentDescription = "")
}
}
}
}
```
```
#### Image Loader
`imageloader()` uses the singleton `Heimdal` class. The singleton `imageLoader()` can be accessed using an extension function
To configure custom singleton `Heimdal`,
```kotlin
val imageLoader = initImageLoader(
decoders = listOf(BitmapDecoder()), // images decoders
fileProvider = FileProviderImpl(
cacheDir,
DiskCacheImpl( // LRU disk cache for your images
DiskLruCache.create(cacheDir, 15728640L)
),
UrlLoader(), // vararg; http/https scheme support
FileLoader(assets), // vararg; file scheme support
ContentLoader(contentResolver) // vararg; content scheme support
),
memoryCache = MemoryCacheImpl(), // Caching images on memory
)
```