From b7026957931b474e6314004146d770b7150437ec Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 26 Apr 2018 10:12:21 -0400 Subject: [PATCH] cleanup --- .../ConversationHeaderView.swift | 11 ++- .../ConversationViewController.m | 42 +++++---- .../MediaPageViewController.swift | 10 +-- SignalMessaging/Views/AvatarImageView.swift | 85 ++++++++++--------- 4 files changed, 73 insertions(+), 75 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationHeaderView.swift b/Signal/src/ViewControllers/ConversationView/ConversationHeaderView.swift index 599326d57..12e3db337 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationHeaderView.swift +++ b/Signal/src/ViewControllers/ConversationView/ConversationHeaderView.swift @@ -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 diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 7f39a6744..2ab1497a9 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -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]; + self.headerView = headerView; + headerView.delegate = self; + self.navigationItem.titleView = headerView; - self.headerView = 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; diff --git a/Signal/src/ViewControllers/MediaPageViewController.swift b/Signal/src/ViewControllers/MediaPageViewController.swift index d3567d542..f0790ab37 100644 --- a/Signal/src/ViewControllers/MediaPageViewController.swift +++ b/Signal/src/ViewControllers/MediaPageViewController.swift @@ -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 diff --git a/SignalMessaging/Views/AvatarImageView.swift b/SignalMessaging/Views/AvatarImageView.swift index a3c3c337e..e6ba70ec0 100644 --- a/SignalMessaging/Views/AvatarImageView.swift +++ b/SignalMessaging/Views/AvatarImageView.swift @@ -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 - } -}