You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

21 lines
597 B

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
}
}