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.
		
		
		
		
		
			
		
			
	
	
		
			83 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			83 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			Swift
		
	
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								class BaseVC : UIViewController {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    private var hasGradient = false
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
								    override var preferredStatusBarStyle: UIStatusBarStyle { return isLightMode ? .default : .lightContent }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    lazy var navBarTitleLabel: UILabel = {
							 | 
						||
| 
								 | 
							
								        let result = UILabel()
							 | 
						||
| 
								 | 
							
								        result.textColor = Colors.text
							 | 
						||
| 
								 | 
							
								        result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
							 | 
						||
| 
								 | 
							
								        result.alpha = 1
							 | 
						||
| 
								 | 
							
								        result.textAlignment = .center
							 | 
						||
| 
								 | 
							
								        return result
							 | 
						||
| 
								 | 
							
								    }()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    lazy var crossfadeLabel: UILabel = {
							 | 
						||
| 
								 | 
							
								        let result = UILabel()
							 | 
						||
| 
								 | 
							
								        result.textColor = Colors.text
							 | 
						||
| 
								 | 
							
								        result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
							 | 
						||
| 
								 | 
							
								        result.alpha = 0
							 | 
						||
| 
								 | 
							
								        result.textAlignment = .center
							 | 
						||
| 
								 | 
							
								        return result
							 | 
						||
| 
								 | 
							
								    }()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    override func viewDidLoad() {
							 | 
						||
| 
								 | 
							
								        setNeedsStatusBarAppearanceUpdate()
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeChangedNotification(_:)), name: .appModeChanged, object: nil)
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    internal func setUpGradientBackground() {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        hasGradient = true
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        view.backgroundColor = .clear
							 | 
						||
| 
								 | 
							
								        let gradient = Gradients.defaultLokiBackground
							 | 
						||
| 
								 | 
							
								        view.setGradient(gradient)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    internal func setUpNavBarStyle() {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        guard let navigationBar = navigationController?.navigationBar else { return }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								        navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
							 | 
						||
| 
								 | 
							
								        navigationBar.shadowImage = UIImage()
							 | 
						||
| 
								 | 
							
								        navigationBar.isTranslucent = false
							 | 
						||
| 
								 | 
							
								        navigationBar.barTintColor = Colors.navigationBarBackground
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    internal func setNavBarTitle(_ title: String, customFontSize: CGFloat? = nil) {
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								        let container = UIView()
							 | 
						||
| 
								 | 
							
								        navBarTitleLabel.text = title
							 | 
						||
| 
								 | 
							
								        crossfadeLabel.text = title
							 | 
						||
| 
								 | 
							
								        if let customFontSize = customFontSize {
							 | 
						||
| 
								 | 
							
								            navBarTitleLabel.font = .boldSystemFont(ofSize: customFontSize)
							 | 
						||
| 
								 | 
							
								            crossfadeLabel.font = .boldSystemFont(ofSize: customFontSize)
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        container.addSubview(navBarTitleLabel)
							 | 
						||
| 
								 | 
							
								        navBarTitleLabel.pin(to: container)
							 | 
						||
| 
								 | 
							
								        container.addSubview(crossfadeLabel)
							 | 
						||
| 
								 | 
							
								        crossfadeLabel.pin(to: container)
							 | 
						||
| 
								 | 
							
								        navigationItem.titleView = container
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    internal func setUpNavBarSessionIcon() {
							 | 
						||
| 
								 | 
							
								        let logoImageView = UIImageView()
							 | 
						||
| 
								 | 
							
								        logoImageView.image = #imageLiteral(resourceName: "SessionGreen32")
							 | 
						||
| 
								 | 
							
								        logoImageView.contentMode = .scaleAspectFit
							 | 
						||
| 
								 | 
							
								        logoImageView.set(.width, to: 32)
							 | 
						||
| 
								 | 
							
								        logoImageView.set(.height, to: 32)
							 | 
						||
| 
								 | 
							
								        navigationItem.titleView = logoImageView
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								    deinit {
							 | 
						||
| 
								 | 
							
								        NotificationCenter.default.removeObserver(self)
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
							 | 
						||
| 
								 | 
							
								        // TODO: Post an appModeChanged notification?
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											5 years ago
										 
									 | 
							
								    @objc internal func handleAppModeChangedNotification(_ notification: Notification) {
							 | 
						||
| 
								 | 
							
								        if hasGradient {
							 | 
						||
| 
								 | 
							
								            setUpGradientBackground() // Re-do the gradient
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 
											6 years ago
										 
									 | 
							
								}
							 |