Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
100
iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.swift
Normal file
100
iphone/Maps/UI/BottomMenu/Menu/BottomMenuViewController.swift
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
protocol BottomMenuViewProtocol: AnyObject {
|
||||
var presenter: BottomMenuPresenterProtocol? { get set }
|
||||
}
|
||||
|
||||
class BottomMenuViewController: MWMViewController {
|
||||
var presenter: BottomMenuPresenterProtocol?
|
||||
private let transitioningManager = BottomMenuTransitioningManager()
|
||||
|
||||
@IBOutlet var tableView: UITableView!
|
||||
@IBOutlet var heightConstraint: NSLayoutConstraint!
|
||||
@IBOutlet var bottomConstraint: NSLayoutConstraint!
|
||||
|
||||
lazy var chromeView: UIView = {
|
||||
let view = UIView()
|
||||
view.setStyle(.presentationBackground)
|
||||
return view
|
||||
}()
|
||||
|
||||
weak var containerView: UIView! {
|
||||
didSet {
|
||||
containerView.insertSubview(chromeView, at: 0)
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
tableView.layer.setCornerRadius(.buttonDefault, maskedCorners: [.layerMinXMinYCorner, .layerMaxXMinYCorner])
|
||||
tableView.sectionFooterHeight = 0
|
||||
|
||||
tableView.dataSource = presenter
|
||||
tableView.delegate = presenter
|
||||
tableView.registerNib(cell: BottomMenuItemCell.self)
|
||||
tableView.registerNib(cell: BottomMenuLayersCell.self)
|
||||
|
||||
NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: nil) { _ in
|
||||
DispatchQueue.main.async {
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
if let cellToHighlight = presenter?.cellToHighlightIndexPath() {
|
||||
tableView.cellForRow(at: cellToHighlight)?.highlight()
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
tableView.setNeedsLayout()
|
||||
tableView.layoutIfNeeded()
|
||||
heightConstraint.constant = min(tableView.contentSize.height, view.height)
|
||||
tableView.isScrollEnabled = tableView.contentSize.height > heightConstraint.constant;
|
||||
}
|
||||
|
||||
@IBAction func onClosePressed(_ sender: Any) {
|
||||
presenter?.onClosePressed()
|
||||
}
|
||||
|
||||
@IBAction func onPan(_ sender: UIPanGestureRecognizer) {
|
||||
let yOffset = sender.translation(in: view.superview).y
|
||||
let yVelocity = sender.velocity(in: view.superview).y
|
||||
sender.setTranslation(CGPoint.zero, in: view.superview)
|
||||
bottomConstraint.constant = min(bottomConstraint.constant - yOffset, 0);
|
||||
|
||||
let alpha = 1.0 - abs(bottomConstraint.constant / tableView.height)
|
||||
self.chromeView.alpha = alpha
|
||||
|
||||
let state = sender.state
|
||||
if state == .ended || state == .cancelled {
|
||||
if yVelocity > 0 || (yVelocity == 0 && alpha < 0.8) {
|
||||
presenter?.onClosePressed()
|
||||
} else {
|
||||
let duration = min(kDefaultAnimationDuration, TimeInterval(self.bottomConstraint.constant / yVelocity))
|
||||
self.view.layoutIfNeeded()
|
||||
UIView.animate(withDuration: duration) {
|
||||
self.chromeView.alpha = 1
|
||||
self.bottomConstraint.constant = 0
|
||||
self.view.layoutIfNeeded()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override var transitioningDelegate: UIViewControllerTransitioningDelegate? {
|
||||
get { return transitioningManager }
|
||||
set { }
|
||||
}
|
||||
|
||||
override var modalPresentationStyle: UIModalPresentationStyle {
|
||||
get { return .custom }
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
extension BottomMenuViewController: BottomMenuViewProtocol {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue