diff --git a/Tusker/Screens/Search/SearchViewController.swift b/Tusker/Screens/Search/SearchViewController.swift index e8239cb5..b9655ad0 100644 --- a/Tusker/Screens/Search/SearchViewController.swift +++ b/Tusker/Screens/Search/SearchViewController.swift @@ -265,6 +265,7 @@ extension SearchViewController: UICollectionViewDelegate { } } + @available(iOS, obsoleted: 16.0) func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { guard let item = dataSource.itemIdentifier(for: indexPath) else { return nil @@ -294,6 +295,34 @@ extension SearchViewController: UICollectionViewDelegate { fatalError("todo") } } + + // implementing the highlightPreviewForItemAt method seems to prevent the old, single IndexPath variant of this method from being called on iOS 16 + @available(iOS 16.0, *) + func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? { + guard indexPaths.count == 1 else { + return nil + } + return self.collectionView(collectionView, contextMenuConfigurationForItemAt: indexPaths[0], point: point) + } + + func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, highlightPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? { + switch dataSource.itemIdentifier(for: indexPath) { + case .link(_): + guard let cell = collectionView.cellForItem(at: indexPath) else { + return nil + } + let params = UIPreviewParameters() + params.visiblePath = UIBezierPath(roundedRect: cell.bounds, cornerRadius: cell.contentView.layer.cornerRadius) + return UITargetedPreview(view: cell, parameters: params) + + default: + return nil + } + } + + func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, dismissalPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? { + return self.collectionView(collectionView, contextMenuConfiguration: configuration, highlightPreviewForItemAt: indexPath) + } } extension SearchViewController: UICollectionViewDragDelegate {