qdsfdhvh / compose-imageloader

Compose Image library for Kotlin Multiplatform.
https://qdsfdhvh.github.io/compose-imageloader/
MIT License
440 stars 15 forks source link

UI Gets laggy when image caching enabled. #281

Open Kashifmasood07 opened 1 year ago

Kashifmasood07 commented 1 year ago

It works fine normally but when I enabled Image caching as mentioned in the documentation, ui starts to lag a lot while scroll through the lazylists.

qdsfdhvh commented 1 year ago

Hi, thanks for use. which cache configure to cause ui to lag, can you provide a demo to help me analyse it?

Kashifmasood07 commented 1 year ago
fun ReviewSection(
    onImageClick: (List<MediaDomainModel>, Int) -> Unit,
    onProductImageClick: (List<MediaDomainModel>) -> Unit,
    onProductInfoClick: (Int) -> Unit,
) = ComposeUIViewController {
    CompositionLocalProvider(
        LocalImageLoader provides remember { generateImageLoader() }
    ) {
        MarkazSupplierAppTheme() {
            ReviewSectionScreen(
                onImageClick = onImageClick,
                onProductImageClick = onProductImageClick,
                onProductInfoClick = onProductInfoClick
            )
        }
    }

}

fun generateImageLoader(): ImageLoader {
    return ImageLoader {
        components {
            setupDefaultComponents()
        }
        interceptor {
            diskCacheConfig {
                directory(getCacheDir().toPath().resolve("image_cache"))
            }
        }
    }
}

fun getCacheDir(): String {
    return NSSearchPathForDirectoriesInDomains(
        NSCachesDirectory,
        NSUserDomainMask,
        true,
    ).first() as String
}

That is how I'm configuring caching. And it lags when I scroll through the lazy list, if i remove the caching it works fine.