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.
		
		
		
		
		
			
		
			
	
	
		
			121 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			121 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Swift
		
	
| 
											9 years ago
										 | // | ||
| 
											7 years ago
										 | //  Copyright (c) 2019 Open Whisper Systems. All rights reserved. | ||
| 
											9 years ago
										 | // | ||
|  | 
 | ||
|  | import Foundation | ||
|  | 
 | ||
| 
											9 years ago
										 | class ReminderView: UIView { | ||
| 
											9 years ago
										 | 
 | ||
|  |     let label = UILabel() | ||
|  | 
 | ||
| 
											7 years ago
										 |     typealias Action = () -> Void | ||
| 
											9 years ago
										 | 
 | ||
| 
											7 years ago
										 |     var tapAction: Action? | ||
| 
											9 years ago
										 | 
 | ||
|  |     var text: String? { | ||
|  |         get { | ||
|  |             return label.text | ||
|  |         } | ||
|  | 
 | ||
|  |         set(newText) { | ||
|  |             label.text = newText | ||
|  |         } | ||
|  |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     enum ReminderViewMode { | ||
|  |         // Nags are urgent interactive prompts, bidding for the user's attention. | ||
|  |         case nag | ||
|  |         // Explanations are not interactive or urgent. | ||
|  |         case explanation | ||
|  |     } | ||
|  |     let mode: ReminderViewMode | ||
| 
											9 years ago
										 | 
 | ||
| 
											8 years ago
										 |     @available(*, unavailable, message:"use other constructor instead.") | ||
|  |     required init?(coder aDecoder: NSCoder) { | ||
| 
											7 years ago
										 |         notImplemented() | ||
| 
											9 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @available(*, unavailable, message:"use other constructor instead.") | ||
| 
											9 years ago
										 |     override init(frame: CGRect) { | ||
| 
											7 years ago
										 |         notImplemented() | ||
| 
											8 years ago
										 |     } | ||
| 
											9 years ago
										 | 
 | ||
| 
											8 years ago
										 |     private init(mode: ReminderViewMode, | ||
| 
											7 years ago
										 |          text: String, tapAction: Action?) { | ||
| 
											8 years ago
										 |         self.mode = mode | ||
|  |         self.tapAction = tapAction | ||
|  | 
 | ||
|  |         super.init(frame: .zero) | ||
|  | 
 | ||
|  |         self.text = text | ||
| 
											9 years ago
										 | 
 | ||
|  |         setupSubviews() | ||
|  |     } | ||
|  | 
 | ||
| 
											7 years ago
										 |     @objc public class func nag(text: String, tapAction: Action?) -> ReminderView { | ||
| 
											8 years ago
										 |         return ReminderView(mode: .nag, text: text, tapAction: tapAction) | ||
|  |     } | ||
|  | 
 | ||
|  |     @objc public class func explanation(text: String) -> ReminderView { | ||
| 
											7 years ago
										 |         return ReminderView(mode: .explanation, text: text, tapAction: nil) | ||
| 
											9 years ago
										 |     } | ||
|  | 
 | ||
|  |     func setupSubviews() { | ||
| 
											7 years ago
										 |         let textColor: UIColor | ||
|  |         let iconColor: UIColor | ||
| 
											7 years ago
										 |         switch mode { | ||
| 
											8 years ago
										 |         case .nag: | ||
|  |             self.backgroundColor = UIColor.ows_reminderYellow | ||
| 
											7 years ago
										 |             textColor = UIColor.ows_gray90 | ||
|  |             iconColor = UIColor.ows_gray60 | ||
| 
											8 years ago
										 |         case .explanation: | ||
| 
											7 years ago
										 |             // TODO: Theme, review with design. | ||
| 
											7 years ago
										 |             self.backgroundColor = Theme.offBackgroundColor | ||
| 
											7 years ago
										 |             textColor = Theme.primaryColor | ||
|  |             iconColor = Theme.secondaryColor | ||
| 
											8 years ago
										 |         } | ||
| 
											9 years ago
										 |         self.clipsToBounds = true | ||
|  | 
 | ||
|  |         let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(gestureRecognizer:))) | ||
| 
											8 years ago
										 |         self.addGestureRecognizer(tapGesture) | ||
|  | 
 | ||
| 
											7 years ago
										 |         let container = UIStackView() | ||
|  |         container.axis = .horizontal | ||
|  |         container.alignment = .center | ||
|  |         container.isLayoutMarginsRelativeArrangement = true | ||
| 
											9 years ago
										 | 
 | ||
|  |         self.addSubview(container) | ||
| 
											7 years ago
										 |         container.layoutMargins = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16) | ||
| 
											7 years ago
										 |         container.ows_autoPinToSuperviewEdges() | ||
| 
											9 years ago
										 | 
 | ||
|  |         // Label | ||
| 
											7 years ago
										 |         label.font = UIFont.ows_dynamicTypeSubheadline | ||
| 
											7 years ago
										 |         container.addArrangedSubview(label) | ||
| 
											7 years ago
										 |         label.textColor = textColor | ||
| 
											9 years ago
										 |         label.numberOfLines = 0 | ||
| 
											8 years ago
										 |         label.lineBreakMode = .byWordWrapping | ||
| 
											9 years ago
										 | 
 | ||
| 
											7 years ago
										 |         // Show the disclosure indicator if this reminder has a tap action. | ||
| 
											7 years ago
										 |         if tapAction != nil { | ||
|  |             // Icon | ||
| 
											7 years ago
										 |             let iconName = (CurrentAppContext().isRTL ? "system_disclosure_indicator_rtl" : "system_disclosure_indicator") | ||
| 
											7 years ago
										 |             guard let iconImage = UIImage(named: iconName) else { | ||
| 
											7 years ago
										 |                 owsFailDebug("missing icon.") | ||
| 
											7 years ago
										 |                 return | ||
|  |             } | ||
|  |             let iconView = UIImageView(image: iconImage.withRenderingMode(.alwaysTemplate)) | ||
|  |             iconView.contentMode = .scaleAspectFit | ||
| 
											7 years ago
										 |             iconView.tintColor = iconColor | ||
| 
											7 years ago
										 |             iconView.autoSetDimension(.width, toSize: 13) | ||
|  |             container.addArrangedSubview(iconView) | ||
| 
											8 years ago
										 |         } | ||
| 
											9 years ago
										 |     } | ||
|  | 
 | ||
| 
											8 years ago
										 |     @objc func handleTap(gestureRecognizer: UIGestureRecognizer) { | ||
| 
											7 years ago
										 |         guard gestureRecognizer.state == .recognized else { | ||
|  |             return | ||
|  |         } | ||
|  |         tapAction?() | ||
| 
											9 years ago
										 |     } | ||
|  | } |