-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💲[Native Checkout] Sheet Overlay Container (#674)
* Sheet overlay container VC and animator * Renaming, fixing rotation issues * Revert testing code * Cleanup and fixing a snapshot * Using keypath lenses * Updating the comment * PR comments * Renaming * Cleanup * View helpers * Style naming * Fix build * Remove iOS 11 Availability Checks From Native Checkout (#679) * Remove iOS 11 availability references * Fix merge conflict issues * Renaming suggestions * Swiftlint
- Loading branch information
Showing
12 changed files
with
292 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
Kickstarter-iOS/Views/Controllers/SheetOverlayViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import UIKit | ||
import Library | ||
import Prelude | ||
|
||
/** | ||
SheetOverlayViewController is intended to be used as a container for another view controller | ||
that renders as a "sheet" or "card" that partially covers the content beneath it. | ||
*/ | ||
|
||
final class SheetOverlayViewController: UIViewController { | ||
// MARK: - Properties | ||
|
||
private let childViewController: UIViewController | ||
private let offset: CGFloat | ||
private let transitionAnimator = SheetOverlayTransitionAnimator() | ||
|
||
init(child: UIViewController, offset: CGFloat = 45.0) { | ||
self.childViewController = child | ||
self.offset = offset | ||
|
||
super.init(nibName: nil, bundle: nil) | ||
|
||
_ = self | ||
|> \.modalPresentationStyle .~ .custom | ||
|> \.transitioningDelegate .~ self | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.addChild(self.childViewController) | ||
self.configure(childView: self.childViewController.view, offset: self.offset) | ||
|
||
self.childViewController.didMove(toParent: self) | ||
} | ||
|
||
private func configure(childView: UIView, offset: CGFloat) { | ||
_ = (childView, self.view) | ||
|> ksr_addSubviewToParent() | ||
|
||
_ = childView | ||
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||
|
||
_ = childView.layer | ||
|> checkoutLayerCardRoundedStyle | ||
|> \.masksToBounds .~ true | ||
|> \.maskedCorners .~ [.layerMaxXMinYCorner, .layerMinXMinYCorner] | ||
|
||
let isRegular = UIScreen.main.traitCollection.isRegularRegular | ||
let portraitWidth = min(UIScreen.main.bounds.height, UIScreen.main.bounds.width) | ||
|
||
NSLayoutConstraint.activate([childView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), | ||
childView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), | ||
childView.topAnchor.constraint(equalTo: self.view.topAnchor, | ||
constant: offset)]) | ||
|
||
if isRegular { | ||
childView.widthAnchor.constraint(equalToConstant: portraitWidth).isActive = true | ||
} else { | ||
childView.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true | ||
} | ||
} | ||
} | ||
|
||
extension SheetOverlayViewController: UIViewControllerTransitioningDelegate { | ||
func animationController(forPresented presented: UIViewController, presenting: UIViewController, | ||
source: UIViewController) -> UIViewControllerAnimatedTransitioning? { | ||
return self.transitionAnimator | ||
} | ||
|
||
func animationController(forDismissed dismissed: UIViewController) -> | ||
UIViewControllerAnimatedTransitioning? { | ||
return self.transitionAnimator | ||
} | ||
} |
Oops, something went wrong.