Fix crash tapping attachments on instance public timelines

This commit is contained in:
Shadowfacts 2020-09-13 13:55:33 -04:00
parent 7999ecafd0
commit b94bfca406
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 9 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import Gifu
import AVFoundation
protocol AttachmentViewDelegate: class {
func attachmentViewGallery(startingAt index: Int) -> UIViewController
func attachmentViewGallery(startingAt index: Int) -> UIViewController?
func attachmentViewPresent(_ vc: UIViewController, animated: Bool)
}
@ -230,8 +230,8 @@ class AttachmentView: UIImageView, GIFAnimatable {
}
func showGallery() {
if let delegate = delegate {
let gallery = delegate.attachmentViewGallery(startingAt: index)
if let delegate = delegate,
let gallery = delegate.attachmentViewGallery(startingAt: index) {
delegate.attachmentViewPresent(gallery, animated: true)
}
}

View File

@ -384,8 +384,8 @@ 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
if let delegate = delegate {
let gallery = delegate.attachmentViewGallery(startingAt: 3)
if let delegate = delegate,
let gallery = delegate.attachmentViewGallery(startingAt: 3) {
delegate.attachmentViewPresent(gallery, animated: true)
}
}

View File

@ -366,10 +366,11 @@ class BaseStatusTableViewCell: UITableViewCell {
}
extension BaseStatusTableViewCell: AttachmentViewDelegate {
func attachmentViewGallery(startingAt index: Int) -> UIViewController {
guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
func attachmentViewGallery(startingAt index: Int) -> UIViewController? {
guard let delegate = delegate,
let status = mastodonController.persistentContainer.status(for: statusID) else { return nil }
let sourceViews = status.attachments.map(attachmentsView.getAttachmentView(for:))
return delegate!.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index)
return delegate.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index)
}
func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {