Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image does not load in iOS with custom Kamel Config #118

Open
erickvelasco11 opened this issue Nov 8, 2024 · 3 comments
Open

Image does not load in iOS with custom Kamel Config #118

erickvelasco11 opened this issue Nov 8, 2024 · 3 comments

Comments

@erickvelasco11
Copy link

Hi
Thanks for your work here and given us this library. It's really useful because load images by URL should be a basic functionality of Kotlin. however, you've made a great job.
I have an issue. When I use Kamel to load a profile image all works fine, but if I need to give the user the ability of change his photo, the photo does not update, because the cache maintain the old photo. I read the documentation and see I can invalidate the cache using a Custom Kamel Config, but when I use it in iOS, the image does not load.

This code works perfectly

KamelImage(
  {
      asyncPainterResource(data = urlImage)
  },
  contentDescription = "image",
  contentScale = ContentScale.Crop,
  modifier = modifier
      .size(radius)
      .clip(CircleShape)
      .clickable {
          onClick()
      },
  animationSpec = tween(),
  onFailure = {
      println("Error loading photo: ${it.message}")
      Image(
          painterResource(Res.drawable.default_profile),
          contentDescription = "Profile",
          modifier = Modifier
              .size(radius)
              .clip(CircleShape)
              .clickable { onClick() },
      )
  },
  onLoading = {
      Box(
          modifier = modifier
              .size(radius)
              .clip(CircleShape),
          contentAlignment = Alignment.Center
      ) {
          CircularProgressIndicator(color = loaderColor)
      }
  }
)

But this code does not work in iOS (Android works perfectly)

val customKamelConfig = KamelConfig {
    takeFrom(KamelConfig.Default)
    if (invalidateCache) {
        imageBitmapCacheSize = 1
    }
}

CompositionLocalProvider(LocalKamelConfig provides customKamelConfig) {
    /// Same code above
}

I really appreciate your help because if I don't invalidate the cache, the user changes his photo, but the image does not update.

Thanks

@erickvelasco11
Copy link
Author

I think you aren't using the Native Ktor client to fetch the image when the cache is invalidated, because the issue in OnFailure is

Error loading photo: TLS sessions are not supported on Native platform.

I'm using last version of Ktor in both platform, OKHTTP for Android and DARWIN for iOS, but the implementation for Kamel is internal.

@luca992
Copy link
Member

luca992 commented Nov 13, 2024

Say you have url_a and url_b. If you have imageBitmapCacheSize = 1 and load url_a, it will be cached in memory since you allowed one image to be cached. Now even if you change the image on the backend, url_a should get loaded from memory every time with the old image. However if you load url_b then url_a once again, it should be loading the new version of url_a since loading url_b wiped if from the cache if one one cached value is allowed.

Also if you are using the disk cache:

KamelConfig {
    httpFetcher {
        // The size of the cache can be defined in bytes. Or DefaultHttpCacheSize (10 MiB) can be used. 
        httpCache(DefaultHttpCacheSize)
    }
}

even if you disable/wipe the memory cache, ktor will try to get it from the disk cache before attempting to make a network call. So you may need disable/ delete the disk cache.

...Off hand I'm not sure if we added a way to invalidate a specific cached entry yet 🤔

@luca992
Copy link
Member

luca992 commented Nov 13, 2024

as for Error loading photo: TLS sessions are not supported on Native platform. if you can provide url that causes that I can take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants