From a442197adf3f4aca8ebb822b0cb17d0746ea6096 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 24 Nov 2024 19:19:57 -0500 Subject: [PATCH] Improve gallery dismiss transition when source view is relatively small compared to content See #520 --- .../GalleryVC/GalleryDismissAnimationController.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift index 11fb9866..ab985eb2 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift @@ -47,8 +47,6 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans container.addSubview(to.view) } - // This trick does not work as well here as it does for presentation, seemingly - // because the delayFactor:0.9 still results in the snapshot fading out too quickly :/ let sourceSnapshot = sourceView.snapshotView(afterScreenUpdates: false) if let sourceSnapshot { let snapshotContainer = sourceView.ancestorForInsertingSnapshot @@ -160,16 +158,21 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans contentContainer.frame = sourceFrameInContainer content.view.frame = sourceSizeWithDestAspectRatioCenteredInContentContainer - content.view.layer.opacity = 0 itemViewController.setControlsVisible(false, animated: false, dueToUserInteraction: false) } + // Delay fading out the content because if it's still big while it's semi-transparent, + // seeing the stuff behind it looks odd. + animator.addAnimations({ + content.view.layer.opacity = 0 + }, delayFactor: 0.35) + if let sourceSnapshot { animator.addAnimations({ self.sourceView.layer.opacity = 1 sourceSnapshot.layer.opacity = 0 - }, delayFactor: 0.9) + }, delayFactor: 0.5) } animator.addCompletion { _ in