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
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			81 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Swift
		
	
| 
											4 years ago
										 | // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. | ||
|  | 
 | ||
|  | import UIKit | ||
| 
											3 years ago
										 | import SessionUIKit | ||
| 
											4 years ago
										 | 
 | ||
| 
											2 years ago
										 | final class RoundIconButton: UIView { | ||
|  |     private let onTap: () -> () | ||
| 
											5 years ago
										 |      | ||
| 
											4 years ago
										 |     // MARK: - Settings | ||
|  |      | ||
| 
											5 years ago
										 |     private static let size: CGFloat = 40 | ||
|  |     private static let iconSize: CGFloat = 16 | ||
|  |      | ||
| 
											4 years ago
										 |     // MARK: - Lifecycle | ||
|  |      | ||
| 
											2 years ago
										 |     init(image: UIImage?, onTap: @escaping () -> ()) { | ||
|  |         self.onTap = onTap | ||
| 
											3 years ago
										 |          | ||
| 
											5 years ago
										 |         super.init(frame: CGRect.zero) | ||
| 
											3 years ago
										 |          | ||
| 
											2 years ago
										 |         setUpViewHierarchy(image: image) | ||
| 
											5 years ago
										 |     } | ||
|  |      | ||
|  |     override init(frame: CGRect) { | ||
|  |         preconditionFailure("Use init(delegate:) instead.") | ||
|  |     } | ||
|  |      | ||
|  |     required init?(coder: NSCoder) { | ||
|  |         preconditionFailure("Use init(delegate:) instead.") | ||
|  |     } | ||
|  |      | ||
| 
											2 years ago
										 |     private func setUpViewHierarchy(image: UIImage?) { | ||
| 
											5 years ago
										 |         // Background & blur | ||
|  |         let backgroundView = UIView() | ||
| 
											3 years ago
										 |         backgroundView.themeBackgroundColor = .backgroundSecondary | ||
| 
											5 years ago
										 |         backgroundView.alpha = Values.lowOpacity | ||
|  |         addSubview(backgroundView) | ||
|  |         backgroundView.pin(to: self) | ||
| 
											3 years ago
										 |          | ||
| 
											3 years ago
										 |         let blurView = UIVisualEffectView() | ||
| 
											5 years ago
										 |         addSubview(blurView) | ||
|  |         blurView.pin(to: self) | ||
| 
											3 years ago
										 |          | ||
| 
											3 years ago
										 |         ThemeManager.onThemeChange(observer: blurView) { [weak blurView] theme, _ in | ||
|  |             switch theme.interfaceStyle { | ||
|  |                 case .light: blurView?.effect = UIBlurEffect(style: .light) | ||
|  |                 default: blurView?.effect = UIBlurEffect(style: .dark) | ||
|  |             } | ||
|  |         } | ||
|  |          | ||
| 
											5 years ago
										 |         // Size & shape | ||
| 
											2 years ago
										 |         set(.width, to: RoundIconButton.size) | ||
|  |         set(.height, to: RoundIconButton.size) | ||
|  |         layer.cornerRadius = (RoundIconButton.size / 2) | ||
| 
											5 years ago
										 |         layer.masksToBounds = true | ||
| 
											3 years ago
										 |          | ||
| 
											5 years ago
										 |         // Border | ||
| 
											3 years ago
										 |         self.themeBorderColor = .borderSeparator | ||
| 
											5 years ago
										 |         layer.borderWidth = Values.separatorThickness | ||
| 
											3 years ago
										 |          | ||
| 
											5 years ago
										 |         // Icon | ||
| 
											2 years ago
										 |         let iconImageView = UIImageView(image: image) | ||
| 
											3 years ago
										 |         iconImageView.themeTintColor = .textPrimary | ||
| 
											5 years ago
										 |         iconImageView.contentMode = .scaleAspectFit | ||
|  |         addSubview(iconImageView) | ||
|  |         iconImageView.center(in: self) | ||
| 
											2 years ago
										 |         iconImageView.set(.width, to: RoundIconButton.iconSize) | ||
|  |         iconImageView.set(.height, to: RoundIconButton.iconSize) | ||
| 
											3 years ago
										 |          | ||
| 
											5 years ago
										 |         // Gesture recognizer | ||
|  |         let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap)) | ||
|  |         addGestureRecognizer(tapGestureRecognizer) | ||
|  |     } | ||
|  |      | ||
| 
											4 years ago
										 |     // MARK: - Interaction | ||
|  |      | ||
| 
											5 years ago
										 |     @objc private func handleTap() { | ||
| 
											2 years ago
										 |         onTap() | ||
| 
											5 years ago
										 |     } | ||
|  | } |