From e3c480131a635c688500b40a6c948f79266bdf64 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 1 Jun 2024 11:22:19 -0700 Subject: [PATCH] Fix gallery dismiss transition from sheet-presented VC Closes #490 --- .../GalleryDismissAnimationController.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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