Skip to content

Commit

Permalink
Correct the fade transition when content modes differ
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ejensen committed May 28, 2024
1 parent 7395c7a commit 02ae806
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/NukeExtensions/ImageViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, aboveSubview: imageView)
transitionView.frame = imageView.frame
} else {
imageView.addSubview(transitionView)
transitionView.frame = imageView.bounds
}

// "Manual" cross-fade.
transitionView.alpha = 1
Expand Down

0 comments on commit 02ae806

Please sign in to comment.