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.
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.