From f3cf2dd8ec685dd5b007b0337906b87f3ed3a6d9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 31 Mar 2024 12:35:10 -0400 Subject: [PATCH] Catalyst: Fix gallery presentation animation not working --- .../GalleryVC/GalleryItemViewController.swift | 2 +- .../GalleryPresentationAnimationController.swift | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift index 478c9d5696..47710da9d8 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryItemViewController.swift @@ -293,7 +293,7 @@ class GalleryItemViewController: UIViewController { setNeedsUpdateOfHomeIndicatorAutoHidden() } - private func updateZoomScale(resetZoom: Bool) { + func updateZoomScale(resetZoom: Bool) { guard scrollAndZoomEnabled else { scrollView.maximumZoomScale = 1 scrollView.minimumZoomScale = 1 diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift index 95ec8b284e..b3e461cf91 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift @@ -38,7 +38,12 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated } let container = transitionContext.containerView - itemViewController.view.layoutIfNeeded() + to.view.frame = container.bounds + container.addSubview(to.view) + + container.layoutIfNeeded() + // Make sure the zoom scale is updated before getting the content view frame, since it needs to take into account the correct transform. + itemViewController.updateZoomScale(resetZoom: true) let sourceFrameInContainer = container.convert(sourceView.bounds, from: sourceView) let destFrameInContainer = container.convert(itemViewController.content.view.bounds, from: itemViewController.content.view) @@ -67,9 +72,8 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated dimmingView.frame = container.bounds dimmingView.layer.opacity = 0 - container.addSubview(dimmingView) - container.addSubview(content.view) - container.addSubview(to.view) + container.insertSubview(content.view, belowSubview: to.view) + container.insertSubview(dimmingView, belowSubview: content.view) to.view.backgroundColor = nil to.view.layer.opacity = 0