Jelajahi Sumber

Fix a11y collection cell select

- only enable actions if not in edit mode

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 2 tahun lalu
induk
melakukan
45c9b65feb

+ 4 - 2
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1509,7 +1509,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 cell.imageStatus.image = NCBrandColor.cacheImages.livePhoto
                 a11yValues.append(NSLocalizedString("_upload_mov_livephoto_", comment: ""))
             }
-            cell.accessibilityValue = a11yValues.joined(separator: ", ")
 
             // E2EE
             if metadata.e2eEncrypted || isEncryptedFolder {
@@ -1530,12 +1529,14 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 cell.selectMode(true)
                 if selectOcId.contains(metadata.ocId) {
                     cell.selected(true)
+                    a11yValues.append(NSLocalizedString("_selected_", comment: ""))
                 } else {
                     cell.selected(false)
                 }
             } else {
                 cell.selectMode(false)
             }
+            cell.accessibilityValue = a11yValues.joined(separator: ", ")
 
             // Disable Share Button
             if appDelegate.disableSharesView {
@@ -1644,19 +1645,20 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 cell.imageStatus.image = NCBrandColor.cacheImages.livePhoto
                 a11yValues.append(NSLocalizedString("_upload_mov_livephoto_", comment: ""))
             }
-            cell.accessibilityValue = a11yValues.joined(separator: ", ")
 
             // Edit mode
             if isEditMode {
                 cell.selectMode(true)
                 if selectOcId.contains(metadata.ocId) {
                     cell.selected(true)
+                    a11yValues.append(NSLocalizedString("_selected_", comment: ""))
                 } else {
                     cell.selected(false)
                 }
             } else {
                 cell.selectMode(false)
             }
+            cell.accessibilityValue = a11yValues.joined(separator: ", ")
 
             return cell
         }

+ 11 - 5
iOSClient/Main/Collection Common/NCGridCell.swift

@@ -122,11 +122,9 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
         delegate?.longPressGridItem(with: objectId, gestureRecognizer: gestureRecognizer)
     }
 
-    func setButtonMore(named: String, image: UIImage) {
-        namedButtonMore = named
-        buttonMore.setImage(image, for: .normal)
-        let moreName = named == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_"
-
+    fileprivate func setA11yActions() {
+        let moreName = namedButtonMore == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_"
+        
         self.accessibilityCustomActions = [
             UIAccessibilityCustomAction(
                 name: NSLocalizedString(moreName, comment: ""),
@@ -134,6 +132,12 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
                 selector: #selector(touchUpInsideMore))
         ]
     }
+    
+    func setButtonMore(named: String, image: UIImage) {
+        namedButtonMore = named
+        buttonMore.setImage(image, for: .normal)
+        setA11yActions()
+    }
 
     func hideButtonMore(_ status: Bool) {
         buttonMore.isHidden = status
@@ -142,9 +146,11 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     func selectMode(_ status: Bool) {
         if status {
             imageSelect.isHidden = false
+            accessibilityCustomActions = nil
         } else {
             imageSelect.isHidden = true
             imageVisualEffect.isHidden = true
+            setA11yActions()
         }
     }
 

+ 11 - 6
iOSClient/Main/Collection Common/NCListCell.swift

@@ -130,12 +130,8 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
         delegate?.longPressListItem(with: objectId, gestureRecognizer: gestureRecognizer)
     }
 
-    func setButtonMore(named: String, image: UIImage) {
-        namedButtonMore = named
-        imageMore.image = image
-
-        let moreName = named == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_"
-
+    fileprivate func setA11yActions() {
+        let moreName = namedButtonMore == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_"
         self.accessibilityCustomActions = [
             UIAccessibilityCustomAction(
                 name: NSLocalizedString("_share_", comment: ""),
@@ -147,6 +143,13 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
                 selector: #selector(touchUpInsideMore))
         ]
     }
+    
+    func setButtonMore(named: String, image: UIImage) {
+        namedButtonMore = named
+        imageMore.image = image
+
+        setA11yActions()
+    }
 
     func hideButtonMore(_ status: Bool) {
         imageMore.isHidden = status
@@ -162,10 +165,12 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
         if status {
             imageItemLeftConstraint.constant = 45
             imageSelect.isHidden = false
+            accessibilityCustomActions = nil
         } else {
             imageItemLeftConstraint.constant = 10
             imageSelect.isHidden = true
             backgroundView = nil
+            setA11yActions()
         }
     }