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.
		
		
		
		
		
			
		
			
	
	
		
			81 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			81 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Swift
		
	
| 
											6 years ago
										 | 
 | ||
|  | @objc(LKModal) | ||
| 
											6 years ago
										 | class Modal : BaseVC { | ||
| 
											6 years ago
										 |     private(set) var verticalCenteringConstraint: NSLayoutConstraint! | ||
|  |      | ||
|  |     // MARK: Components | ||
|  |     lazy var contentView: UIView = { | ||
|  |         let result = UIView() | ||
|  |         result.backgroundColor = Colors.modalBackground | ||
|  |         result.layer.cornerRadius = Values.modalCornerRadius | ||
|  |         result.layer.masksToBounds = false | ||
| 
											5 years ago
										 |         result.layer.borderColor = isLightMode ? UIColor.white.cgColor : Colors.modalBorder.cgColor | ||
| 
											6 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 | ||
| 
											6 years ago
										 |         return result | ||
|  |     }() | ||
|  |      | ||
|  |     lazy var cancelButton: UIButton = { | ||
|  |         let result = UIButton() | ||
|  |         result.set(.height, to: Values.mediumButtonHeight) | ||
|  |         result.layer.cornerRadius = Values.modalButtonCornerRadius | ||
|  |         result.backgroundColor = Colors.buttonBackground | ||
|  |         result.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize) | ||
|  |         result.setTitleColor(Colors.text, for: UIControl.State.normal) | ||
| 
											5 years ago
										 |         result.setTitle(NSLocalizedString("cancel", comment: ""), for: UIControl.State.normal) | ||
| 
											6 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) | ||
| 
											6 years ago
										 |         cancelButton.addTarget(self, action: #selector(close), for: UIControl.Event.touchUpInside) | ||
|  |         let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close)) | ||
|  |         swipeGestureRecognizer.direction = .down | ||
|  |         view.addGestureRecognizer(swipeGestureRecognizer) | ||
| 
											6 years ago
										 |         setUpViewHierarchy() | ||
|  |     } | ||
|  |      | ||
|  |     private func setUpViewHierarchy() { | ||
|  |         view.addSubview(contentView) | ||
|  |         contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: Values.veryLargeSpacing).isActive = true | ||
|  |         view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: Values.veryLargeSpacing).isActive = true | ||
|  |         verticalCenteringConstraint = contentView.center(.vertical, in: view) | ||
|  |         populateContentView() | ||
|  |     } | ||
|  |      | ||
|  |     /// To be overridden by subclasses. | ||
|  |     func populateContentView() { | ||
|  |         preconditionFailure("populateContentView() is abstract and must be overridden.") | ||
|  |     } | ||
|  |      | ||
|  |     override func viewWillAppear(_ animated: Bool) { | ||
|  |         super.viewWillAppear(animated) | ||
| 
											6 years ago
										 | //        verticalCenteringConstraint.constant = contentView.height() / 2 + view.height() / 2 | ||
|  | //        view.layoutIfNeeded() | ||
|  | //        verticalCenteringConstraint.constant = 0 | ||
|  | //        UIView.animate(withDuration: 0.25) { | ||
|  | //            self.view.layoutIfNeeded() | ||
|  | //        } | ||
| 
											6 years ago
										 |     } | ||
|  |      | ||
|  |     // 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 { | ||
| 
											6 years ago
										 |             close() | ||
| 
											6 years ago
										 |         } | ||
|  |     } | ||
|  |      | ||
| 
											6 years ago
										 |     @objc func close() { | ||
| 
											6 years ago
										 |         dismiss(animated: true, completion: nil) | ||
|  |     } | ||
|  | } |