Prechádzať zdrojové kódy

MediaViewController: Hide SortButton and don't scroll in editmode

We shouldn't scroll when we're in edit so we're checking if we're allowed to scroll
Carola Nitz 6 rokov pred
rodič
commit
9985a0f67d

+ 6 - 2
Sources/MediaViewControllers/MediaViewController.swift

@@ -15,6 +15,7 @@ import UIKit
 class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
     var services: Services
     private var rendererButton: UIButton
+    private var sortButton: UIBarButtonItem?
     private let fixedSpaceWidth: CGFloat = 21
 
     init(services: Services) {
@@ -41,8 +42,8 @@ class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
         navigationController?.navigationBar.isTranslucent = false
         let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
         fixedSpace.width = fixedSpaceWidth
-
-        navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
+        sortButton = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
+        navigationItem.leftBarButtonItem = sortButton
         navigationItem.rightBarButtonItems = [editButtonItem, fixedSpace, UIBarButtonItem(customView: rendererButton)]
     }
 
@@ -102,6 +103,9 @@ class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
 
     override func setEditing(_ editing: Bool, animated: Bool) {
         super.setEditing(editing, animated: animated)
+
+        scrollingEnabled(!editing)
+        navigationItem.leftBarButtonItem = editing ? nil : sortButton
         viewControllers[currentIndex].setEditing(editing, animated: animated)
     }
 }

+ 2 - 2
Sources/PagerStripViewController.swift

@@ -159,8 +159,8 @@ class PagerTabStripViewController: UIViewController, UIScrollViewDelegate {
         }
     }
 
-    func canMoveTo(index: Int) -> Bool {
-        return currentIndex != index && viewControllers.count > index
+    func scrollingEnabled(_ enabled: Bool) {
+        containerView.isScrollEnabled = enabled
     }
 
     func pageOffsetForChild(at index: Int) -> CGFloat {

+ 1 - 1
Sources/VLCPagingViewController.swift

@@ -188,7 +188,7 @@ class VLCPagingViewController<ButtonBarCellType: UICollectionViewCell>: PagerTab
     }
 
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        guard indexPath.item != currentIndex else { return }
+        guard indexPath.item != currentIndex && containerView.isScrollEnabled else { return }
 
         buttonBarView.moveTo(index: indexPath.item, animated: true, swipeDirection: .none, pagerScroll: .yes)
         shouldUpdateButtonBarView = false