Don't use snapshot for gallery present/dismiss transition of non-static content
This commit is contained in:
parent
a5066140fd
commit
dc01804359
|
@ -82,8 +82,8 @@ public class FallbackGalleryNavigationController: UINavigationController, Galler
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public var canAnimateFromSourceView: Bool {
|
public var presentationAnimation: GalleryContentPresentationAnimation {
|
||||||
false
|
.fade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,10 @@ open class ImageGalleryContentViewController: UIViewController, GalleryContentVi
|
||||||
return [image]
|
return [image]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var presentationAnimation: GalleryContentPresentationAnimation {
|
||||||
|
gifController != nil ? .fromSourceViewWithoutSnapshot : .fromSourceView
|
||||||
|
}
|
||||||
|
|
||||||
public func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) {
|
public func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) {
|
||||||
if #available(iOS 16.0, macCatalyst 17.0, *),
|
if #available(iOS 16.0, macCatalyst 17.0, *),
|
||||||
let analysisInteraction {
|
let analysisInteraction {
|
||||||
|
|
|
@ -27,8 +27,8 @@ public class LoadingGalleryContentViewController: UIViewController, GalleryConte
|
||||||
wrapped?.caption ?? fallbackCaption
|
wrapped?.caption ?? fallbackCaption
|
||||||
}
|
}
|
||||||
|
|
||||||
public var canAnimateFromSourceView: Bool {
|
public var presentationAnimation: GalleryContentPresentationAnimation {
|
||||||
wrapped?.canAnimateFromSourceView ?? true
|
wrapped?.presentationAnimation ?? .fade
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(caption: String?, provider: @escaping () async -> (any GalleryContentViewController)?) {
|
public init(caption: String?, provider: @escaping () async -> (any GalleryContentViewController)?) {
|
||||||
|
|
|
@ -157,6 +157,10 @@ open class VideoGalleryContentViewController: UIViewController, GalleryContentVi
|
||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var presentationAnimation: GalleryContentPresentationAnimation {
|
||||||
|
.fromSourceViewWithoutSnapshot
|
||||||
|
}
|
||||||
|
|
||||||
private lazy var overlayVC = VideoOverlayViewController(player: player)
|
private lazy var overlayVC = VideoOverlayViewController(player: player)
|
||||||
public var contentOverlayAccessoryViewController: UIViewController? {
|
public var contentOverlayAccessoryViewController: UIViewController? {
|
||||||
overlayVC
|
overlayVC
|
||||||
|
|
|
@ -15,7 +15,7 @@ public protocol GalleryContentViewController: UIViewController {
|
||||||
var caption: String? { get }
|
var caption: String? { get }
|
||||||
var contentOverlayAccessoryViewController: UIViewController? { get }
|
var contentOverlayAccessoryViewController: UIViewController? { get }
|
||||||
var bottomControlsAccessoryViewController: UIViewController? { get }
|
var bottomControlsAccessoryViewController: UIViewController? { get }
|
||||||
var canAnimateFromSourceView: Bool { get }
|
var presentationAnimation: GalleryContentPresentationAnimation { get }
|
||||||
|
|
||||||
func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool)
|
func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool)
|
||||||
func galleryContentDidAppear()
|
func galleryContentDidAppear()
|
||||||
|
@ -31,8 +31,8 @@ public extension GalleryContentViewController {
|
||||||
nil
|
nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var canAnimateFromSourceView: Bool {
|
var presentationAnimation: GalleryContentPresentationAnimation {
|
||||||
true
|
.fromSourceView
|
||||||
}
|
}
|
||||||
|
|
||||||
func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) {
|
func setControlsVisible(_ visible: Bool, animated: Bool, dueToUserInteraction: Bool) {
|
||||||
|
@ -44,3 +44,9 @@ public extension GalleryContentViewController {
|
||||||
func galleryContentWillDisappear() {
|
func galleryContentWillDisappear() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum GalleryContentPresentationAnimation {
|
||||||
|
case fade
|
||||||
|
case fromSourceView
|
||||||
|
case fromSourceViewWithoutSnapshot
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans
|
||||||
|
|
||||||
let itemViewController = from.currentItemViewController
|
let itemViewController = from.currentItemViewController
|
||||||
|
|
||||||
if !itemViewController.content.canAnimateFromSourceView || (UIAccessibility.prefersCrossFadeTransitions && interactiveVelocity == nil) {
|
if itemViewController.content.presentationAnimation == .fade || (UIAccessibility.prefersCrossFadeTransitions && interactiveVelocity == nil) {
|
||||||
animateCrossFadeTransition(using: transitionContext)
|
animateCrossFadeTransition(using: transitionContext)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,11 @@ class GalleryDismissAnimationController: NSObject, UIViewControllerAnimatedTrans
|
||||||
container.addSubview(to.view)
|
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 {
|
if let sourceSnapshot {
|
||||||
let snapshotContainer = sourceView.ancestorForInsertingSnapshot
|
let snapshotContainer = sourceView.ancestorForInsertingSnapshot
|
||||||
snapshotContainer.addSubview(sourceSnapshot)
|
snapshotContainer.addSubview(sourceSnapshot)
|
||||||
|
|
|
@ -25,7 +25,7 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
|
||||||
|
|
||||||
let itemViewController = to.currentItemViewController
|
let itemViewController = to.currentItemViewController
|
||||||
|
|
||||||
if !itemViewController.content.canAnimateFromSourceView || UIAccessibility.prefersCrossFadeTransitions {
|
if itemViewController.content.presentationAnimation == .fade || UIAccessibility.prefersCrossFadeTransitions {
|
||||||
animateCrossFadeTransition(using: transitionContext)
|
animateCrossFadeTransition(using: transitionContext)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,11 @@ class GalleryPresentationAnimationController: NSObject, UIViewControllerAnimated
|
||||||
// Try to effectively "fade out" anything that's on top of the source view.
|
// 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,
|
// The 0.1 duration makes this happen faster than the rest of the animation,
|
||||||
// and so less noticeable.
|
// 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 {
|
if let sourceSnapshot {
|
||||||
let snapshotContainer = sourceView.ancestorForInsertingSnapshot
|
let snapshotContainer = sourceView.ancestorForInsertingSnapshot
|
||||||
snapshotContainer.addSubview(sourceSnapshot)
|
snapshotContainer.addSubview(sourceSnapshot)
|
||||||
|
|
|
@ -69,4 +69,8 @@ class GifvGalleryContentViewController: UIViewController, GalleryContentViewCont
|
||||||
[VideoActivityItemSource(asset: controller.item.asset, url: url)]
|
[VideoActivityItemSource(asset: controller.item.asset, url: url)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var presentationAnimation: GalleryContentPresentationAnimation {
|
||||||
|
.fromSourceViewWithoutSnapshot
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue