From 0a8d50cc27dc91c321f7962d7ab3a19babe607df Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 20 Nov 2022 15:48:29 -0500 Subject: [PATCH] Fix double-tap to zoom in gallery not working Closes #256 --- .../Screens/Large Image/LargeImageContentView.swift | 11 +++++------ .../Large Image/LargeImageViewController.swift | 6 +++++- .../Large Image/LoadingLargeImageViewController.swift | 6 +++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Tusker/Screens/Large Image/LargeImageContentView.swift b/Tusker/Screens/Large Image/LargeImageContentView.swift index 7a3a6875..b995755a 100644 --- a/Tusker/Screens/Large Image/LargeImageContentView.swift +++ b/Tusker/Screens/Large Image/LargeImageContentView.swift @@ -14,6 +14,7 @@ import VisionKit protocol LargeImageContentView: UIView { var animationImage: UIImage? { get } var activityItemsForSharing: [Any] { get } + var owner: LargeImageViewController? { get set } func setControlsVisible(_ controlsVisible: Bool) func grayscaleStateChanged() } @@ -29,17 +30,14 @@ class LargeImageImageContentView: UIImageView, LargeImageContentView { #endif var animationImage: UIImage? { image! } - var activityItemsForSharing: [Any] { [image!] } + weak var owner: LargeImageViewController? private var sourceData: Data? - private weak var owner: UIViewController? - init(image: UIImage, owner: UIViewController?) { - self.owner = owner - + init(image: UIImage) { super.init(image: image) contentMode = .scaleAspectFit @@ -109,11 +107,11 @@ extension LargeImageImageContentView: ImageAnalysisInteractionDelegate { class LargeImageGifContentView: GIFImageView, LargeImageContentView { var animationImage: UIImage? { image } - var activityItemsForSharing: [Any] { // todo: should gifs share the data? [image].compactMap { $0 } } + weak var owner: LargeImageViewController? init(gifController: GIFController) { super.init(image: gifController.lastFrame?.image) @@ -144,6 +142,7 @@ class LargeImageGifvContentView: GifvAttachmentView, LargeImageContentView { // some SO posts indicate that just sharing a URL to the video should work, but that may need to be a local URL? [] } + weak var owner: LargeImageViewController? private let asset: AVURLAsset diff --git a/Tusker/Screens/Large Image/LargeImageViewController.swift b/Tusker/Screens/Large Image/LargeImageViewController.swift index c6672ca4..1397a069 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.swift +++ b/Tusker/Screens/Large Image/LargeImageViewController.swift @@ -103,15 +103,19 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma dismissInteractionController = LargeImageInteractionController(viewController: self) } - view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(scrollViewPressed(_:)))) + let singleTap = UITapGestureRecognizer(target: self, action: #selector(scrollViewPressed(_:))) let doubleTap = UITapGestureRecognizer(target: self, action: #selector(scrollViewDoubleTapped(_:))) doubleTap.numberOfTapsRequired = 2 + // this requirement is needed to make sure the double tap is ever recognized + singleTap.require(toFail: doubleTap) + view.addGestureRecognizer(singleTap) view.addGestureRecognizer(doubleTap) NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil) } private func setupContentView() { + contentView.owner = self contentView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(contentView) contentViewLeadingConstraint = contentView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor) diff --git a/Tusker/Screens/Large Image/LoadingLargeImageViewController.swift b/Tusker/Screens/Large Image/LoadingLargeImageViewController.swift index 1b0c2e68..487889b6 100644 --- a/Tusker/Screens/Large Image/LoadingLargeImageViewController.swift +++ b/Tusker/Screens/Large Image/LoadingLargeImageViewController.swift @@ -138,9 +138,9 @@ class LoadingLargeImageViewController: UIViewController, LargeImageAnimatableVie content = LargeImageGifContentView(gifController: gifController) } else { if let transformedImage = ImageGrayscalifier.convertIfNecessary(url: url, image: image) { - content = LargeImageImageContentView(image: transformedImage, owner: self) + content = LargeImageImageContentView(image: transformedImage) } else { - content = LargeImageImageContentView(image: image, owner: self) + content = LargeImageImageContentView(image: image) } } @@ -167,7 +167,7 @@ class LoadingLargeImageViewController: UIViewController, LargeImageAnimatableVie let grayscale = ImageGrayscalifier.convert(url: nil, cgImage: source) { image = grayscale } - setContent(LargeImageImageContentView(image: image, owner: self)) + setContent(LargeImageImageContentView(image: image)) } }