Repo created
This commit is contained in:
parent
4af19165ec
commit
68073add76
12458 changed files with 12350765 additions and 2 deletions
|
|
@ -0,0 +1,27 @@
|
|||
final class AlertPresentationController: DimmedModalPresentationController {
|
||||
override var frameOfPresentedViewInContainerView: CGRect {
|
||||
let f = super.frameOfPresentedViewInContainerView
|
||||
let s = presentedViewController.view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
|
||||
let r = CGRect(x: 0, y: 0, width: s.width, height: s.height)
|
||||
return r.offsetBy(dx: (f.width - r.width) / 2, dy: (f.height - r.height) / 2)
|
||||
}
|
||||
|
||||
override func presentationTransitionWillBegin() {
|
||||
super.presentationTransitionWillBegin()
|
||||
presentedViewController.view.layer.setCornerRadius(.modalSheet)
|
||||
presentedViewController.view.clipsToBounds = true
|
||||
guard let containerView = containerView, let presentedView = presentedView else { return }
|
||||
containerView.addSubview(presentedView)
|
||||
presentedView.center = containerView.center
|
||||
presentedView.frame = frameOfPresentedViewInContainerView
|
||||
presentedView.autoresizingMask = [.flexibleLeftMargin, .flexibleTopMargin, .flexibleRightMargin, .flexibleBottomMargin]
|
||||
}
|
||||
|
||||
override func dismissalTransitionDidEnd(_ completed: Bool) {
|
||||
super.presentationTransitionDidEnd(completed)
|
||||
guard let presentedView = presentedView else { return }
|
||||
if completed {
|
||||
presentedView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
final class CoverVerticalDismissalAnimator: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return kDefaultAnimationDuration
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let fromVC = transitionContext.viewController(forKey: .from),
|
||||
let toVC = transitionContext.viewController(forKey: .to)
|
||||
else { return }
|
||||
|
||||
let originFrame = transitionContext.finalFrame(for: toVC)
|
||||
let finalFrame = originFrame.offsetBy(dx: 0, dy: originFrame.height)
|
||||
UIView.animate(withDuration: transitionDuration(using: transitionContext),
|
||||
animations: {
|
||||
fromVC.view.frame = finalFrame
|
||||
}) { finished in
|
||||
fromVC.view.removeFromSuperview()
|
||||
transitionContext.completeTransition(finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
final class CoverVerticalModalTransitioning: NSObject, UIViewControllerTransitioningDelegate {
|
||||
private var height: CGFloat
|
||||
init(presentationHeight: CGFloat) {
|
||||
height = presentationHeight
|
||||
}
|
||||
|
||||
func animationController(forPresented presented: UIViewController,
|
||||
presenting: UIViewController,
|
||||
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
return CoverVerticalPresentationAnimator()
|
||||
}
|
||||
|
||||
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
return CoverVerticalDismissalAnimator()
|
||||
}
|
||||
|
||||
func presentationController(forPresented presented: UIViewController,
|
||||
presenting: UIViewController?,
|
||||
source: UIViewController) -> UIPresentationController? {
|
||||
return PresentationController(presentedViewController: presented, presenting: presenting, presentationHeight: height)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate final class PresentationController: DimmedModalPresentationController {
|
||||
private var height: CGFloat
|
||||
init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, presentationHeight: CGFloat) {
|
||||
height = presentationHeight
|
||||
super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
|
||||
}
|
||||
|
||||
required init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, cancellable: Bool = true) {
|
||||
fatalError("init(presentedViewController:presenting:cancellable:) has not been implemented")
|
||||
}
|
||||
|
||||
override var frameOfPresentedViewInContainerView: CGRect {
|
||||
let f = super.frameOfPresentedViewInContainerView
|
||||
return CGRect(x: 0, y: f.height - height, width: f.width, height: height)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
final class CoverVerticalPresentationAnimator: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return kDefaultAnimationDuration
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let toVC = transitionContext.viewController(forKey: .to) else { return }
|
||||
|
||||
let containerView = transitionContext.containerView
|
||||
let finalFrame = transitionContext.finalFrame(for: toVC)
|
||||
let originFrame = finalFrame.offsetBy(dx: 0, dy: finalFrame.height)
|
||||
|
||||
containerView.addSubview(toVC.view)
|
||||
toVC.view.frame = originFrame
|
||||
toVC.view.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
|
||||
UIView.animate(withDuration: transitionDuration(using: transitionContext),
|
||||
animations: {
|
||||
toVC.view.frame = finalFrame
|
||||
}) { transitionContext.completeTransition($0) }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
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() }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
final class FadeInAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return kDefaultAnimationDuration
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let presentedView = transitionContext.view(forKey: .to) else { return }
|
||||
|
||||
presentedView.alpha = 0
|
||||
UIView.animate(withDuration: transitionDuration(using: transitionContext),
|
||||
animations: {
|
||||
presentedView.alpha = 1
|
||||
}) { transitionContext.completeTransition($0) }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
final class FadeOutAnimatedTransitioning: NSObject, UIViewControllerAnimatedTransitioning {
|
||||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
|
||||
return kDefaultAnimationDuration
|
||||
}
|
||||
|
||||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
|
||||
guard let presentedView = transitionContext.view(forKey: .from) else { return }
|
||||
UIView.animate(withDuration: transitionDuration(using: transitionContext),
|
||||
animations: {
|
||||
presentedView.alpha = 0
|
||||
}) { finished in
|
||||
transitionContext.completeTransition(finished)
|
||||
}
|
||||
}
|
||||
}
|
||||
26
iphone/Maps/Classes/Components/Modal/FadeTransitioning.swift
Normal file
26
iphone/Maps/Classes/Components/Modal/FadeTransitioning.swift
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class FadeTransitioning<T: DimmedModalPresentationController>: NSObject, UIViewControllerTransitioningDelegate {
|
||||
let presentedTransitioning = FadeInAnimatedTransitioning()
|
||||
let dismissedTransitioning = FadeOutAnimatedTransitioning()
|
||||
let isCancellable: Bool
|
||||
|
||||
init(cancellable: Bool = true) {
|
||||
isCancellable = cancellable
|
||||
super.init()
|
||||
}
|
||||
|
||||
func animationController(forPresented presented: UIViewController,
|
||||
presenting: UIViewController,
|
||||
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
return presentedTransitioning
|
||||
}
|
||||
|
||||
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
|
||||
return dismissedTransitioning
|
||||
}
|
||||
|
||||
func presentationController(forPresented presented: UIViewController,
|
||||
presenting: UIViewController?,
|
||||
source: UIViewController) -> UIPresentationController? {
|
||||
return T(presentedViewController: presented, presenting: presenting, cancellable: isCancellable)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
final class IPadModalPresentationController: DimmedModalPresentationController {
|
||||
override var frameOfPresentedViewInContainerView: CGRect {
|
||||
guard let containerView = containerView else { return CGRect.zero }
|
||||
let screenSize = UIScreen.main.bounds
|
||||
let contentSize = presentedViewController.preferredContentSize
|
||||
let r = alternative(iPhone: containerView.bounds,
|
||||
iPad: CGRect(x: screenSize.width/2 - contentSize.width/2,
|
||||
y: screenSize.height/2 - contentSize.height/2,
|
||||
width: contentSize.width,
|
||||
height: contentSize.height))
|
||||
return r
|
||||
}
|
||||
|
||||
override func containerViewWillLayoutSubviews() {
|
||||
presentedView?.frame = frameOfPresentedViewInContainerView
|
||||
}
|
||||
|
||||
override func presentationTransitionWillBegin() {
|
||||
super.presentationTransitionWillBegin()
|
||||
presentedViewController.view.layer.setCornerRadius(.buttonDefault)
|
||||
presentedViewController.view.clipsToBounds = true
|
||||
guard let containerView = containerView, let presentedView = presentedView else { return }
|
||||
containerView.addSubview(presentedView)
|
||||
presentedView.frame = frameOfPresentedViewInContainerView
|
||||
}
|
||||
|
||||
override func dismissalTransitionDidEnd(_ completed: Bool) {
|
||||
super.presentationTransitionDidEnd(completed)
|
||||
guard let presentedView = presentedView else { return }
|
||||
if completed {
|
||||
presentedView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
final class PromoBookingPresentationController: DimmedModalPresentationController {
|
||||
let sideMargin: CGFloat = 32.0
|
||||
let maxWidth: CGFloat = 310.0
|
||||
|
||||
override var frameOfPresentedViewInContainerView: CGRect {
|
||||
let f = super.frameOfPresentedViewInContainerView
|
||||
let estimatedWidth = min(maxWidth, f.width - (sideMargin * 2.0))
|
||||
let s = presentedViewController.view.systemLayoutSizeFitting(CGSize(width: estimatedWidth, height: f.height), withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow)
|
||||
let r = CGRect(x: (f.width - s.width) / 2, y: (f.height - s.height) / 2, width: s.width, height: s.height)
|
||||
return r
|
||||
}
|
||||
|
||||
override func containerViewWillLayoutSubviews() {
|
||||
presentedView?.frame = frameOfPresentedViewInContainerView
|
||||
}
|
||||
|
||||
override func presentationTransitionWillBegin() {
|
||||
super.presentationTransitionWillBegin()
|
||||
presentedViewController.view.layer.setCornerRadius(.buttonDefault)
|
||||
presentedViewController.view.clipsToBounds = true
|
||||
guard let containerView = containerView, let presentedView = presentedView else { return }
|
||||
containerView.addSubview(presentedView)
|
||||
presentedView.frame = frameOfPresentedViewInContainerView
|
||||
}
|
||||
|
||||
override func dismissalTransitionDidEnd(_ completed: Bool) {
|
||||
super.presentationTransitionDidEnd(completed)
|
||||
guard let presentedView = presentedView else { return }
|
||||
if completed {
|
||||
presentedView.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue