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

jvmMain.ImageComposition.kt Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import com.seiko.imageloader.ImageLoader
import com.seiko.imageloader.LocalImageLoader
import com.seiko.imageloader.component.setupDefaultComponents
import com.seiko.imageloader.defaultImageResultMemoryCache
import okio.Path.Companion.toOkioPath
import java.io.File

private fun generateImageLoader(): ImageLoader {
    return ImageLoader {
        components {
            setupDefaultComponents()
        }
        interceptor {
            // cache 100 success image result, without bitmap
            defaultImageResultMemoryCache()
            memoryCacheConfig {
                maxSize(32 * 1024 * 1024) // 32MB
            }
            diskCacheConfig {
                directory(File.createTempFile("prefix", "postfix").parentFile.resolve("image_cache").toOkioPath())
                maxSizeBytes(512L * 1024 * 1024) // 512MB
            }
        }
    }
}

@Composable
fun ImageComposition(content: @Composable () -> Unit) {
    CompositionLocalProvider(
        LocalImageLoader provides remember { generateImageLoader() },
        content = content
    )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy