forked from shadowfacts/Tusker
Fix previewing video/audio attachments
This commit is contained in:
parent
bef3388fe8
commit
d9517047d7
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue