Files
comaps/iphone/Maps/Classes/Components/Modal/DimmedModalPresentationController.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

51 lines
1.6 KiB
Swift

class DimmedModalPresentationController: UIPresentationController {
private lazy var onTapGr: UITapGestureRecognizer = {
return UITapGestureRecognizer(target: self, action: #selector(onTap))
}()
private lazy var dimView: UIView = {
let view = UIView()
view.setStyle(.blackStatusBarBackground)
if isCancellable {
view.addGestureRecognizer(onTapGr)
}
return view
}()
let isCancellable: Bool
required init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, cancellable: Bool = true) {
isCancellable = cancellable
super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
}
@objc private func onTap() {
presentingViewController.dismiss(animated: true, completion: nil)
}
override func presentationTransitionWillBegin() {
guard let containerView = containerView else { return }
containerView.addSubview(dimView)
dimView.frame = containerView.bounds
dimView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
dimView.alpha = 0
presentingViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
self.dimView.alpha = 1
})
}
override func presentationTransitionDidEnd(_ completed: Bool) {
if !completed { dimView.removeFromSuperview() }
}
override func dismissalTransitionWillBegin() {
presentingViewController.transitionCoordinator?.animate(alongsideTransition: { _ in
self.dimView.alpha = 0
})
}
override func dismissalTransitionDidEnd(_ completed: Bool) {
if completed { dimView.removeFromSuperview() }
}
}