diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift index 6cc15997f7..10f5b5416b 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift @@ -52,15 +52,22 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans appliedSourceToDestTransform = false } - to.view.frame = container.bounds + // 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) let content = itemViewController.takeContent() content.view.translatesAutoresizingMaskIntoConstraints = true content.view.layer.masksToBounds = true - - container.addSubview(to.view) - container.addSubview(from.view) container.addSubview(content.view) content.view.frame = destFrameInContainer