123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- //
- // MainMenuTableViewController.swift
- // Nextcloud
- //
- // Created by Philippe Weidmann on 16.01.20.
- // Copyright © 2020 TWS. All rights reserved.
- //
- import UIKit
- import FloatingPanel
- class MainMenuTableViewController: UITableViewController {
- var actions = [MenuAction]()
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let menuAction = actions[indexPath.row]
- self.dismiss(animated: true, completion: nil)
- menuAction.action?(menuAction)
- }
- // MARK: - Table view data source
- override func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return actions.count
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "menuActionCell", for: indexPath)
- cell.tintColor = NCBrandColor.sharedInstance.customer
- let action = actions[indexPath.row]
- let actionIconView = cell.viewWithTag(1) as! UIImageView
- let actionNameLabel = cell.viewWithTag(2) as! UILabel
- if (action.isOn) {
- actionIconView.image = action.onIcon
- actionNameLabel.text = action.onTitle
- } else {
- actionIconView.image = action.icon
- actionNameLabel.text = action.title
- }
- cell.accessoryType = action.selectable && action.selected ? .checkmark : .none
- return cell
- }
- }
- extension MainMenuTableViewController: FloatingPanelControllerDelegate {
- func floatingPanel(_ vc: FloatingPanelController, layoutFor newCollection: UITraitCollection) -> FloatingPanelLayout? {
- return MainMenuFloatingPanelLayout(height: self.actions.count * 60)
- }
- func floatingPanel(_ vc: FloatingPanelController, behaviorFor newCollection: UITraitCollection) -> FloatingPanelBehavior? {
- return MainMenuFloatingPanelBehavior()
- }
- }
- class MainMenuFloatingPanelLayout: FloatingPanelLayout {
- let height: CGFloat
- init(height: Int) {
- self.height = CGFloat(height)
- }
- var initialPosition: FloatingPanelPosition {
- return .tip
- }
- var supportedPositions: Set<FloatingPanelPosition> {
- return [.half]
- }
- func insetFor(position: FloatingPanelPosition) -> CGFloat? {
- switch position {
- case .half: return height
- case .tip: return height
- default: return nil
- }
- }
- func backdropAlphaFor(position: FloatingPanelPosition) -> CGFloat {
- return 0.5
- }
- }
- public class MainMenuFloatingPanelBehavior: 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)
- }
- }
|