From dc018043596e25a5dec102c07a61891828e8c96e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 25 Nov 2024 21:04:46 -0500 Subject: [PATCH] Don't use snapshot for gallery present/dismiss transition of non-static content --- .../FallbackGalleryContentViewController.swift | 4 ++-- .../Content/ImageGalleryContentViewController.swift | 4 ++++ .../LoadingGalleryContentViewController.swift | 4 ++-- .../Content/VideoGalleryContentViewController.swift | 4 ++++ .../GalleryVC/GalleryContentViewController.swift | 12 +++++++++--- .../GalleryDismissAnimationController.swift | 8 ++++++-- .../GalleryPresentationAnimationController.swift | 8 ++++++-- .../Gallery/GifvGalleryContentViewController.swift | 4 ++++ 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Packages/GalleryVC/Sources/GalleryVC/Content/FallbackGalleryContentViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/Content/FallbackGalleryContentViewController.swift index 12d28da88..81fd0ebb7 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/Content/FallbackGalleryContentViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/Content/FallbackGalleryContentViewController.swift @@ -82,8 +82,8 @@ public class FallbackGalleryNavigationController: UINavigationController, Galler nil } - public var canAnimateFromSourceView: Bool { - false + public var presentationAnimation: GalleryContentPresentationAnimation { + .fade } } diff --git a/Packages/GalleryVC/Sources/GalleryVC/Content/ImageGalleryContentViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/Content/ImageGalleryContentViewController.swift index 37191dbcb..e24895af5 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/Content/ImageGalleryContentViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/Content/ImageGalleryContentViewController.swift @@ -97,6 +97,10 @@ open class ImageGalleryContentViewController: UIViewController, GalleryContentVi return [image] } + public var presentationAnimation: GalleryContentPresentationAnimation { + gifController != nil ? .fromSourceViewWithoutSnapshot : .fromSourceView + } + public func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) { if #available(iOS 16.0, macCatalyst 17.0, *), let analysisInteraction { diff --git a/Packages/GalleryVC/Sources/GalleryVC/Content/LoadingGalleryContentViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/Content/LoadingGalleryContentViewController.swift index 48509d645..82751d5af 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/Content/LoadingGalleryContentViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/Content/LoadingGalleryContentViewController.swift @@ -27,8 +27,8 @@ public class LoadingGalleryContentViewController: UIViewController, GalleryConte wrapped?.caption ?? fallbackCaption } - public var canAnimateFromSourceView: Bool { - wrapped?.canAnimateFromSourceView ?? true + public var presentationAnimation: GalleryContentPresentationAnimation { + wrapped?.presentationAnimation ?? .fade } public init(caption: String?, provider: @escaping () async -> (any GalleryContentViewController)?) { diff --git a/Packages/GalleryVC/Sources/GalleryVC/Content/VideoGalleryContentViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/Content/VideoGalleryContentViewController.swift index 4afa609d3..bcc857327 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/Content/VideoGalleryContentViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/Content/VideoGalleryContentViewController.swift @@ -157,6 +157,10 @@ open class VideoGalleryContentViewController: UIViewController, GalleryContentVi [] } + public var presentationAnimation: GalleryContentPresentationAnimation { + .fromSourceViewWithoutSnapshot + } + private lazy var overlayVC = VideoOverlayViewController(player: player) public var contentOverlayAccessoryViewController: UIViewController? { overlayVC diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryContentViewController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryContentViewController.swift index e2bbbfa58..7485d19b6 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryContentViewController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryContentViewController.swift @@ -15,7 +15,7 @@ public protocol GalleryContentViewController: UIViewController { var caption: String? { get } var contentOverlayAccessoryViewController: UIViewController? { get } var bottomControlsAccessoryViewController: UIViewController? { get } - var canAnimateFromSourceView: Bool { get } + var presentationAnimation: GalleryContentPresentationAnimation { get } func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) func galleryContentDidAppear() @@ -31,8 +31,8 @@ public extension GalleryContentViewController { nil } - var canAnimateFromSourceView: Bool { - true + var presentationAnimation: GalleryContentPresentationAnimation { + .fromSourceView } func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) { @@ -44,3 +44,9 @@ public extension GalleryContentViewController { func galleryContentWillDisappear() { } } + +public enum GalleryContentPresentationAnimation { + case fade + case fromSourceView + case fromSourceViewWithoutSnapshot +} diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift index b26ad4b54..c14ef0413 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissAnimationController.swift @@ -30,7 +30,7 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans let itemViewController = from.currentItemViewController - if !itemViewController.content.canAnimateFromSourceView || (UIAccessibility.prefersCrossFadeTransitions && interactiveVelocity == nil) { + if itemViewController.content.presentationAnimation == .fade || (UIAccessibility.prefersCrossFadeTransitions && interactiveVelocity == nil) { animateCrossFadeTransition(using: transitionContext) return } @@ -47,7 +47,11 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans container.addSubview(to.view) } - let sourceSnapshot = sourceView.snapshotView(afterScreenUpdates: false) + let sourceSnapshot: UIView? = if itemViewController.content.presentationAnimation == .fromSourceViewWithoutSnapshot { + nil + } else { + sourceView.snapshotView(afterScreenUpdates: false) + } if let sourceSnapshot { let snapshotContainer = sourceView.ancestorForInsertingSnapshot snapshotContainer.addSubview(sourceSnapshot) diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift index 8b7143e1d..e508a6f8f 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryPresentationAnimationController.swift @@ -25,7 +25,7 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated let itemViewController = to.currentItemViewController - if !itemViewController.content.canAnimateFromSourceView || UIAccessibility.prefersCrossFadeTransitions { + if itemViewController.content.presentationAnimation == .fade || UIAccessibility.prefersCrossFadeTransitions { animateCrossFadeTransition(using: transitionContext) return } @@ -33,7 +33,11 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated // Try to effectively "fade out" anything that's on top of the source view. // The 0.1 duration makes this happen faster than the rest of the animation, // and so less noticeable. - let sourceSnapshot = sourceView.snapshotView(afterScreenUpdates: false) + let sourceSnapshot: UIView? = if itemViewController.content.presentationAnimation == .fromSourceViewWithoutSnapshot { + nil + } else { + sourceView.snapshotView(afterScreenUpdates: false) + } if let sourceSnapshot { let snapshotContainer = sourceView.ancestorForInsertingSnapshot snapshotContainer.addSubview(sourceSnapshot) diff --git a/Tusker/Screens/Gallery/GifvGalleryContentViewController.swift b/Tusker/Screens/Gallery/GifvGalleryContentViewController.swift index a5d73a1bf..efc91b970 100644 --- a/Tusker/Screens/Gallery/GifvGalleryContentViewController.swift +++ b/Tusker/Screens/Gallery/GifvGalleryContentViewController.swift @@ -69,4 +69,8 @@ class GifvGalleryContentViewController: UIViewController, GalleryContentViewCont [VideoActivityItemSource(asset: controller.item.asset, url: url)] } + var presentationAnimation: GalleryContentPresentationAnimation { + .fromSourceViewWithoutSnapshot + } + }