mirror of https://github.com/oxen-io/session-ios
WIP moving to stackview backed header view in conversation view
- iOS10 with large titles doesn't truncatepull/1/head
parent
3d766e4cf8
commit
b1bff71145
@ -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,125 @@
|
||||
//
|
||||
// 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
|
||||
// self.layoutIfNeeded()
|
||||
// self.titleLabel.sizeToFit()
|
||||
// self.sizeToFit()
|
||||
}
|
||||
}
|
||||
|
||||
public var attributedSubtitle: NSAttributedString? {
|
||||
get {
|
||||
return self.subtitleLabel.attributedText
|
||||
}
|
||||
set {
|
||||
self.subtitleLabel.attributedText = newValue
|
||||
// self.layoutIfNeeded()
|
||||
// self.subtitleLabel.sizeToFit()
|
||||
// self.sizeToFit()
|
||||
}
|
||||
}
|
||||
|
||||
public let titlePrimaryFont: UIFont = UIFont.ows_boldFont(withSize: 20)
|
||||
public let titleSecondaryFont: UIFont = UIFont.ows_regularFont(withSize: 11)
|
||||
|
||||
public let subtitleFont: UIFont = UIFont.ows_regularFont(withSize: 12)
|
||||
// public let columns: UIStackView
|
||||
// public let textRows: UIStackView
|
||||
private let titleLabel: UILabel
|
||||
private let subtitleLabel: UILabel
|
||||
|
||||
override init(frame: CGRect) {
|
||||
|
||||
// TODO
|
||||
// let avatarView: UIImageView = UIImageView()
|
||||
|
||||
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()
|
||||
|
||||
// textRows = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel])
|
||||
// textRows.axis = .vertical
|
||||
// textRows.alignment = .leading
|
||||
|
||||
// columns = UIStackView(arrangedSubviews: [avatarView, textRows])
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
// needed for proper layout on iOS10
|
||||
self.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
self.axis = .vertical
|
||||
self.distribution = .fillProportionally
|
||||
self.alignment = .leading
|
||||
self.spacing = 0
|
||||
self.addArrangedSubview(titleLabel)
|
||||
self.addArrangedSubview(subtitleLabel)
|
||||
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapView))
|
||||
self.addGestureRecognizer(tapGesture)
|
||||
|
||||
// titleLabel.setCompressionResistanceHigh()
|
||||
// subtitleLabel.setCompressionResistanceHigh()
|
||||
// self.setCompressionResistanceHigh()
|
||||
// self.setContentHuggingLow()
|
||||
|
||||
// self.layoutIfNeeded()
|
||||
// sizeToFit()
|
||||
//
|
||||
// self.translatesAutoresizingMaskIntoConstraints = true
|
||||
|
||||
// self.addSubview(columns)
|
||||
// columns.autoPinEdgesToSuperviewEdges()
|
||||
// self.addRedBorderRecursively()
|
||||
}
|
||||
|
||||
required public init(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
public override var intrinsicContentSize: CGSize {
|
||||
// Grow to fill as much of the navbar as possible.
|
||||
if #available(iOS 11, *) {
|
||||
return UILayoutFittingExpandedSize
|
||||
} else {
|
||||
return super.intrinsicContentSize
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Delegate Methods
|
||||
|
||||
func didTapView(tapGesture: UITapGestureRecognizer) {
|
||||
guard tapGesture.state == .recognized else {
|
||||
return
|
||||
}
|
||||
|
||||
self.delegate?.didTapConversationHeaderView(self)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue