2021-02-21 22:47:20 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 New Vector Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Reusable
|
|
|
|
|
2021-06-04 14:13:12 +00:00
|
|
|
final class RoomAvatarView: AvatarView, NibOwnerLoadable {
|
2021-02-21 22:47:20 +00:00
|
|
|
|
|
|
|
// MARK: - Properties
|
|
|
|
|
|
|
|
// MARK: Outlets
|
|
|
|
|
|
|
|
@IBOutlet private weak var cameraBadgeContainerView: UIView!
|
|
|
|
|
|
|
|
// MARK: Setup
|
|
|
|
|
|
|
|
private func commonInit() {
|
|
|
|
}
|
|
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
super.init(coder: aDecoder)
|
|
|
|
self.loadNibContent()
|
|
|
|
self.commonInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
super.init(frame: frame)
|
|
|
|
self.loadNibContent()
|
|
|
|
self.commonInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Lifecycle
|
|
|
|
|
|
|
|
override func layoutSubviews() {
|
|
|
|
super.layoutSubviews()
|
|
|
|
|
|
|
|
self.avatarImageView.layer.cornerRadius = self.avatarImageView.bounds.height/2
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Public
|
|
|
|
|
2021-06-04 14:13:12 +00:00
|
|
|
override func fill(with viewData: AvatarViewDataProtocol) {
|
2021-02-21 22:47:20 +00:00
|
|
|
self.updateAvatarImageView(with: viewData)
|
|
|
|
|
|
|
|
// Fix layoutSubviews not triggered issue
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
|
|
self.setNeedsLayout()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 14:13:12 +00:00
|
|
|
// MARK: - Overrides
|
2021-02-21 22:47:20 +00:00
|
|
|
|
2021-06-04 14:13:12 +00:00
|
|
|
override func updateAccessibilityTraits() {
|
|
|
|
if self.isUserInteractionEnabled {
|
|
|
|
self.vc_setupAccessibilityTraitsButton(withTitle: VectorL10n.roomAvatarViewAccessibilityLabel, hint: VectorL10n.roomAvatarViewAccessibilityHint, isEnabled: true)
|
2021-02-21 22:47:20 +00:00
|
|
|
} else {
|
2021-06-04 14:13:12 +00:00
|
|
|
self.vc_setupAccessibilityTraitsImage(withTitle: VectorL10n.roomAvatarViewAccessibilityLabel)
|
2021-02-21 22:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 14:13:12 +00:00
|
|
|
override func updateAvatarImageView(with viewData: AvatarViewDataProtocol) {
|
|
|
|
super.updateAvatarImageView(with: viewData)
|
2021-02-21 22:47:20 +00:00
|
|
|
|
2021-06-04 14:13:12 +00:00
|
|
|
self.cameraBadgeContainerView.isHidden = viewData.avatarUrl != nil
|
2021-02-21 22:47:20 +00:00
|
|
|
}
|
|
|
|
}
|