pinterest / PINRemoteImage

A thread safe, performant, feature rich image fetcher
Apache License 2.0
4.01k stars 511 forks source link

Add support for dynamic placeholder images #613

Closed bdolman closed 2 years ago

bdolman commented 3 years ago

Before this change, if you attempted to use a dynamic image for a placeholder (e.g. an image from an asset catalog that has both dark and light versions) you would get unpredictable results. This is because PINAnimatedImageView is drawing the image directly to the layer without consulting the view's current trait collection. So which version of the image you get depends entirely on what the global UITraitCollection.currentTraitCollection is.

According to Apple, "UIKit updates the value of this property before calling several well-known methods of UIView, UIViewController, and UIPresentationController." Though they do not say what those methods are, experimentation concludes that "displayLayer:" is not one of those.

To solve this, we need to make sure that when we generate the CGImage, we are explicit about using the view's trait collection so that we get the correct image.

garrettmoon commented 2 years ago

Looks great, thank you for the contribution!

It sounds like this is a non-issue for the UIImageView categories?