소스 검색

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 년 전
부모
커밋
4d6476ae80
2개의 변경된 파일12개의 추가작업 그리고 8개의 파일을 삭제
  1. 10 1
      Sources/MediaCategories/MediaCategoryViewController.swift
  2. 2 7
      Sources/MediaViewControllers/MediaViewController.swift

+ 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)
         }
     }
 }