Skip to content

Commit

Permalink
fix: flaky transition, wait for the transition once the target image …
Browse files Browse the repository at this point in the history
…is ready.
  • Loading branch information
michaelhenry committed Oct 18, 2022
1 parent 840b873 commit 3274b5f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Sources/ImageViewer_swift/ImageLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public struct URLSessionImageLoader: ImageLoader {
}

DispatchQueue.main.async {
UIView.setAnimationsEnabled(false)
imageView.image = image
completion(image)
UIView.setAnimationsEnabled(true)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/ImageViewer_swift/ImageViewerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ extension ImageViewerController {
}

func updateConstraintsForSize(_ size: CGSize) {

let yOffset = max(0, (size.height - imageView.frame.height) / 2)
top.constant = yOffset
bottom.constant = yOffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class ImageViewerTransitionPresentationAnimator:NSObject {

let isPresenting: Bool
let imageContentMode: UIView.ContentMode

var observation: NSKeyValueObservation?

init(isPresenting: Bool, imageContentMode: UIView.ContentMode) {
self.isPresenting = isPresenting
Expand Down Expand Up @@ -100,10 +102,14 @@ extension ImageViewerTransitionPresentationAnimator: UIViewControllerAnimatedTra
UIView.animate(withDuration: duration, animations: {
dummyImageView.frame = UIScreen.main.bounds
controller.view.alpha = 1.0
}) { finished in
transitionVC.targetView?.alpha = 1.0
dummyImageView.removeFromSuperview()
completed(finished)
}) { [weak self] finished in
self?.observation = transitionVC.targetView?.observe(\.image, options: [.new, .initial]) { img, change in
if img.image != nil {
transitionVC.targetView?.alpha = 1.0
dummyImageView.removeFromSuperview()
completed(finished)
}
}
}
}

Expand Down

0 comments on commit 3274b5f

Please sign in to comment.