Adoption of ConversationAvatarView2 in many key locations. This isn't exhaustive, but it's mostly there. Some work left to be done around ConversationAvatarView2 data source tweaks.
103 lines
2.2 KiB
Swift
103 lines
2.2 KiB
Swift
//
|
|
// Copyright (c) 2021 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@objc
|
|
open class AvatarImageView: UIImageView, CVView {
|
|
|
|
@objc
|
|
public var shouldDeactivateConstraints = false
|
|
|
|
public init() {
|
|
super.init(frame: .zero)
|
|
self.configureView()
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
self.configureView()
|
|
}
|
|
|
|
required public init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
self.configureView()
|
|
}
|
|
|
|
public override init(image: UIImage?) {
|
|
super.init(image: image)
|
|
self.configureView()
|
|
}
|
|
|
|
public init(shouldDeactivateConstraints: Bool) {
|
|
self.shouldDeactivateConstraints = shouldDeactivateConstraints
|
|
super.init(frame: .zero)
|
|
self.configureView()
|
|
}
|
|
|
|
func configureView() {
|
|
self.autoPinToSquareAspectRatio()
|
|
|
|
self.layer.minificationFilter = .trilinear
|
|
self.layer.magnificationFilter = .trilinear
|
|
self.layer.masksToBounds = true
|
|
|
|
self.contentMode = .scaleToFill
|
|
}
|
|
|
|
override public func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
layer.cornerRadius = frame.size.width / 2
|
|
}
|
|
|
|
public override func updateConstraints() {
|
|
super.updateConstraints()
|
|
|
|
if shouldDeactivateConstraints {
|
|
deactivateAllConstraints()
|
|
}
|
|
}
|
|
|
|
public func reset() {
|
|
self.image = nil
|
|
}
|
|
}
|
|
|
|
// MARK: -
|
|
|
|
@objc
|
|
public class AvatarImageButton: UIButton {
|
|
|
|
// MARK: - Button Overrides
|
|
|
|
override public func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
|
|
layer.cornerRadius = frame.size.width / 2
|
|
}
|
|
|
|
override public func setImage(_ image: UIImage?, for state: UIControl.State) {
|
|
ensureViewConfigured()
|
|
super.setImage(image, for: state)
|
|
}
|
|
|
|
// MARK: Private
|
|
|
|
var hasBeenConfigured = false
|
|
func ensureViewConfigured() {
|
|
guard !hasBeenConfigured else {
|
|
return
|
|
}
|
|
hasBeenConfigured = true
|
|
|
|
autoPinToSquareAspectRatio()
|
|
|
|
layer.minificationFilter = .trilinear
|
|
layer.magnificationFilter = .trilinear
|
|
layer.masksToBounds = true
|
|
|
|
contentMode = .scaleToFill
|
|
}
|
|
}
|