Coder Social home page Coder Social logo

compose-image-loader's Introduction

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

// Initialize SDK in Application
// Sample application
class ImageLoaderApplication : Application() {
    override fun onCreate() {
        super.onCreate()
            imageLoader()
    }
}

Configured Image request

 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<Boolean>(true)
        }

        var bitMap by remember {
            mutableStateOf<Bitmap?>(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
)

compose-image-loader's People

Contributors

iamatulkumar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.