diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index d5fa6740..fa453d0b 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 f5ca1dad..06147d9e 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 {