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
Use ImageLoaderFactory to create the singleton ImageLoader. #609
Conversation
Crane/app/src/main/java/androidx/compose/samples/crane/util/UnsplashSizingInterceptor.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvment! Please can we revert the AGP change, other than that LGTM.
Crane/buildSrc/src/main/java/com/example/crane/buildsrc/Dependencies.kt
Outdated
Show resolved
Hide resolved
Crane/app/src/main/java/androidx/compose/samples/crane/CraneApplication.kt
Show resolved
Hide resolved
Owl/buildSrc/src/main/java/com/example/owl/buildsrc/Dependencies.kt
Outdated
Show resolved
Hide resolved
Crane/app/src/main/java/androidx/compose/samples/crane/util/UnsplashSizingInterceptor.kt
Show resolved
Hide resolved
@nickbutcher Thanks for the quick review! Updated based on the feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes!
Ahh, looks like this needs a |
@nickbutcher Updated |
Thanks for the contribution! |
@colinrtwhite I have a question about the implementation here. I currently have coil working as it was in this repo (before you made this PR. I basically shamelessly copy pasted what was here 😄 ) but I was using it in a specific compose-only module. The goal of this module is that everything is self contained, and so now with your changes I don't actually know where I would put
as I don't have an Application class. Any tips? |
@ColtonIdle You can use |
@colinrtwhite gotta be honest. Not sure where I would end up calling that setImageLoader method since my module is just filled with composables. I have a ImageWithUrl that just wraps a Coil image. i.e.
I will try to play around with this a bit more as I'm probably going a bit off topic at this point. |
For anyone following along... I ended up going this route with the guidance of @colinrtwhite
|
Removes
ProvideImageLoader
and implementsImageLoaderFactory
in the Crane and Owl apps. This has a couple benefits:ImageLoader
which is shared for everyrememberImagePainter
call. EachImageLoader
has its own memory cache, OkHttpClient, network observer, so it's cheaper to only create one.ImageLoaderFactory
creates theImageLoader
lazily the first timerememberImagePainter
is called.LocalImageLoader provides ImageLoader(context)
setsLocalImageLoader.current
for any child composables, however it doesn't set the singletonImageLoader
in theCoil
object. If you callLocalContext.current.imageLoader
elsewhere in the app, it'll return the singletonImageLoader
and not the value set inLocalImageLoader
. Maybe there's a better way for Coil to handle this (open to suggestions!)...