From 164a8e26c4b3ece5321217de3a4c4b7997899df4 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 8 Oct 2022 19:10:21 -0400 Subject: [PATCH] Fix not being able to press attachments in new status cells --- .../Status/StatusCollectionViewCell.swift | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index 107b0101..2a95544f 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -16,7 +16,7 @@ protocol StatusCollectionViewCellDelegate: AnyObject, TuskerNavigationDelegate, } @MainActor -protocol StatusCollectionViewCell: UICollectionViewCell { +protocol StatusCollectionViewCell: UICollectionViewCell, AttachmentViewDelegate { // MARK: Subviews var avatarImageView: CachedImageView { get } var displayNameLabel: EmojiLabel { get } @@ -82,8 +82,9 @@ extension StatusCollectionViewCell { updateAccountUI(account: status.account) updateUIForPreferences(status: status) - contentContainer.contentTextView.setTextFrom(status: status) + contentContainer.contentTextView.setTextFrom(status: status) + contentContainer.attachmentsView.delegate = self contentContainer.cardView.updateUI(status: status) contentContainer.cardView.isHidden = status.card == nil contentContainer.cardView.navigationDelegate = delegate @@ -224,6 +225,22 @@ extension StatusCollectionViewCell { } } +extension StatusCollectionViewCell { + func attachmentViewGallery(startingAt index: Int) -> GalleryViewController? { + guard let delegate = delegate, + let status = mastodonController.persistentContainer.status(for: statusID) else { return nil } + let sourceViews = status.attachments.map(contentContainer.attachmentsView.getAttachmentView(for:)) + let gallery = delegate.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index) + // TODO: PiP +// gallery.avPlayerViewControllerDelegate = self + return gallery + } + + func attachmentViewPresent(_ vc: UIViewController, animated: Bool) { + delegate?.present(vc, animated: animated) + } +} + extension StatusCollectionViewCell { func contextMenuConfigurationForAccount(sourceView: UIView) -> UIContextMenuConfiguration? { return UIContextMenuConfiguration() {