Last active
April 15, 2020 14:05
-
-
Save b-onc/5778255826b21cd6930e3556bb2b7cde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import StreamChat | |
import RxSwift | |
class MessagesViewController: ChatViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
navigationItem.largeTitleDisplayMode = .never | |
setupNavigationBar() | |
} | |
private func setupNavigationBar() { | |
guard let channel = presenter?.channel else { | |
return | |
} | |
navigationItem.rightBarButtonItem = nil | |
let chatNavigationTitleView = ChatNavigationTitleView() | |
chatNavigationTitleView.update(title: channel.name ?? "", imageURL: channel.imageURL) | |
navigationItem.titleView = chatNavigationTitleView | |
} | |
} | |
class ChatNavigationTitleView: UIView { | |
private let avatar = AvatarView(cornerRadius: 12) | |
private let titleLabel = UILabel() | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
setupUI() | |
} | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) | |
setupUI() | |
} | |
private func setupUI() { | |
addSubview(avatar) | |
avatar.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(titleLabel) | |
titleLabel.translatesAutoresizingMaskIntoConstraints = false | |
titleLabel.font = .systemFont(ofSize: 12) | |
NSLayoutConstraint.activate([ | |
avatar.centerXAnchor.constraint(equalTo: centerXAnchor), | |
avatar.topAnchor.constraint(equalTo: topAnchor), | |
avatar.leftAnchor.constraint(equalTo: leftAnchor), | |
avatar.rightAnchor.constraint(equalTo: rightAnchor), | |
titleLabel.topAnchor.constraint(equalTo: avatar.bottomAnchor, constant: 0), | |
titleLabel.centerXAnchor.constraint(equalTo: avatar.centerXAnchor), | |
titleLabel.bottomAnchor.constraint(equalTo: bottomAnchor), | |
]) | |
} | |
func update(title: String, imageURL: URL?) { | |
titleLabel.text = title | |
titleLabel.sizeToFit() | |
avatar.update(with: imageURL, name: title, baseColor: .clear) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment