Skip to content

Commit 3274b5f

Browse files
committed
fix: flaky transition, wait for the transition once the target image is ready.
1 parent 840b873 commit 3274b5f

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Sources/ImageViewer_swift/ImageLoader.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ public struct URLSessionImageLoader: ImageLoader {
2222
}
2323

2424
DispatchQueue.main.async {
25-
UIView.setAnimationsEnabled(false)
2625
imageView.image = image
2726
completion(image)
28-
UIView.setAnimationsEnabled(true)
2927
}
3028
}
3129
}

Sources/ImageViewer_swift/ImageViewerController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ extension ImageViewerController {
254254
}
255255

256256
func updateConstraintsForSize(_ size: CGSize) {
257-
258257
let yOffset = max(0, (size.height - imageView.frame.height) / 2)
259258
top.constant = yOffset
260259
bottom.constant = yOffset

Sources/ImageViewer_swift/ImageViewerTransitionPresentationManager.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ final class ImageViewerTransitionPresentationAnimator:NSObject {
2121

2222
let isPresenting: Bool
2323
let imageContentMode: UIView.ContentMode
24+
25+
var observation: NSKeyValueObservation?
2426

2527
init(isPresenting: Bool, imageContentMode: UIView.ContentMode) {
2628
self.isPresenting = isPresenting
@@ -100,10 +102,14 @@ extension ImageViewerTransitionPresentationAnimator: UIViewControllerAnimatedTra
100102
UIView.animate(withDuration: duration, animations: {
101103
dummyImageView.frame = UIScreen.main.bounds
102104
controller.view.alpha = 1.0
103-
}) { finished in
104-
transitionVC.targetView?.alpha = 1.0
105-
dummyImageView.removeFromSuperview()
106-
completed(finished)
105+
}) { [weak self] finished in
106+
self?.observation = transitionVC.targetView?.observe(\.image, options: [.new, .initial]) { img, change in
107+
if img.image != nil {
108+
transitionVC.targetView?.alpha = 1.0
109+
dummyImageView.removeFromSuperview()
110+
completed(finished)
111+
}
112+
}
107113
}
108114
}
109115

0 commit comments

Comments
 (0)