# compose-ios

Khanzada Kashif

09/06/2023, 7:02 PM
I am trying to load and cache images from a remote source in my compose multiplatform project, I have used the image-loader library to do that but the problem with it is that it works fine normally but it makes the UI very laggy once caching enabled. image-loader:- I have also tried using Kamel but it is not working on iOS with some classes not found error on compile time. Now I have moved my image loader to expect/actual and for android I am using coil which is working really well and for iOS I have done the following,
Copy code
actual fun MyAsyncImage(
    url: String,
    contentScale: ContentScale,
    contentDescription: String?,
    modifier: Modifier,
) {
        modifier = modifier
    ) {
            factory = {
                UIImageView().apply {
                    loadImageFromUrl(url = url)
            modifier = Modifier
        Box(modifier = Modifier.fillMaxSize())

fun UIImageView.loadImageFromUrl(url: String) {
    if (url.contains("\\s".toRegex()).not())
            url = NSURL(string = url),
            completionHandler = { data, response, error ->
                if (error == null && response != null && data != null) {
                    if ((response as NSHTTPURLResponse).statusCode == 200L) {
                        CoroutineScope(Dispatchers.Main).launch {
                            image = UIImage(data = data)
It loads and caches images just fine but the only problem is the these images are being loaded in a lazy column that is under the top bar. Now while scrolling when rest of the lazy column goes under the top bar, just this image goes on top of the top bar. I have attached the ss of it.


09/08/2023, 6:05 AM
Is lagging after configuring disk cache? can you show me the configure of ImageLoader?