All Downloads are FREE. Search and download functionalities are using the official Maven repository.

desktopMain.org.jetbrains.compose.animatedimage.NetworkAnimatedImageLoader.kt Maven / Gradle / Ivy

There is a newer version: 1.8.0-alpha01
Show newest version
package org.jetbrains.compose.animatedimage

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.net.URL

internal class NetworkAnimatedImageLoader(private val imageUrl: String) : AnimatedImageLoader() {
    var cachedBytes: ByteArray? = null

    override suspend fun generateByteArray(): ByteArray = withContext(Dispatchers.IO) {
        var bytesArray: ByteArray? = cachedBytes

        if (bytesArray == null) {
            bytesArray = URL(imageUrl).readBytes()

            cachedBytes = bytesArray
        }

        return@withContext bytesArray
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy