mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.3 KiB
Swift
66 lines
2.3 KiB
Swift
5 years ago
|
|
||
5 years ago
|
class Sheet : BaseVC {
|
||
5 years ago
|
private(set) var bottomConstraint: NSLayoutConstraint!
|
||
|
|
||
|
// MARK: Settings
|
||
|
let overshoot: CGFloat = 40
|
||
4 years ago
|
class var isDismissable: Bool { true }
|
||
|
|
||
5 years ago
|
// MARK: Components
|
||
|
lazy var contentView: UIView = {
|
||
|
let result = UIView()
|
||
|
result.backgroundColor = Colors.modalBackground
|
||
|
result.layer.cornerRadius = 24
|
||
|
result.layer.masksToBounds = false
|
||
5 years ago
|
result.layer.borderColor = isLightMode ? UIColor.white.cgColor : Colors.modalBorder.cgColor
|
||
5 years ago
|
result.layer.borderWidth = Values.borderThickness
|
||
|
result.layer.shadowColor = UIColor.black.cgColor
|
||
5 years ago
|
result.layer.shadowRadius = isLightMode ? 2 : 8
|
||
|
result.layer.shadowOpacity = isLightMode ? 0.1 : 0.64
|
||
5 years ago
|
return result
|
||
|
}()
|
||
|
|
||
|
// MARK: Lifecycle
|
||
|
override func viewDidLoad() {
|
||
|
super.viewDidLoad()
|
||
5 years ago
|
let alpha = isLightMode ? CGFloat(0.1) : Values.modalBackgroundOpacity
|
||
|
view.backgroundColor = UIColor(hex: 0x000000).withAlphaComponent(alpha)
|
||
4 years ago
|
if type(of: self).isDismissable {
|
||
|
let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close))
|
||
|
swipeGestureRecognizer.direction = .down
|
||
|
view.addGestureRecognizer(swipeGestureRecognizer)
|
||
|
}
|
||
5 years ago
|
setUpViewHierarchy()
|
||
|
}
|
||
|
|
||
|
private func setUpViewHierarchy() {
|
||
|
view.addSubview(contentView)
|
||
|
contentView.pin(.leading, to: .leading, of: view, withInset: -Values.borderThickness)
|
||
|
contentView.pin(.trailing, to: .trailing, of: view, withInset: Values.borderThickness)
|
||
|
bottomConstraint = contentView.pin(.bottom, to: .bottom, of: view, withInset: overshoot)
|
||
|
populateContentView()
|
||
|
}
|
||
|
|
||
|
/// To be overridden by subclasses.
|
||
|
func populateContentView() {
|
||
|
preconditionFailure("populateContentView() is abstract and must be overridden.")
|
||
|
}
|
||
|
|
||
|
// MARK: Interaction
|
||
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||
|
let touch = touches.first!
|
||
|
let location = touch.location(in: view)
|
||
|
if contentView.frame.contains(location) {
|
||
|
super.touchesBegan(touches, with: event)
|
||
|
} else {
|
||
4 years ago
|
if type(of: self).isDismissable {
|
||
|
close()
|
||
|
}
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@objc func close() {
|
||
|
dismiss(animated: true, completion: nil)
|
||
|
}
|
||
|
}
|