Mask trending link card previews with same corner radius as cells

This commit is contained in:
Shadowfacts 2023-01-22 12:06:51 -05:00
parent 0738683ee3
commit a75862b5cc
1 changed files with 29 additions and 0 deletions

View File

@ -265,6 +265,7 @@ extension SearchViewController: UICollectionViewDelegate {
} }
} }
@available(iOS, obsoleted: 16.0)
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
guard let item = dataSource.itemIdentifier(for: indexPath) else { guard let item = dataSource.itemIdentifier(for: indexPath) else {
return nil return nil
@ -294,6 +295,34 @@ extension SearchViewController: UICollectionViewDelegate {
fatalError("todo") 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 { extension SearchViewController: UICollectionViewDragDelegate {