diff --git a/Tusker/Views/Attachments/AttachmentView.swift b/Tusker/Views/Attachments/AttachmentView.swift index 29a9c7d7..84386000 100644 --- a/Tusker/Views/Attachments/AttachmentView.swift +++ b/Tusker/Views/Attachments/AttachmentView.swift @@ -12,7 +12,8 @@ import Gifu import AVFoundation protocol AttachmentViewDelegate: class { - func showAttachmentsGallery(startingAt index: Int) + func attachmentViewGallery(startingAt index: Int) -> UIViewController + func attachmentViewPresent(_ vc: UIViewController, animated: Bool) } class AttachmentView: UIImageView, GIFAnimatable { @@ -153,8 +154,15 @@ class AttachmentView: UIImageView, GIFAnimatable { updateImageIfNeeded() } + func showGallery() { + if let delegate = delegate { + let gallery = delegate.attachmentViewGallery(startingAt: index) + delegate.attachmentViewPresent(gallery, animated: true) + } + } + @objc func imagePressed() { - delegate?.showAttachmentsGallery(startingAt: index) + showGallery() } } @@ -162,12 +170,21 @@ class AttachmentView: UIImageView, GIFAnimatable { extension AttachmentView: UIContextMenuInteractionDelegate { func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { return UIContextMenuConfiguration(identifier: nil, previewProvider: { () -> UIViewController? in - return AttachmentPreviewViewController(attachment: self.attachment) + if self.attachment.kind == .image { + return AttachmentPreviewViewController(attachment: self.attachment) + } else { + return self.delegate?.attachmentViewGallery(startingAt: self.index) + } }, actionProvider: nil) } func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { animator.addCompletion { - self.delegate?.showAttachmentsGallery(startingAt: self.index) + animator.preferredCommitStyle = .pop + if let gallery = animator.previewViewController as? GalleryViewController { + self.delegate?.attachmentViewPresent(gallery, animated: true) + } else { + self.showGallery() + } } } } diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index da54fd96..99f372b9 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -366,7 +366,10 @@ class AttachmentsContainerView: UIView { @objc func moreViewTapped() { guard attachments.count > 4 else { return } // the more view shows up in place of the fourth attachemtn view, show tapping it should start at the fourth attachment - delegate?.showAttachmentsGallery(startingAt: 3) + if let delegate = delegate { + let gallery = delegate.attachmentViewGallery(startingAt: 3) + delegate.attachmentViewPresent(gallery, animated: true) + } } } diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 267ad904..663d581d 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -310,10 +310,14 @@ class BaseStatusTableViewCell: UITableViewCell { } extension BaseStatusTableViewCell: AttachmentViewDelegate { - func showAttachmentsGallery(startingAt index: Int) { + func attachmentViewGallery(startingAt index: Int) -> UIViewController { guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") } let sourceViews = status.attachments.map(attachmentsView.getAttachmentView(for:)) - delegate?.showGallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) + return delegate!.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) + } + + func attachmentViewPresent(_ vc: UIViewController, animated: Bool) { + delegate?.show(vc) } }