فهرست منبع

Update FloatingPanel ~> v2

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 سال پیش
والد
کامیت
366b60367b

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -2983,7 +2983,7 @@
 			repositoryURL = "https://github.com/scenee/FloatingPanel";
 			requirement = {
 				kind = upToNextMajorVersion;
-				minimumVersion = 1.7.6;
+				minimumVersion = 2.0.0;
 			};
 		};
 		F782A57925123694007BBABD /* XCRemoteSwiftPackageReference "realm-cocoa" */ = {

+ 2 - 2
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -51,8 +51,8 @@
         "repositoryURL": "https://github.com/scenee/FloatingPanel",
         "state": {
           "branch": null,
-          "revision": "ca7596e1cae161415f54059a8c44b82c95724160",
-          "version": "1.7.6"
+          "revision": "0fbbbc8d99b4dfe58bb1dd704d14b45f35b46584",
+          "version": "2.5.1"
         }
       },
       {

+ 37 - 51
iOSClient/Menu/NCMenu.swift

@@ -84,88 +84,74 @@ class NCMenu: UITableViewController {
         return cell
     }
 
+    // MARK: - Tabel View Layout
+
+    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
+        return 60
+    }
+
     // MARK: - Accessibility
-    
+
     open override func accessibilityPerformEscape() -> Bool {
         dismiss(animated: true)
         return true
     }
-
 }
 extension NCMenu: FloatingPanelControllerDelegate {
 
-    func floatingPanel(_ vc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout? {
-        let safeAreaInsetsBottom = Int(UIApplication.shared.keyWindow?.rootViewController?.view.safeAreaInsets.bottom ?? 0)
-        return NCMenuFloatingPanelLayout(height: self.actions.count * 60 + safeAreaInsetsBottom)
+    func floatingPanel(_ fpc: FloatingPanelController, layoutFor size: CGSize) -> FloatingPanelLayout {
+        return NCMenuFloatingPanelLayout(numberOfActions: self.actions.count, view: view)
     }
-    
-    func floatingPanel(_ vc: FloatingPanelController, behaviorFor newCollection: UITraitCollection) -> FloatingPanelBehavior? {
-        return NCMenuFloatingPanelBehavior()
+
+    func floatingPanel(_ fpc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout {
+        return NCMenuFloatingPanelLayout(numberOfActions: self.actions.count, view: view)
     }
 
-    func floatingPanelDidEndDecelerating(_ vc: FloatingPanelController) {
-        if vc.position == .hidden {
-            vc.dismiss(animated: false, completion: nil)
-        }
+    func floatingPanel(_ fpc: FloatingPanelController, animatorForDismissingWith velocity: CGVector) -> UIViewPropertyAnimator {
+        return UIViewPropertyAnimator(duration: 0.1, curve: .easeInOut)
+    }
+
+    func floatingPanel(_ fpc: FloatingPanelController, animatorForPresentingTo state: FloatingPanelState) -> UIViewPropertyAnimator {
+        return UIViewPropertyAnimator(duration: 0.3, curve: .easeInOut)
+    }
+    
+    func floatingPanelDidChangeState(_ fpc: FloatingPanelController) {
+        guard fpc.state == .hidden else { return }
+        fpc.dismiss(animated: false, completion: nil)
     }
 }
 
 class NCMenuFloatingPanelLayout: FloatingPanelLayout {
+    var position: FloatingPanelPosition = .bottom
 
-    let height: CGFloat
-
-    init(height: Int) {
-        self.height = CGFloat(height)
-    }
+    var initialState: FloatingPanelState = .full
 
-    var initialPosition: FloatingPanelPosition {
-        return .full
-    }
-
-    var supportedPositions: Set<FloatingPanelPosition> {
-        return [.full, .hidden]
+    var anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] {
+        [
+            .full: FloatingPanelLayoutAnchor(absoluteInset: topInset, edge: .top, referenceGuide: .superview)
+        ]
     }
 
-    func insetFor(position: FloatingPanelPosition) -> CGFloat? {
-        if (position == .full) {
-            return max(48, UIScreen.main.bounds.size.height - height)
-        } else {
-            return nil
-        }
-    }
+    let topInset: CGFloat
 
-    var positionReference: FloatingPanelLayoutReference {
-        return .fromSuperview
+    init(numberOfActions: Int, view: UIView) {
+        let bottomInset = UIApplication.shared.keyWindow?.rootViewController?.view.safeAreaInsets.bottom ?? 0
+        let panelHeight = CGFloat(numberOfActions * 60) + bottomInset
+        topInset = max(48, view.bounds.height - panelHeight)
     }
 
-    public func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] {
+    func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] {
         return [
             surfaceView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
             surfaceView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0),
         ]
     }
 
-    func backdropAlphaFor(position: FloatingPanelPosition) -> CGFloat {
+    func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
         return 0.2
     }
 }
 
-public class NCMenuFloatingPanelBehavior: FloatingPanelBehavior {
-
-    public func addAnimator(_ fpc: FloatingPanelController, to: FloatingPanelPosition) -> UIViewPropertyAnimator {
-        return UIViewPropertyAnimator(duration: 0.3, curve: .easeInOut)
-    }
-
-    public func removeAnimator(_ fpc: FloatingPanelController, from: FloatingPanelPosition) -> UIViewPropertyAnimator {
-        return UIViewPropertyAnimator(duration: 0.1, curve: .easeInOut)
-    }
-
-    public func moveAnimator(_ fpc: FloatingPanelController, from: FloatingPanelPosition, to: FloatingPanelPosition) -> UIViewPropertyAnimator {
-        return UIViewPropertyAnimator(duration: 0.1, curve: .easeInOut)
-    }
-
-}
-
 class NCMenuPanelController: FloatingPanelController {
 
     var parentPresenter: UIViewController?
@@ -177,7 +163,7 @@ class NCMenuPanelController: FloatingPanelController {
 
         self.surfaceView.backgroundColor = NCBrandColor.shared.systemBackground
         self.isRemovalInteractionEnabled = true
-        self.surfaceView.cornerRadius = 16
+        self.surfaceView.layer.cornerRadius = 16
     }
 }