mirror of https://github.com/oxen-io/session-ios
Merge branch 'mkirk/profile-pic-in-conversation'
commit
945ab7e4a2
@ -1,14 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ConversationHeaderView : UIView
|
||||
|
||||
@property (nonatomic) UILabel *titleLabel;
|
||||
@property (nonatomic) UILabel *subtitleLabel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -1,65 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ConversationHeaderView.h"
|
||||
#import "UIView+OWS.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation ConversationHeaderView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
|
||||
if (self) {
|
||||
self.layoutMargins = UIEdgeInsetsZero;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setBounds:(CGRect)bounds
|
||||
{
|
||||
[super setBounds:bounds];
|
||||
|
||||
[self layoutSubviews];
|
||||
}
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
[super setFrame:frame];
|
||||
|
||||
[self layoutSubviews];
|
||||
}
|
||||
|
||||
- (void)setCenter:(CGPoint)center
|
||||
{
|
||||
[super setCenter:center];
|
||||
|
||||
[self layoutSubviews];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
// We need to manually resize and position the title views;
|
||||
// iOS AutoLayout doesn't work inside navigation bar items.
|
||||
const int kTitleVSpacing = 0.f;
|
||||
const int kTitleHMargin = 0.f;
|
||||
CGFloat titleHeight = ceil([self.titleLabel sizeThatFits:CGSizeZero].height);
|
||||
CGFloat subtitleHeight = ceil([self.subtitleLabel sizeThatFits:CGSizeZero].height);
|
||||
CGFloat contentHeight = titleHeight + kTitleVSpacing + subtitleHeight;
|
||||
CGFloat contentWidth = round(self.width - 2 * kTitleHMargin);
|
||||
|
||||
CGFloat y = MAX(0, round((self.height - contentHeight) * 0.5f));
|
||||
self.titleLabel.frame = CGRectMake(kTitleHMargin, y, contentWidth, titleHeight);
|
||||
self.subtitleLabel.frame
|
||||
= CGRectMake(kTitleHMargin, ceil(y + titleHeight + kTitleVSpacing), contentWidth, subtitleHeight);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -0,0 +1,120 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc
|
||||
public protocol ConversationHeaderViewDelegate {
|
||||
func didTapConversationHeaderView(_ conversationHeaderView: ConversationHeaderView)
|
||||
}
|
||||
|
||||
@objc
|
||||
public class ConversationHeaderView: UIStackView {
|
||||
|
||||
public weak var delegate: ConversationHeaderViewDelegate?
|
||||
|
||||
public var attributedTitle: NSAttributedString? {
|
||||
get {
|
||||
return self.titleLabel.attributedText
|
||||
}
|
||||
set {
|
||||
self.titleLabel.attributedText = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var attributedSubtitle: NSAttributedString? {
|
||||
get {
|
||||
return self.subtitleLabel.attributedText
|
||||
}
|
||||
set {
|
||||
self.subtitleLabel.attributedText = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public var avatarImage: UIImage? {
|
||||
get {
|
||||
return self.avatarView.image
|
||||
}
|
||||
set {
|
||||
self.avatarView.image = newValue
|
||||
}
|
||||
}
|
||||
|
||||
public let titlePrimaryFont: UIFont = UIFont.ows_boldFont(withSize: 17)
|
||||
public let titleSecondaryFont: UIFont = UIFont.ows_regularFont(withSize: 9)
|
||||
|
||||
public let subtitleFont: UIFont = UIFont.ows_regularFont(withSize: 12)
|
||||
private let titleLabel: UILabel
|
||||
private let subtitleLabel: UILabel
|
||||
private let avatarView: AvatarImageView
|
||||
|
||||
public required init(thread: TSThread, contactsManager: OWSContactsManager) {
|
||||
|
||||
let avatarView = ConversationAvatarImageView(thread: thread, diameter: 36, contactsManager: contactsManager)
|
||||
self.avatarView = avatarView
|
||||
// remove default border on avatarView
|
||||
avatarView.layer.borderWidth = 0
|
||||
|
||||
titleLabel = UILabel()
|
||||
titleLabel.textColor = .white
|
||||
titleLabel.lineBreakMode = .byTruncatingTail
|
||||
titleLabel.font = titlePrimaryFont
|
||||
titleLabel.setContentHuggingHigh()
|
||||
|
||||
subtitleLabel = UILabel()
|
||||
subtitleLabel.textColor = .white
|
||||
subtitleLabel.lineBreakMode = .byTruncatingTail
|
||||
subtitleLabel.font = subtitleFont
|
||||
subtitleLabel.setContentHuggingHigh()
|
||||
|
||||
let textRows = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
|
||||
textRows.axis = .vertical
|
||||
textRows.alignment = .leading
|
||||
textRows.distribution = .fillProportionally
|
||||
textRows.spacing = 0
|
||||
|
||||
textRows.layoutMargins = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 8)
|
||||
textRows.isLayoutMarginsRelativeArrangement = true
|
||||
|
||||
// low content hugging so that the text rows push container to the right bar button item(s)
|
||||
textRows.setContentHuggingLow()
|
||||
|
||||
super.init(frame: .zero)
|
||||
|
||||
self.layoutMargins = UIEdgeInsets(top: 4, left: 2, bottom: 4, right: 2)
|
||||
self.isLayoutMarginsRelativeArrangement = true
|
||||
|
||||
self.axis = .horizontal
|
||||
self.alignment = .center
|
||||
self.spacing = 0
|
||||
self.addArrangedSubview(avatarView)
|
||||
self.addArrangedSubview(textRows)
|
||||
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapView))
|
||||
self.addGestureRecognizer(tapGesture)
|
||||
}
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
required public override init(frame: CGRect) {
|
||||
fatalError("init(frame:) has not been implemented")
|
||||
}
|
||||
|
||||
public override var intrinsicContentSize: CGSize {
|
||||
// Grow to fill as much of the navbar as possible.
|
||||
return UILayoutFittingExpandedSize
|
||||
}
|
||||
|
||||
// MARK: Delegate Methods
|
||||
|
||||
func didTapView(tapGesture: UITapGestureRecognizer) {
|
||||
guard tapGesture.state == .recognized else {
|
||||
return
|
||||
}
|
||||
|
||||
self.delegate?.didTapConversationHeaderView(self)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue