2020-02-20 04:37:17 +01:00
|
|
|
|
|
|
|
class BaseVC : UIViewController {
|
2020-08-24 03:28:56 +02:00
|
|
|
private var hasGradient = false
|
2020-02-20 04:37:17 +01:00
|
|
|
|
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle { return isLightMode ? .default : .lightContent }
|
|
|
|
|
2020-06-25 09:36:32 +02:00
|
|
|
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
|
|
|
|
}()
|
|
|
|
|
2020-02-20 04:37:17 +01:00
|
|
|
override func viewDidLoad() {
|
|
|
|
setNeedsStatusBarAppearanceUpdate()
|
2020-08-24 03:28:56 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(handleAppModeChangedNotification(_:)), name: .appModeChanged, object: nil)
|
2022-04-11 08:22:09 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive(_:)), name: .OWSApplicationDidBecomeActive, object: nil)
|
2020-03-23 07:09:59 +01:00
|
|
|
}
|
2021-10-19 02:03:59 +02:00
|
|
|
|
|
|
|
internal func ensureWindowBackground() {
|
|
|
|
let appMode = AppModeManager.shared.currentAppMode
|
|
|
|
switch appMode {
|
|
|
|
case .light:
|
|
|
|
UIApplication.shared.delegate?.window??.backgroundColor = .white
|
|
|
|
case .dark:
|
|
|
|
UIApplication.shared.delegate?.window??.backgroundColor = .black
|
|
|
|
}
|
|
|
|
}
|
2020-03-23 07:09:59 +01:00
|
|
|
|
2020-05-30 00:20:30 +02:00
|
|
|
internal func setUpGradientBackground() {
|
2020-08-24 03:28:56 +02:00
|
|
|
hasGradient = true
|
2020-05-30 00:20:30 +02:00
|
|
|
view.backgroundColor = .clear
|
2021-01-29 01:46:32 +01:00
|
|
|
let gradient = Gradients.defaultBackground
|
2020-05-30 00:20:30 +02:00
|
|
|
view.setGradient(gradient)
|
|
|
|
}
|
|
|
|
|
|
|
|
internal func setUpNavBarStyle() {
|
2020-08-27 07:06:11 +02:00
|
|
|
guard let navigationBar = navigationController?.navigationBar else { return }
|
2022-03-01 00:25:54 +01:00
|
|
|
|
2021-09-23 04:56:00 +02:00
|
|
|
if #available(iOS 15.0, *) {
|
2021-09-22 07:57:12 +02:00
|
|
|
let appearance = UINavigationBarAppearance()
|
|
|
|
appearance.configureWithOpaqueBackground()
|
|
|
|
appearance.backgroundColor = Colors.navigationBarBackground
|
|
|
|
appearance.shadowColor = .clear
|
|
|
|
navigationBar.standardAppearance = appearance;
|
|
|
|
navigationBar.scrollEdgeAppearance = navigationBar.standardAppearance
|
|
|
|
} else {
|
|
|
|
navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
|
|
|
|
navigationBar.shadowImage = UIImage()
|
|
|
|
navigationBar.isTranslucent = false
|
|
|
|
navigationBar.barTintColor = Colors.navigationBarBackground
|
|
|
|
}
|
2022-03-01 00:25:54 +01:00
|
|
|
|
|
|
|
// Back button (to appear on pushed screen)
|
|
|
|
let backButton = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
|
|
|
|
backButton.tintColor = Colors.text
|
|
|
|
navigationItem.backBarButtonItem = backButton
|
2020-05-30 00:20:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
internal func setNavBarTitle(_ title: String, customFontSize: CGFloat? = nil) {
|
2020-06-25 09:36:32 +02:00
|
|
|
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
|
2020-05-30 00:20:30 +02:00
|
|
|
}
|
2022-01-13 01:41:21 +01:00
|
|
|
|
|
|
|
internal func setUpNavBarSessionHeading() {
|
|
|
|
let headingImageView = UIImageView()
|
2022-03-01 01:34:23 +01:00
|
|
|
headingImageView.tintColor = Colors.text
|
2022-01-13 01:41:21 +01:00
|
|
|
headingImageView.image = UIImage(named: "SessionHeading")?.withRenderingMode(.alwaysTemplate)
|
|
|
|
headingImageView.contentMode = .scaleAspectFit
|
|
|
|
headingImageView.set(.width, to: 150)
|
2022-01-20 05:33:31 +01:00
|
|
|
headingImageView.set(.height, to: Values.mediumFontSize)
|
2022-01-13 01:41:21 +01:00
|
|
|
navigationItem.titleView = headingImageView
|
|
|
|
}
|
2020-05-30 00:20:30 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-03-23 07:09:59 +01:00
|
|
|
deinit {
|
|
|
|
NotificationCenter.default.removeObserver(self)
|
|
|
|
}
|
2022-04-11 08:22:09 +02:00
|
|
|
|
|
|
|
@objc func appDidBecomeActive(_ notification: Notification) {
|
2022-04-20 07:09:33 +02:00
|
|
|
// To be implemented by child class
|
2022-04-11 08:22:09 +02:00
|
|
|
}
|
2020-03-23 07:09:59 +01:00
|
|
|
|
2020-08-24 06:24:44 +02:00
|
|
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
2022-03-21 03:55:51 +01:00
|
|
|
if #available(iOS 13.0, *) {
|
|
|
|
SNLog("Current trait collection: \(UITraitCollection.current), previous trait collection: \(previousTraitCollection)")
|
|
|
|
}
|
2021-12-01 05:05:30 +01:00
|
|
|
if LKAppModeUtilities.isSystemDefault {
|
|
|
|
NotificationCenter.default.post(name: .appModeChanged, object: nil)
|
|
|
|
}
|
2020-08-24 06:24:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-24 03:28:56 +02:00
|
|
|
@objc internal func handleAppModeChangedNotification(_ notification: Notification) {
|
|
|
|
if hasGradient {
|
|
|
|
setUpGradientBackground() // Re-do the gradient
|
|
|
|
}
|
2021-10-19 02:03:59 +02:00
|
|
|
ensureWindowBackground()
|
2020-08-24 03:28:56 +02:00
|
|
|
}
|
2020-02-20 04:37:17 +01:00
|
|
|
}
|