Fix layout for iOS9/10

code cleanup

// FREEBIE
pull/1/head
Michael Kirk 7 years ago committed by Matthew Chen
parent 7a1d24a9ab
commit 55e19b55b3

@ -20,9 +20,6 @@ public class ConversationHeaderView: UIStackView {
} }
set { set {
self.titleLabel.attributedText = newValue self.titleLabel.attributedText = newValue
// self.layoutIfNeeded()
// self.titleLabel.sizeToFit()
// self.sizeToFit()
} }
} }
@ -32,9 +29,6 @@ public class ConversationHeaderView: UIStackView {
} }
set { set {
self.subtitleLabel.attributedText = newValue self.subtitleLabel.attributedText = newValue
// self.layoutIfNeeded()
// self.subtitleLabel.sizeToFit()
// self.sizeToFit()
} }
} }
@ -51,8 +45,6 @@ public class ConversationHeaderView: UIStackView {
public let titleSecondaryFont: UIFont = UIFont.ows_regularFont(withSize: 9) public let titleSecondaryFont: UIFont = UIFont.ows_regularFont(withSize: 9)
public let subtitleFont: UIFont = UIFont.ows_regularFont(withSize: 12) public let subtitleFont: UIFont = UIFont.ows_regularFont(withSize: 12)
// public let columns: UIStackView
// public let textRows: UIStackView
private let titleLabel: UILabel private let titleLabel: UILabel
private let subtitleLabel: UILabel private let subtitleLabel: UILabel
private let avatarView: AvatarImageView private let avatarView: AvatarImageView
@ -90,9 +82,6 @@ public class ConversationHeaderView: UIStackView {
self.layoutMargins = UIEdgeInsets(top: 4, left: 2, bottom: 4, right: 2) self.layoutMargins = UIEdgeInsets(top: 4, left: 2, bottom: 4, right: 2)
self.isLayoutMarginsRelativeArrangement = true self.isLayoutMarginsRelativeArrangement = true
// needed for proper layout on iOS10
self.translatesAutoresizingMaskIntoConstraints = false
self.axis = .horizontal self.axis = .horizontal
self.alignment = .center self.alignment = .center
self.spacing = 0 self.spacing = 0
@ -112,8 +101,8 @@ public class ConversationHeaderView: UIStackView {
} }
public override var intrinsicContentSize: CGSize { public override var intrinsicContentSize: CGSize {
// Grow to fill as much of the navbar as possible.
if #available(iOS 11, *) { if #available(iOS 11, *) {
// Grow to fill as much of the navbar as possible.
return UILayoutFittingExpandedSize return UILayoutFittingExpandedSize
} else { } else {
return super.intrinsicContentSize return super.intrinsicContentSize

@ -179,8 +179,6 @@ typedef enum : NSUInteger {
@property (nonatomic, nullable) NSTimer *readTimer; @property (nonatomic, nullable) NSTimer *readTimer;
@property (nonatomic) NSCache *cellMediaCache; @property (nonatomic) NSCache *cellMediaCache;
@property (nonatomic) ConversationHeaderView *headerView; @property (nonatomic) ConversationHeaderView *headerView;
//@property (nonatomic) UILabel *navigationBarTitleLabel;
@property (nonatomic) UILabel *navigationBarSubtitleLabel;
@property (nonatomic, nullable) UIView *bannerView; @property (nonatomic, nullable) UIView *bannerView;
@property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; @property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
@ -490,7 +488,7 @@ typedef enum : NSUInteger {
[self createConversationScrollButtons]; [self createConversationScrollButtons];
[self createHeaderViews]; [self createHeaderViews];
// [self createBackButton];
[self addNotificationListeners]; [self addNotificationListeners];
[self loadDraftInCompose]; [self loadDraftInCompose];
} }
@ -1106,35 +1104,26 @@ typedef enum : NSUInteger {
} }
self.headerView.attributedTitle = name; self.headerView.attributedTitle = name;
// self.navigationBarTitleLabel.attributedText = name;
// TODO layout still necessary with stackview?
// Changing the title requires relayout of the nav bar contents.
[self updateBarButtonItems];
} }
- (void)createHeaderViews - (void)createHeaderViews
{ {
// _backButtonUnreadCountView = [UIView new]; _backButtonUnreadCountView = [UIView new];
// _backButtonUnreadCountView.layer.cornerRadius = self.unreadCountViewDiameter / 2; _backButtonUnreadCountView.layer.cornerRadius = self.unreadCountViewDiameter / 2;
// _backButtonUnreadCountView.backgroundColor = [UIColor redColor]; _backButtonUnreadCountView.backgroundColor = [UIColor redColor];
// _backButtonUnreadCountView.hidden = YES; _backButtonUnreadCountView.hidden = YES;
// _backButtonUnreadCountView.userInteractionEnabled = NO; _backButtonUnreadCountView.userInteractionEnabled = NO;
//
// _backButtonUnreadCountLabel = [UILabel new]; _backButtonUnreadCountLabel = [UILabel new];
// _backButtonUnreadCountLabel.backgroundColor = [UIColor clearColor]; _backButtonUnreadCountLabel.backgroundColor = [UIColor clearColor];
// _backButtonUnreadCountLabel.textColor = [UIColor whiteColor]; _backButtonUnreadCountLabel.textColor = [UIColor whiteColor];
// _backButtonUnreadCountLabel.font = [UIFont systemFontOfSize:11]; _backButtonUnreadCountLabel.font = [UIFont systemFontOfSize:11];
// _backButtonUnreadCountLabel.textAlignment = NSTextAlignmentCenter; _backButtonUnreadCountLabel.textAlignment = NSTextAlignmentCenter;
//
ConversationHeaderView *headerView = ConversationHeaderView *headerView =
[[ConversationHeaderView alloc] initWithThread:self.thread contactsManager:self.contactsManager]; [[ConversationHeaderView alloc] initWithThread:self.thread contactsManager:self.contactsManager];
headerView.delegate = self; headerView.delegate = self;
// UIImage *avatarImage = [OWSAvatarBuilder buildImageForThread:self.thread diameter:36
// contactsManager:self.contactsManager]; headerView.avatarImage = avatarImage;
self.headerView = headerView; self.headerView = headerView;
#ifdef USE_DEBUG_UI #ifdef USE_DEBUG_UI
@ -1143,24 +1132,9 @@ typedef enum : NSUInteger {
action:@selector(navigationTitleLongPressed:)]]; action:@selector(navigationTitleLongPressed:)]];
#endif #endif
// self.navigationBarTitleLabel = [UILabel new];
// self.navigationBarTitleView.titleLabel = self.navigationBarTitleLabel;
// self.navigationBarTitleLabel.textColor = [UIColor whiteColor];
// self.navigationBarTitleLabel.font = [self navigationBarTitleLabelFont];
// self.navigationBarTitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
// [self.navigationBarTitleView addSubview:self.navigationBarTitleLabel];
// self.navigationBarSubtitleLabel = [UILabel new];
// self.navigationBarTitleView.subtitleLabel = self.navigationBarSubtitleLabel;
[self updateNavigationBarSubtitleLabel]; [self updateNavigationBarSubtitleLabel];
// [self.navigationBarTitleView addSubview:self.navigationBarSubtitleLabel];
} }
//- (UIFont *)navigationBarTitleLabelFont
//{
// return [UIFont ows_boldFontWithSize:20.f];
//}
- (CGFloat)unreadCountViewDiameter - (CGFloat)unreadCountViewDiameter
{ {
return 16; return 16;
@ -1199,35 +1173,17 @@ typedef enum : NSUInteger {
- (void)updateBarButtonItems - (void)updateBarButtonItems
{ {
if (self.navigationItem.titleView == nil) { if (self.navigationItem.titleView == nil) {
// Request "full width" title; the navigation bar will truncate this if (@available(iOS 11, *)) {
// to fit between the left and right buttons. // Do nothing, we use autolayout/intrinsic content size to grow
// self.navigationBarTitleView.frame = CGRectMake(0, 0, screenWidth, 44); } else {
DDLogDebug(@"%@ assigning titleView", self.logTag); // Request "full width" title; the navigation bar will truncate this
// to fit between the left and right buttons.
UILabel *label1 = [UILabel new]; CGSize screenSize = [UIScreen mainScreen].bounds.size;
label1.text = @"title"; CGRect headerFrame = CGRectMake(0, 0, screenSize.width, 44);
label1.textColor = UIColor.whiteColor; self.headerView.frame = headerFrame;
label1.font = [UIFont ows_regularFontWithSize:17]; }
UILabel *label2 = [UILabel new];
label2.text = @"subtitle";
label2.textColor = UIColor.whiteColor;
label2.font = [UIFont ows_regularFontWithSize:12];
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ label1, label2 ]];
stackView.axis = UILayoutConstraintAxisVertical;
[label1 setCompressionResistanceHigh];
[label2 setCompressionResistanceHigh];
[stackView setCompressionResistanceHigh];
// [stackView autoSetDimensionsToSize:CGSizeMake(100, 40)];
// self.navigationItem.titleView = stackView;
self.navigationItem.titleView = self.headerView; self.navigationItem.titleView = self.headerView;
} else {
// Don't reset the frame of the navigationBarTitleView every time
// this method is called or we'll gave bad frames where it will appear
// in the wrong position.
// [self.navigationBarTitleView layoutSubviews];
} }
if (self.userLeftGroup) { if (self.userLeftGroup) {
@ -3819,21 +3775,21 @@ typedef enum : NSUInteger {
- (void)setBackButtonUnreadCount:(NSUInteger)unreadCount - (void)setBackButtonUnreadCount:(NSUInteger)unreadCount
{ {
// OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
// if (_backButtonUnreadCount == unreadCount) { if (_backButtonUnreadCount == unreadCount) {
// // No need to re-render same count. // No need to re-render same count.
// return; return;
// } }
// _backButtonUnreadCount = unreadCount; _backButtonUnreadCount = unreadCount;
//
// OWSAssert(_backButtonUnreadCountView != nil); OWSAssert(_backButtonUnreadCountView != nil);
// _backButtonUnreadCountView.hidden = unreadCount <= 0; _backButtonUnreadCountView.hidden = unreadCount <= 0;
//
// OWSAssert(_backButtonUnreadCountLabel != nil); OWSAssert(_backButtonUnreadCountLabel != nil);
//
// // Max out the unread count at 99+. // Max out the unread count at 99+.
// const NSUInteger kMaxUnreadCount = 99; const NSUInteger kMaxUnreadCount = 99;
// _backButtonUnreadCountLabel.text = [OWSFormat formatInt:(int)MIN(kMaxUnreadCount, unreadCount)]; _backButtonUnreadCountLabel.text = [OWSFormat formatInt:(int)MIN(kMaxUnreadCount, unreadCount)];
} }
#pragma mark 3D Touch Preview Actions #pragma mark 3D Touch Preview Actions

@ -279,8 +279,11 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
// Admittedly this is kind of a hack and not super fine grained, but it's simple and results in the interactive pop // Admittedly this is kind of a hack and not super fine grained, but it's simple and results in the interactive pop
// gesture animating our title view nicely vs. creating our own back button bar item with custom padding, which does // gesture animating our title view nicely vs. creating our own back button bar item with custom padding, which does
// not properly animate with the "swipe to go back" or "swipe left for info" gestures. // not properly animate with the "swipe to go back" or "swipe left for info" gestures.
NSUInteger paddingLength = 3;
NSString *paddingString = [@"" stringByPaddingToLength:paddingLength withString:@" " startingAtIndex:0];
self.navigationItem.backBarButtonItem = self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil]; [[UIBarButtonItem alloc] initWithTitle:paddingString style:UIBarButtonItemStylePlain target:nil action:nil];
if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]
&& (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) { && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {

Loading…
Cancel
Save