This commit is contained in:
Michael Kirk 2018-04-26 10:12:21 -04:00 committed by Matthew Chen
parent 55e19b55b3
commit b702695793
4 changed files with 74 additions and 76 deletions

View File

@ -60,16 +60,19 @@ public class ConversationHeaderView: UIStackView {
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: 4, bottom: 0, right: 4)
textRows.isLayoutMarginsRelativeArrangement = true
@ -101,12 +104,8 @@ public class ConversationHeaderView: UIStackView {
}
public override var intrinsicContentSize: CGSize {
if #available(iOS 11, *) {
// Grow to fill as much of the navbar as possible.
return UILayoutFittingExpandedSize
} else {
return super.intrinsicContentSize
}
// Grow to fill as much of the navbar as possible.
return UILayoutFittingExpandedSize
}
// MARK: Delegate Methods

View File

@ -488,6 +488,14 @@ typedef enum : NSUInteger {
[self createConversationScrollButtons];
[self createHeaderViews];
if (@available(iOS 11, *)) {
// We use the default back button from home view, which animates nicely with interactive transitions like the
// interactive pop gesture and the "slide left" for info.
} else {
// On iOS9/10 the default back button is too wide, so we use a custom back button. This doesn't animate nicely
// with interactive transitions, but has the appropriate width.
[self createBackButton];
}
[self addNotificationListeners];
[self loadDraftInCompose];
@ -1122,16 +1130,28 @@ typedef enum : NSUInteger {
ConversationHeaderView *headerView =
[[ConversationHeaderView alloc] initWithThread:self.thread contactsManager:self.contactsManager];
headerView.delegate = self;
self.headerView = headerView;
headerView.delegate = self;
self.navigationItem.titleView = headerView;
if (@available(iOS 11, *)) {
// Do nothing, we use autolayout/intrinsic content size to grow
} else {
// Request "full width" title; the navigation bar will truncate this
// to fit between the left and right buttons.
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGRect headerFrame = CGRectMake(0, 0, screenSize.width, 44);
headerView.frame = headerFrame;
}
#ifdef USE_DEBUG_UI
[self.headerView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(navigationTitleLongPressed:)]];
[headerView addGestureRecognizer:[[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(navigationTitleLongPressed:)]];
#endif
[self updateNavigationBarSubtitleLabel];
}
@ -1172,20 +1192,6 @@ typedef enum : NSUInteger {
- (void)updateBarButtonItems
{
if (self.navigationItem.titleView == nil) {
if (@available(iOS 11, *)) {
// Do nothing, we use autolayout/intrinsic content size to grow
} else {
// Request "full width" title; the navigation bar will truncate this
// to fit between the left and right buttons.
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGRect headerFrame = CGRectMake(0, 0, screenSize.width, 44);
self.headerView.frame = headerFrame;
}
self.navigationItem.titleView = self.headerView;
}
if (self.userLeftGroup) {
self.navigationItem.rightBarButtonItems = @[];
return;

View File

@ -85,21 +85,13 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
navigationOrientation: .horizontal,
options: [UIPageViewControllerOptionInterPageSpacingKey: kSpacingBetweenItems])
// needed for proper layout on iOS10
// needed for proper layout on iOS9/10
headerView.translatesAutoresizingMaskIntoConstraints = false
headerView.axis = .vertical
headerView.alignment = .center
headerView.addArrangedSubview(headerNameLabel)
headerView.addArrangedSubview(headerDateLabel)
Logger.debug("\(self.logTag) in \(#function) 1 headerView.frame: \(headerView.frame)")
// headerView.layoutIfNeeded()
Logger.debug("\(self.logTag) in \(#function) 2 headerView.frame: \(headerView.frame)")
// headerView.sizeToFit()
Logger.debug("\(self.logTag) in \(#function) 3 headerView.frame: \(headerView.frame)")
self.dataSource = self
self.delegate = self

View File

@ -4,6 +4,46 @@
import UIKit
@objc
public class AvatarImageView: UIImageView {
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()
}
override init(image: UIImage?) {
super.init(image: image)
self.configureView()
}
func configureView() {
self.autoPinToSquareAspectRatio()
self.layer.minificationFilter = kCAFilterTrilinear
self.layer.magnificationFilter = kCAFilterTrilinear
self.layer.borderWidth = 0.5
self.layer.masksToBounds = true
self.contentMode = .scaleToFill
}
override public func layoutSubviews() {
self.layer.borderColor = UIColor.black.cgColor.copy(alpha: 0.15)
self.layer.cornerRadius = self.frame.size.width / 2
}
}
/// Avatar View which updates itself as necessary when the profile, contact, or group picture changes.
@objc
public class ConversationAvatarImageView: AvatarImageView {
@ -58,8 +98,8 @@ public class ConversationAvatarImageView: AvatarImageView {
func handleSignalAccountsChanged(notification: Notification) {
Logger.debug("\(self.logTag) in \(#function)")
// It would be nice if we could do this only if *this* user changed,
// but currently this is a course grained notification.
// PERF: It would be nice if we could do this only if *this* user's SignalAccount changed,
// but currently this is only a course grained notification.
self.updateImage()
}
@ -78,7 +118,7 @@ public class ConversationAvatarImageView: AvatarImageView {
return
}
guard recipientId == recipientId else {
guard recipientId == changedRecipientId else {
// not this avatar
return
}
@ -116,42 +156,3 @@ public class ConversationAvatarImageView: AvatarImageView {
self.image = OWSAvatarBuilder.buildImage(thread: thread, diameter: diameter, contactsManager: contactsManager)
}
}
@objc
public class AvatarImageView: UIImageView {
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()
}
override init(image: UIImage?) {
super.init(image: image)
self.configureView()
}
func configureView() {
self.autoPinToSquareAspectRatio()
self.layer.minificationFilter = kCAFilterTrilinear
self.layer.magnificationFilter = kCAFilterTrilinear
self.layer.borderWidth = 0.5
self.layer.masksToBounds = true
self.contentMode = .scaleToFill
}
override public func layoutSubviews() {
self.layer.borderColor = UIColor.black.cgColor.copy(alpha: 0.15)
self.layer.cornerRadius = self.frame.size.width / 2
}
}