From 0dcb67c44eb4d6d8e513bb07a3b73b4c3df666be Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 23 Nov 2024 10:59:51 -0500 Subject: [PATCH] Fix gallery dismiss animation not working when the window's origin is not the screen origin sourceView is inside to.view, so to.view needs to be added as a subview of container before we call convert(_:from:) --- .../GalleryDismissAnimationController.swift | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift index df960cb13..6fb3fe51c 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift @@ -36,6 +36,17 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans } let container = transitionContext.containerView + + // Moving `to.view` to the container is necessary when the presenting VC (i.e., `to`) + // is in the window's root presentation. + // But it breaks when the gallery is presented from a sheet-presented VC--in which case + // `to.view` is already in the view hierarchy at this point; and adding it to the + // container causees it to be removed when the transition completes. + if to.view.superview == nil { + to.view.frame = container.bounds + container.addSubview(to.view) + } + let sourceFrameInContainer = container.convert(sourceView.bounds, from: sourceView) let destFrameInContainer = container.convert(itemViewController.content.view.bounds, from: itemViewController.content.view) @@ -52,16 +63,6 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans appliedSourceToDestTransform = false } - // Moving `to.view` to the container is necessary when the presenting VC (i.e., `to`) - // is in the window's root presentation. - // But it breaks when the gallery is presented from a sheet-presented VC--in which case - // `to.view` is already in the view hierarchy at this point; and adding it to the - // container causees it to be removed when the transition completes. - if to.view.superview == nil { - to.view.frame = container.bounds - container.addSubview(to.view) - } - from.view.frame = container.bounds container.addSubview(from.view)