jvmMain.ImageComposition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sample-jvm Show documentation
Show all versions of sample-jvm Show documentation
Kotlin Multiplatform paging library
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