From 9befe516da8486b9d2c137804622fc1d245877e4 Mon Sep 17 00:00:00 2001 From: Eric Jensen Date: Tue, 28 May 2024 13:47:28 -0400 Subject: [PATCH] Correct the fade transition when content modes differ Previously runCrossDissolveWithContentMode was adding the transitionView to the imageView and settting the imageViews alpha to 0. This resulted in the image immediately disappearing since alpha of subviews are multiplied by the alpha of parent views. --- Sources/NukeExtensions/ImageViewExtensions.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/NukeExtensions/ImageViewExtensions.swift b/Sources/NukeExtensions/ImageViewExtensions.swift index 805b6787e..7d9d6cf7c 100644 --- a/Sources/NukeExtensions/ImageViewExtensions.swift +++ b/Sources/NukeExtensions/ImageViewExtensions.swift @@ -400,7 +400,7 @@ extension ImageViewController { ) } - /// Performs cross-dissolve animation alonside transition to a new content + /// Performs cross-dissolve animation alongside transition to a new content /// mode. This isn't natively supported feature and it requires a second /// image view. There might be better ways to implement it. private func runCrossDissolveWithContentMode(imageView: UIImageView, image: ImageContainer, params: ImageLoadingOptions.Transition.Parameters) { @@ -410,8 +410,13 @@ extension ImageViewController { // Create a transition view which mimics current view's contents. transitionView.image = imageView.image transitionView.contentMode = imageView.contentMode - imageView.addSubview(transitionView) - transitionView.frame = imageView.bounds + if let superview = imageView.superview { + superview.insertSubview(transitionView, belowSubview: imageView) + transitionView.frame = imageView.frame + } else { + imageView.addSubview(transitionView) + transitionView.frame = imageView.bounds + } // "Manual" cross-fade. transitionView.alpha = 1