Selaa lähdekoodia

MediaCategoryViewController: Fix sort shortcut inside collections

While using the long press shortcut inside a media collection, we
directly send the sort action without filtering the gesture.

This lead to quick succession of sort that couldn't be used.

This regroups the behaviour from the shortcut outside of collections.
Soomin Lee 5 vuotta sitten
vanhempi
commit
4d6476ae80

+ 10 - 1
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -465,7 +465,7 @@ extension MediaCategoryViewController {
                              for: .touchUpInside)
         sortButton
             .addGestureRecognizer(UILongPressGestureRecognizer(target: self,
-                                                               action: #selector(handleSortShortcut)))
+                                                               action: #selector(handleSortLongPress(sender:))))
 
         sortButton.tintColor = PresentationTheme.current.colors.orangeUI
         sortButton.accessibilityLabel = NSLocalizedString("BUTTON_SORT", comment: "")
@@ -501,6 +501,15 @@ extension MediaCategoryViewController {
         }
     }
 
+    @objc func handleSortLongPress(sender: UILongPressGestureRecognizer) {
+        if sender.state == .began {
+            if #available(iOS 10.0, *) {
+                UIImpactFeedbackGenerator(style: .medium).impactOccurred()
+            }
+            handleSortShortcut()
+        }
+    }
+
     @objc func handleSortShortcut() {
         model.sort(by: model.sortModel.currentSort, desc: !model.sortModel.desc)
     }

+ 2 - 7
Sources/MediaViewControllers/MediaViewController.swift

@@ -168,13 +168,8 @@ extension MediaViewController {
     }
 
     @objc func handleSortShortcut(sender: UILongPressGestureRecognizer) {
-        if sender.state == .began {
-            if #available(iOS 10.0, *) {
-                UIImpactFeedbackGenerator(style: .light).impactOccurred()
-            }
-            if let mediaCategoryViewController = viewControllers[currentIndex] as? MediaCategoryViewController {
-                mediaCategoryViewController.handleSortShortcut()
-            }
+        if let mediaCategoryViewController = viewControllers[currentIndex] as? MediaCategoryViewController {
+            mediaCategoryViewController.handleSortLongPress(sender: sender)
         }
     }
 }