From ba1300b1b7a03ce031dd581cd0b671592410920f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 8 Oct 2022 14:59:50 -0400 Subject: [PATCH] Re-add status cell dragging --- .../Timeline/TimelineViewController.swift | 9 +++++++-- .../TimelineStatusCollectionViewCell.swift | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index d5fa67401e..fa453d0bb3 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -68,9 +68,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } let layout = UICollectionViewCompositionalLayout.list(using: config) view = UICollectionView(frame: .zero, collectionViewLayout: layout) - // TODO: delegates collectionView.delegate = self - // collectionView.dragDelegate = self + collectionView.dragDelegate = self registerTimelineLikeCells() collectionView.register(PublicTimelineDescriptionCollectionViewCell.self, forCellWithReuseIdentifier: "publicTimelineDescription") @@ -344,6 +343,12 @@ extension TimelineViewController: UICollectionViewDelegate { } } +extension TimelineViewController: UICollectionViewDragDelegate { + func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] { + (collectionView.cellForItem(at: indexPath) as? TimelineStatusCollectionViewCell)?.dragItemsForBeginning(session: session) ?? [] + } +} + extension TimelineViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } diff --git a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift index f5ca1dadaa..06147d9e12 100644 --- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift @@ -168,7 +168,6 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti reblogButton.widthAnchor.constraint(equalTo: replyButton.widthAnchor), moreButton.widthAnchor.constraint(equalTo: replyButton.widthAnchor), - // TODO: gah placeholderReplyButtonLeadingConstraint, replyButton.topAnchor.constraint(equalTo: $0.topAnchor), replyButton.bottomAnchor.constraint(equalTo: $0.bottomAnchor), @@ -564,6 +563,21 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti return UISwipeActionsConfiguration(actions: actions) } + func dragItemsForBeginning(session: UIDragSession) -> [UIDragItem] { + // the poll options view is tracking while the user is dragging between options + // while that's happening, don't initiate a drag + guard !pollView.isTracking, + let status = mastodonController.persistentContainer.status(for: statusID), + let accountID = mastodonController.accountInfo?.id else { + return [] + } + let provider = NSItemProvider(object: status.url! as NSURL) + let activity = UserActivityManager.showConversationActivity(mainStatusID: status.id, accountID: accountID) + activity.displaysAuxiliaryScene = true + provider.registerObject(activity, visibility: .all) + return [UIDragItem(itemProvider: provider)] + } + } extension TimelineStatusCollectionViewCell: UIContextMenuInteractionDelegate {