mirror of
https://github.com/lux-tel/session-ios.git
synced 2026-10-30 20:38:32 +00:00
• Added the SwiftUI `SessionAsyncImage` (SwiftUI version of the `SessionImageView`) • Removed some redundant theme logic from the share extension • Updated the placeholder icon to use the `ImageDataManager` • Marked a bunch of functions and closures which should always run on the main thread as `@MainActor` • Fixed a bug where the CallVC would load display pictures • Fixed a crash when accessing the nav stack too early
92 lines
2.9 KiB
Swift
92 lines
2.9 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import UIKit
|
|
import SessionUIKit
|
|
import SessionUtilitiesKit
|
|
|
|
/// Shown when the user taps a profile picture in the conversation settings.
|
|
final class ProfilePictureVC: BaseVC {
|
|
private let dependencies: Dependencies
|
|
private let imageSource: ImageDataManager.DataSource
|
|
private let snTitle: String
|
|
|
|
private var imageSize: CGFloat { (UIScreen.main.bounds.width - (2 * Values.largeSpacing)) }
|
|
|
|
// MARK: - UI
|
|
|
|
private lazy var fallbackView: UIView = {
|
|
let result: UIView = UIView()
|
|
result.clipsToBounds = true
|
|
result.themeBackgroundColor = .backgroundSecondary
|
|
result.layer.cornerRadius = (imageSize / 2)
|
|
result.isHidden = true
|
|
result.set(.width, to: imageSize)
|
|
result.set(.height, to: imageSize)
|
|
|
|
return result
|
|
}()
|
|
|
|
private lazy var imageView: SessionImageView = {
|
|
let result: SessionImageView = SessionImageView(
|
|
dataManager: dependencies[singleton: .imageDataManager]
|
|
)
|
|
result.clipsToBounds = true
|
|
result.contentMode = .scaleAspectFill
|
|
result.layer.cornerRadius = (imageSize / 2)
|
|
result.loadImage(imageSource)
|
|
result.set(.width, to: imageSize)
|
|
result.set(.height, to: imageSize)
|
|
|
|
return result
|
|
}()
|
|
|
|
// MARK: - Initialization
|
|
|
|
init(imageSource: ImageDataManager.DataSource, title: String, using dependencies: Dependencies) {
|
|
self.dependencies = dependencies
|
|
self.imageSource = imageSource
|
|
self.snTitle = title
|
|
|
|
super.init(nibName: nil, bundle: nil)
|
|
}
|
|
|
|
override init(nibName: String?, bundle: Bundle?) {
|
|
preconditionFailure("Use init(image:) instead.")
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
preconditionFailure("Use init(coder:) instead.")
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
view.themeBackgroundColor = .backgroundPrimary
|
|
|
|
setNavBarTitle(snTitle)
|
|
|
|
// Close button
|
|
let closeButton = UIBarButtonItem(
|
|
image: #imageLiteral(resourceName: "X").withRenderingMode(.alwaysTemplate),
|
|
style: .plain,
|
|
target: self,
|
|
action: #selector(close)
|
|
)
|
|
closeButton.themeTintColor = .textPrimary
|
|
navigationItem.leftBarButtonItem = closeButton
|
|
|
|
view.addSubview(fallbackView)
|
|
view.addSubview(imageView)
|
|
|
|
fallbackView.center(in: view)
|
|
imageView.center(in: view)
|
|
|
|
// Gesture recognizer
|
|
let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close))
|
|
swipeGestureRecognizer.direction = .down
|
|
view.addGestureRecognizer(swipeGestureRecognizer)
|
|
}
|
|
|
|
@objc private func close() {
|
|
presentingViewController?.dismiss(animated: true, completion: nil)
|
|
}
|
|
}
|