Browse Source

improvements

marinofaggiana 4 năm trước cách đây
mục cha
commit
8135e60625

+ 13 - 2
iOSClient/Main/Colleaction Common/NCCollectionViewCommon.swift

@@ -1050,8 +1050,9 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
         
         guard let metadata = dataSource.cellForItemAt(indexPath: indexPath) else { return nil }
         metadataTouch = metadata
-        
-        return UIContextMenuConfiguration(identifier: nil, previewProvider: {
+        let identifier = indexPath as NSCopying
+
+        return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
             
             return NCViewerProviderContextMenu(metadata: metadata)
             
@@ -1119,6 +1120,16 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
             }
         })
     }
+    
+    @available(iOS 13.0, *)
+    func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
+        animator.addCompletion {
+
+            if let indexPath = configuration.identifier as? IndexPath {
+                self.collectionView(collectionView, didSelectItemAt: indexPath)
+            }
+        }
+    }
 }
 
 extension NCCollectionViewCommon: UICollectionViewDataSource {

+ 12 - 1
iOSClient/Media/NCMedia.swift

@@ -498,8 +498,9 @@ extension NCMedia: UICollectionViewDelegate {
     func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
         
         let metadata = metadatas[indexPath.row]
+        let identifier = indexPath as NSCopying
 
-        return UIContextMenuConfiguration(identifier: nil, previewProvider: {
+        return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
             
             return NCViewerProviderContextMenu(metadata: metadata)
             
@@ -541,6 +542,16 @@ extension NCMedia: UICollectionViewDelegate {
             return UIMenu(title: "", children: [save, openIn, moveCopy, delete])
         })
     }
+    
+    @available(iOS 13.0, *)
+    func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
+        animator.addCompletion {
+
+            if let indexPath = configuration.identifier as? IndexPath {
+                self.collectionView(collectionView, didSelectItemAt: indexPath)
+            }
+        }
+    }
 }
 
 extension NCMedia: UICollectionViewDataSourcePrefetching {