mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
# Conflicts: # Session.xcodeproj/project.pbxproj # Session/Conversations/ConversationVC+Interaction.swift # Session/Conversations/ConversationVC.swift # Session/Conversations/Settings/ThreadSettingsViewModel.swift # Session/Home/App Review/AppReviewPromptModel.swift # Session/Home/HomeViewModel.swift # Session/Media Viewing & Editing/MessageInfoScreen.swift # Session/Meta/AppDelegate.swift # Session/Settings/DeveloperSettings/DeveloperSettingsProViewModel.swift # Session/Settings/SettingsViewModel.swift # Session/Shared/BaseVC.swift # Session/Utilities/UIContextualAction+Utilities.swift # SessionMessagingKit/Database/Models/SessionThread.swift # SessionMessagingKit/SessionPro/SessionProPaymentScreenContent.swift # SessionMessagingKit/SessionPro/SessionProSettingsViewModel.swift # SessionMessagingKit/SessionPro/SessionProState.swift # SessionMessagingKit/Shared Models/SessionThreadViewModel.swift # SessionNotificationServiceExtension/NotificationServiceExtension.swift # SessionUIKit/Components/Input View/InputView.swift # SessionUIKit/Components/SwiftUI/ProCTAModal.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen+CancelPlan.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen+Models.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen+Purchase.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen+Renew.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen+RequestRefund.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen+UpdatePlan.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPaymentScreen.swift # SessionUIKit/Screens/Settings/SessionProSettings/SessionProPlanUpdatedScreen.swift # SessionUIKit/Style Guide/Constants+Apple.swift # SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentApprovalViewController.swift # SignalUtilitiesKit/Media Viewing & Editing/Attachment Approval/AttachmentTextToolbar.swift
121 lines
4.1 KiB
Swift
121 lines
4.1 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionUIKit
|
|
import Combine
|
|
import SessionUtilitiesKit
|
|
|
|
public class BaseVC: UIViewController {
|
|
private var proObservationTask: Task<Void, Never>?
|
|
public var onViewWillAppear: ((UIViewController) -> Void)?
|
|
public var onViewWillDisappear: ((UIViewController) -> Void)?
|
|
public var onViewDidDisappear: ((UIViewController) -> Void)?
|
|
|
|
public override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
return ThemeManager.currentTheme.statusBarStyle
|
|
}
|
|
|
|
lazy var navBarTitleLabel: UILabel = {
|
|
let result = UILabel()
|
|
result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
|
|
result.themeTextColor = .textPrimary
|
|
result.textAlignment = .center
|
|
result.alpha = 1
|
|
|
|
return result
|
|
}()
|
|
|
|
lazy var crossfadeLabel: UILabel = {
|
|
let result = UILabel()
|
|
result.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
|
|
result.themeTextColor = .textPrimary
|
|
result.textAlignment = .center
|
|
result.alpha = 0
|
|
|
|
return result
|
|
}()
|
|
|
|
deinit {
|
|
proObservationTask?.cancel()
|
|
}
|
|
|
|
public override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
navigationItem.backButtonTitle = ""
|
|
view.themeBackgroundColor = .backgroundPrimary
|
|
|
|
setNeedsStatusBarAppearanceUpdate()
|
|
}
|
|
|
|
public override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
|
|
/// Apply the nav styling in `viewWillAppear` instead of `viewDidLoad` as it's possible the nav stack isn't fully setup
|
|
/// and could crash when trying to access it (whereas by the time `viewWillAppear` is called it should be setup)
|
|
ThemeManager.applyNavigationStylingIfNeeded(to: self)
|
|
onViewWillAppear?(self)
|
|
}
|
|
|
|
public override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
|
|
onViewWillDisappear?(self)
|
|
}
|
|
|
|
public override func viewDidDisappear(_ animated: Bool) {
|
|
super.viewDidDisappear(animated)
|
|
|
|
onViewDidDisappear?(self)
|
|
}
|
|
|
|
internal func setNavBarTitle(_ title: String, customFontSize: CGFloat? = nil) {
|
|
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)
|
|
container.addSubview(crossfadeLabel)
|
|
|
|
navBarTitleLabel.pin(to: container)
|
|
crossfadeLabel.pin(to: container)
|
|
|
|
navigationItem.titleView = container
|
|
}
|
|
|
|
internal func setUpNavBarSessionHeading(sessionProUIManager: SessionProUIManagerType) {
|
|
let headingImageView = UIImageView(
|
|
image: UIImage(named: "SessionHeading")?
|
|
.withRenderingMode(.alwaysTemplate)
|
|
)
|
|
headingImageView.themeTintColor = .textPrimary
|
|
headingImageView.contentMode = .scaleAspectFit
|
|
headingImageView.set(.width, to: 140)
|
|
headingImageView.set(.height, to: Values.mediumFontSize)
|
|
|
|
let sessionProBadge: SessionProBadge = SessionProBadge(size: .medium)
|
|
sessionProBadge.isHidden = !sessionProUIManager.currentUserIsCurrentlyPro
|
|
|
|
let stackView: UIStackView = UIStackView(arrangedSubviews: [ headingImageView, sessionProBadge ])
|
|
stackView.axis = .horizontal
|
|
stackView.alignment = .center
|
|
stackView.spacing = 0
|
|
|
|
proObservationTask?.cancel()
|
|
proObservationTask = Task.detached(priority: .userInitiated) { [weak sessionProBadge] in
|
|
for await isPro in sessionProUIManager.currentUserIsPro {
|
|
await MainActor.run { [weak sessionProBadge] in
|
|
sessionProBadge?.isHidden = !isPro
|
|
}
|
|
}
|
|
}
|
|
|
|
navigationItem.titleView = stackView
|
|
}
|
|
}
|