123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import Foundation
- import FloatingPanel
- import UIKit
- class NCMenuFloatingPanelLayout: FloatingPanelLayout {
- var position: FloatingPanelPosition = .bottom
- var initialState: FloatingPanelState = .full
- var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
- [
- .full: FloatingPanelLayoutAnchor(absoluteInset: topInset, edge: .top, referenceGuide: .superview)
- ]
- }
- let topInset: CGFloat
- init(actionsHeight: CGFloat) {
-
-
-
- let screenHeight = UIApplication.shared.isLandscape
- ? min(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)
- : max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)
- let bottomInset = UIApplication.shared.keyWindow?.rootViewController?.view.safeAreaInsets.bottom ?? 0
- let panelHeight = CGFloat(actionsHeight) + bottomInset
- topInset = max(48, screenHeight - panelHeight)
- }
- 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 backdropAlpha(for state: FloatingPanelState) -> CGFloat {
- return 0.2
- }
- }
- class NCMenuPanelController: FloatingPanelController {
- var parentPresenter: UIViewController?
-
- override func viewDidLoad() {
- super.viewDidLoad()
- self.surfaceView.backgroundColor = .systemBackground
- self.isRemovalInteractionEnabled = true
- self.backdropView.dismissalTapGestureRecognizer.isEnabled = true
- self.surfaceView.layer.cornerRadius = 16
- self.surfaceView.clipsToBounds = true
- surfaceView.grabberHandle.accessibilityLabel = NSLocalizedString("_cart_controller_", comment: "")
- let collapseName = NSLocalizedString("_dismiss_menu_", comment: "")
- let collapseAction = UIAccessibilityCustomAction(name: collapseName, target: self, selector: #selector(accessibilityActionCollapsePanel))
- surfaceView.grabberHandle.accessibilityCustomActions = [collapseAction]
- surfaceView.grabberHandle.isAccessibilityElement = true
- }
- @objc private func accessibilityActionCollapsePanel() {
- self.dismiss(animated: true)
- }
- }
|