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.
		
		
		
		
		
			
		
			
	
	
		
			97 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			97 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Swift
		
	
| 
											3 years ago
										 | // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. | ||
|  | 
 | ||
|  | import UIKit | ||
|  | import SessionUIKit | ||
|  | 
 | ||
| 
											3 years ago
										 | class SessionHeaderView: UITableViewHeaderFooterView { | ||
| 
											3 years ago
										 |     private lazy var emptyHeightConstraint: NSLayoutConstraint = self.heightAnchor | ||
|  |         .constraint(equalToConstant: (Values.verySmallSpacing * 2)) | ||
|  |     private lazy var filledHeightConstraint: NSLayoutConstraint = self.heightAnchor | ||
|  |         .constraint(greaterThanOrEqualToConstant: Values.mediumSpacing) | ||
|  |      | ||
|  |     // MARK: - UI | ||
|  |      | ||
|  |     private let stackView: UIStackView = { | ||
|  |         let result: UIStackView = UIStackView() | ||
|  |         result.translatesAutoresizingMaskIntoConstraints = false | ||
|  |         result.axis = .vertical | ||
|  |         result.distribution = .fill | ||
|  |         result.alignment = .fill | ||
|  |         result.isLayoutMarginsRelativeArrangement = true | ||
|  |          | ||
|  |         return result | ||
|  |     }() | ||
|  |      | ||
|  |     private let titleLabel: UILabel = { | ||
|  |         let result: UILabel = UILabel() | ||
|  |         result.translatesAutoresizingMaskIntoConstraints = false | ||
|  |         result.font = .systemFont(ofSize: Values.mediumFontSize) | ||
|  |         result.themeTextColor = .textSecondary | ||
|  |          | ||
|  |         return result | ||
|  |     }() | ||
|  |      | ||
|  |     private let separator: UIView = UIView.separator() | ||
|  |      | ||
|  |     // MARK: - Initialization | ||
|  |      | ||
|  |     override init(reuseIdentifier: String?) { | ||
|  |         super.init(reuseIdentifier: reuseIdentifier) | ||
|  |          | ||
|  |         self.backgroundView = UIView() | ||
|  |         self.backgroundView?.themeBackgroundColor = .backgroundPrimary | ||
|  |          | ||
|  |         addSubview(stackView) | ||
|  |         addSubview(separator) | ||
|  |          | ||
|  |         stackView.addArrangedSubview(titleLabel) | ||
|  |          | ||
|  |         setupLayout() | ||
|  |     } | ||
|  |      | ||
|  |     required init?(coder: NSCoder) { | ||
|  |         fatalError("use init(reuseIdentifier:) instead") | ||
|  |     } | ||
|  |      | ||
|  |     private func setupLayout() { | ||
|  |         stackView.pin(to: self) | ||
|  |          | ||
|  |         separator.pin(.left, to: .left, of: self) | ||
|  |         separator.pin(.right, to: .right, of: self) | ||
|  |         separator.pin(.bottom, to: .bottom, of: self) | ||
|  |     } | ||
|  |      | ||
|  |     // MARK: - Content | ||
|  |      | ||
| 
											3 years ago
										 |     public func update( | ||
| 
											3 years ago
										 |         style: SessionCell.Style = .rounded, | ||
| 
											3 years ago
										 |         title: String?, | ||
|  |         hasSeparator: Bool | ||
|  |     ) { | ||
| 
											3 years ago
										 |         let titleIsEmpty: Bool = (title ?? "").isEmpty | ||
| 
											3 years ago
										 |         let edgePadding: CGFloat = { | ||
|  |             switch style { | ||
|  |                 case .rounded: | ||
|  |                     // Align to the start of the text in the cell | ||
|  |                     return (Values.largeSpacing + Values.mediumSpacing) | ||
|  |                  | ||
| 
											3 years ago
										 |                 case .edgeToEdge, .roundedEdgeToEdge: return Values.largeSpacing | ||
| 
											3 years ago
										 |             } | ||
|  |         }() | ||
| 
											3 years ago
										 |          | ||
|  |         titleLabel.text = title | ||
|  |         titleLabel.isHidden = titleIsEmpty | ||
|  |         stackView.layoutMargins = UIEdgeInsets( | ||
|  |             top: (titleIsEmpty ? Values.verySmallSpacing : Values.mediumSpacing), | ||
| 
											3 years ago
										 |             left: edgePadding, | ||
| 
											3 years ago
										 |             bottom: (titleIsEmpty ? Values.verySmallSpacing : Values.mediumSpacing), | ||
| 
											3 years ago
										 |             right: edgePadding | ||
| 
											3 years ago
										 |         ) | ||
|  |         emptyHeightConstraint.isActive = titleIsEmpty | ||
|  |         filledHeightConstraint.isActive = !titleIsEmpty | ||
| 
											3 years ago
										 |         separator.isHidden = (style == .rounded || !hasSeparator) | ||
| 
											3 years ago
										 |          | ||
|  |         self.layoutIfNeeded() | ||
|  |     } | ||
|  | } |