glide
glide copied to clipboard
Glide placeholders load drawable resources with wrong context
Glide Version: 4.12.0
Device/Android Version: Explicitly tested on Pixel 5 running Android 12, but this is applicable to all devices and Android versions.
Issue details / Repro steps / Use case background:
When using a placeholder resource ID like so, Glide uses an unexpected Context to load the drawable:
val options = RequestOptions().placeholder(R.color.some_color_resource)
Glide.with(imageView.context)
.load("http://the.url")
.apply(options)
.into(imageView)
I would expect this to use the imageView's context to load the Placeholder (which in most cases would be an Activity), but in fact it uses the application context to load the image.
This is because SingleRequest uses glideContext to load the drawable.
The reason we discovered this is this behavior does not work well with dark mode. Specifically, if the device is currently in dark mode but an application has set itself to MODE_NIGHT_NO via AppCompatDelegate.setDefaultNightMode() then the placeholder will be incorrectly loaded from values-night.
Glide load line / GlideModule (if any) / list Adapter code (if any):
val options = RequestOptions().placeholder(R.color.some_color_resource)
Glide.with(imageView.context)
.load("http://the.url")
.apply(options)
.into(imageView)
values/colors.xml:
<color name="some_color_resource">#ff000000</color>
values-night/colors.xml:
<color name="some_color_resource">#ffffffff</color>
SampleApplication.kt:
class SampleApplication : Application {
override fun onCreate() {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
As a short term fix we are getting the Drawable instance ourselves via ResourcesCompat.getDrawable() instead of letting Glide manage getting the drawable.
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Still an issue.
Would be great if this could be fixed
Still waiting for a fix.
Seems like a duplicate of https://github.com/bumptech/glide/issues/3778 and https://github.com/bumptech/glide/issues/3751, PR for fix in https://github.com/bumptech/glide/pull/4842
Duplicate of #3751
Thanks @TWiStErRob