12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import Foundation
- import FloatingPanel
- 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(numberOfActions: Int) {
-
-
-
- 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(numberOfActions * 60) + 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 = NCBrandColor.shared.systemBackground
- self.isRemovalInteractionEnabled = true
- self.backdropView.dismissalTapGestureRecognizer.isEnabled = true
- self.surfaceView.layer.cornerRadius = 16
- }
- }
|