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)