Move attachment context menu interaction to AttachmentView
This commit is contained in:
parent
c9c001d403
commit
2e8241d734
|
@ -13,12 +13,10 @@ import Gifu
|
||||||
class AttachmentPreviewViewController: UIViewController {
|
class AttachmentPreviewViewController: UIViewController {
|
||||||
|
|
||||||
let attachment: Attachment
|
let attachment: Attachment
|
||||||
let createGallery: () -> GalleryViewController
|
|
||||||
|
|
||||||
init(attachment: Attachment, createGallery: @escaping () -> GalleryViewController) {
|
init(attachment: Attachment) {
|
||||||
self.attachment = attachment
|
self.attachment = attachment
|
||||||
self.createGallery = createGallery
|
|
||||||
|
|
||||||
super.init(nibName: nil, bundle: nil)
|
super.init(nibName: nil, bundle: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,15 +44,3 @@ class AttachmentPreviewViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension AttachmentPreviewViewController: TuskerNavigationDelegate {
|
|
||||||
var apiController: MastodonController {
|
|
||||||
fatalError("AttachmentPreviewViewController doesn't have a MastodonController")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension AttachmentPreviewViewController: CustomPreviewPresenting {
|
|
||||||
func presentFromPreview(presenter: UIViewController) {
|
|
||||||
presenter.present(createGallery(), animated: true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -55,6 +55,8 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imagePressed)))
|
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imagePressed)))
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
||||||
|
|
||||||
|
addInteraction(UIContextMenuInteraction(delegate: self))
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func preferencesChanged() {
|
@objc func preferencesChanged() {
|
||||||
|
@ -156,3 +158,16 @@ 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)
|
||||||
|
}, actionProvider: nil)
|
||||||
|
}
|
||||||
|
func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
|
||||||
|
animator.addCompletion {
|
||||||
|
self.delegate?.showAttachmentsGallery(startingAt: self.index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -329,21 +329,6 @@ extension BaseStatusTableViewCell: MenuPreviewProvider {
|
||||||
content: { ProfileTableViewController(accountID: self.accountID, mastodonController: mastodonController) },
|
content: { ProfileTableViewController(accountID: self.accountID, mastodonController: mastodonController) },
|
||||||
actions: { self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) }
|
actions: { self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) }
|
||||||
)
|
)
|
||||||
} else if attachmentsView.frame.contains(location) {
|
|
||||||
let attachmentsViewLocation = attachmentsView.convert(location, from: self)
|
|
||||||
if let attachmentView = attachmentsView.attachmentViews.allObjects.first(where: { $0.frame.contains(attachmentsViewLocation) }) {
|
|
||||||
return (
|
|
||||||
content: {
|
|
||||||
let attachments = self.attachmentsView.attachments!
|
|
||||||
let sourceViews = attachments.map(self.attachmentsView.getAttachmentView(for:))
|
|
||||||
let startIndex = sourceViews.firstIndex(of: attachmentView)!
|
|
||||||
return AttachmentPreviewViewController(attachment: attachments[startIndex]) { () -> GalleryViewController in
|
|
||||||
return self.delegate!.gallery(attachments: attachments, sourceViews: sourceViews, startIndex: startIndex)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions: { [] }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return self.getStatusCellPreviewProviders(for: location, sourceViewController: sourceViewController)
|
return self.getStatusCellPreviewProviders(for: location, sourceViewController: sourceViewController)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue