From c3345a4c4e91af71a543089c31eaaf21202658f5 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 10 Apr 2018 16:35:49 -0400 Subject: [PATCH 1/6] Scale home view cells to reflect dynamic type size. --- .../ViewControllers/HomeView/HomeViewCell.h | 5 +- .../ViewControllers/HomeView/HomeViewCell.m | 78 ++++++++++++------- .../HomeView/HomeViewController.m | 9 +-- .../UpdateGroupViewController.m | 2 +- SignalMessaging/utils/OWSMath.h | 8 +- 5 files changed, 63 insertions(+), 39 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.h b/Signal/src/ViewControllers/HomeView/HomeViewCell.h index 2063fdc14..4e51d15fc 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.h +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.h @@ -14,9 +14,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)cellReuseIdentifier; - (void)configureWithThread:(TSThread *)thread - contactsManager:(OWSContactsManager *)contactsManager - blockedPhoneNumberSet:(NSSet *)blockedPhoneNumberSet - shouldHaveBottomSeparator:(BOOL)shouldHaveBottomSeparator; + contactsManager:(OWSContactsManager *)contactsManager + blockedPhoneNumberSet:(NSSet *)blockedPhoneNumberSet; @end diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index fbdefd232..158c32a11 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -15,16 +15,11 @@ NS_ASSUME_NONNULL_BEGIN -const NSUInteger kHomeViewCellHeight = 72; -const NSUInteger kHomeViewCellHMargin = 16; -const NSUInteger kHomeViewCellVMargin = 12; -const NSUInteger kHomeViewAvatarSize = kHomeViewCellHeight - kHomeViewCellVMargin * 2; -const NSUInteger kHomeViewAvatarHSpacing = 12; - @interface HomeViewCell () @property (nonatomic) AvatarImageView *avatarView; @property (nonatomic) UIView *payloadView; +@property (nonatomic) UIStackView *topRowView; @property (nonatomic) UILabel *nameLabel; @property (nonatomic) UILabel *snippetLabel; @property (nonatomic) UILabel *dateTimeLabel; @@ -76,16 +71,16 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; self.avatarView = [[AvatarImageView alloc] init]; [self.contentView addSubview:self.avatarView]; - [self.avatarView autoSetDimension:ALDimensionWidth toSize:kHomeViewAvatarSize]; - [self.avatarView autoSetDimension:ALDimensionHeight toSize:kHomeViewAvatarSize]; - [self.avatarView autoPinLeadingToSuperviewMarginWithInset:kHomeViewCellHMargin]; + [self.avatarView autoSetDimension:ALDimensionWidth toSize:self.avatarSize]; + [self.avatarView autoSetDimension:ALDimensionHeight toSize:self.avatarSize]; + [self.avatarView autoPinLeadingToSuperviewMarginWithInset:self.cellHMargin]; [self.avatarView autoVCenterInSuperview]; [self.avatarView setContentHuggingHigh]; [self.avatarView setCompressionResistanceHigh]; self.payloadView = [UIView containerView]; [self.contentView addSubview:self.payloadView]; - [self.payloadView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:kHomeViewAvatarHSpacing]; + [self.payloadView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:self.avatarHSpacing]; [self.payloadView autoVCenterInSuperview]; self.nameLabel = [UILabel new]; @@ -102,6 +97,7 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; self.nameLabel, self.dateTimeLabel, ]]; + self.topRowView = topRowView; topRowView.axis = UILayoutConstraintAxisHorizontal; topRowView.spacing = 4; [self.payloadView addSubview:topRowView]; @@ -117,7 +113,6 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; [self.snippetLabel autoPinLeadingToSuperviewMargin]; [self.snippetLabel autoPinTrailingToSuperviewMargin]; [self.snippetLabel autoPinBottomToSuperviewMargin]; - [self.snippetLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRowView withOffset:5.f]; [self.snippetLabel setContentHuggingHorizontalLow]; [self.snippetLabel setCompressionResistanceHorizontalLow]; @@ -130,7 +125,7 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; self.unreadBadge = [NeverClearView new]; self.unreadBadge.backgroundColor = [UIColor ows_materialBlueColor]; [self.contentView addSubview:self.unreadBadge]; - [self.unreadBadge autoPinTrailingToSuperviewMarginWithInset:kHomeViewCellHMargin]; + [self.unreadBadge autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; [self.unreadBadge autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.dateTimeLabel]; [self.unreadBadge setContentHuggingHigh]; [self.unreadBadge setCompressionResistanceHigh]; @@ -145,11 +140,6 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; return NSStringFromClass([self class]); } -+ (CGFloat)rowHeight -{ - return kHomeViewCellHeight; -} - - (void)initializeLayout { self.selectionStyle = UITableViewCellSelectionStyleDefault; @@ -163,15 +153,12 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; - (void)configureWithThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager blockedPhoneNumberSet:(NSSet *)blockedPhoneNumberSet - shouldHaveBottomSeparator:(BOOL)shouldHaveBottomSeparator { OWSAssertIsOnMainThread(); OWSAssert(thread); OWSAssert(contactsManager); OWSAssert(blockedPhoneNumberSet); - // TODO: Honor shouldHaveBottomSeparator. - self.thread = thread; self.contactsManager = contactsManager; @@ -190,9 +177,10 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; self.snippetLabel.attributedText = [self attributedSnippetForThread:thread blockedPhoneNumberSet:blockedPhoneNumberSet]; self.dateTimeLabel.attributedText = [self attributedStringForDate:thread.lastMessageDate]; - - self.separatorInset - = UIEdgeInsetsMake(0, kHomeViewAvatarSize + kHomeViewCellHMargin + kHomeViewAvatarHSpacing, 0, 0); + CGFloat snippetHSpacing = ceil([HomeViewCell scaleValueWithDynamicType:6]); + [self.viewConstraints addObjectsFromArray:@[ + [self.snippetLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.topRowView withOffset:snippetHSpacing], + ]]; self.dateTimeLabel.textColor = hasUnreadMessages ? [UIColor ows_materialBlueColor] : [UIColor ows_darkGrayColor]; @@ -209,16 +197,18 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; const int unreadBadgeSize = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f); self.unreadBadge.layer.cornerRadius = unreadBadgeSize / 2; + CGFloat unreadBadgeHSpacing = ceil([HomeViewCell scaleValueWithDynamicType:7]); + [self.viewConstraints addObjectsFromArray:@[ - [self.unreadBadge autoSetDimension:ALDimensionWidth toSize:unreadBadgeSize], - [self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeSize], - [self.unreadBadge autoPinLeadingToTrailingEdgeOfView:self.payloadView offset:4.f], + [self.unreadBadge autoSetDimension:ALDimensionWidth toSize:unreadBadgeSize], + [self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeSize], + [self.unreadBadge autoPinLeadingToTrailingEdgeOfView:self.payloadView offset:unreadBadgeHSpacing], ]]; } else { self.unreadBadge.hidden = YES; [self.viewConstraints addObjectsFromArray:@[ - [self.payloadView autoPinTrailingToSuperviewMarginWithInset:kHomeViewCellHMargin], + [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin], ]]; } } @@ -240,7 +230,7 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; } self.avatarView.image = - [OWSAvatarBuilder buildImageForThread:thread diameter:kHomeViewAvatarSize contactsManager:contactsManager]; + [OWSAvatarBuilder buildImageForThread:thread diameter:self.avatarSize contactsManager:contactsManager]; } - (NSAttributedString *)attributedSnippetForThread:(TSThread *)thread @@ -345,6 +335,38 @@ const NSUInteger kHomeViewAvatarHSpacing = 12; return [UIFont ows_dynamicTypeFootnoteFont]; } ++ (CGFloat)scaleValueWithDynamicType:(CGFloat)minValue +{ + const NSUInteger kReferenceFontSizeMin = 17.f; + + CGFloat referenceFontSize = UIFont.ows_dynamicTypeBodyFont.pointSize; + // We don't want to scale these values any smaller than their reference values. + CGFloat alpha = MAX(1.f, referenceFontSize / kReferenceFontSizeMin); + return minValue * alpha; +} + ++ (CGFloat)rowHeight +{ + const NSUInteger kMinCellHeight = 72; + + return CeilEven([self scaleValueWithDynamicType:kMinCellHeight]); +} + +- (NSUInteger)cellHMargin +{ + return 16; +} + +- (NSUInteger)avatarSize +{ + return 48.f; +} + +- (NSUInteger)avatarHSpacing +{ + return 12.f; +} + #pragma mark - Reuse - (void)prepareForReuse diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 9d4ba834f..fec465118 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -210,6 +210,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; self.tableView.delegate = self; self.tableView.dataSource = self; + self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.tableView registerClass:[HomeViewCell class] forCellReuseIdentifier:HomeViewCell.cellReuseIdentifier]; [self.view addSubview:self.tableView]; [self.tableView autoPinWidthToSuperview]; @@ -583,13 +584,9 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; TSThread *thread = [self threadForIndexPath:indexPath]; - BOOL isLastCell = (indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1); - BOOL shouldHaveBottomSeparator = !isLastCell; - [cell configureWithThread:thread - contactsManager:self.contactsManager - blockedPhoneNumberSet:self.blockedPhoneNumberSet - shouldHaveBottomSeparator:shouldHaveBottomSeparator]; + contactsManager:self.contactsManager + blockedPhoneNumberSet:self.blockedPhoneNumberSet]; if ((unsigned long)indexPath.row == [self.threadMappings numberOfItemsInSection:0] - 1) { cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f); diff --git a/Signal/src/ViewControllers/ThreadSettings/UpdateGroupViewController.m b/Signal/src/ViewControllers/ThreadSettings/UpdateGroupViewController.m index fcea5ff6f..a67d5e7ae 100644 --- a/Signal/src/ViewControllers/ThreadSettings/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/UpdateGroupViewController.m @@ -276,7 +276,7 @@ NS_ASSUME_NONNULL_BEGIN cell.accessoryMessage = NSLocalizedString( @"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked."); } else { - cell.selectionStyle = UITableViewCellSeparatorStyleNone; + cell.selectionStyle = UITableViewCellSelectionStyleNone; } } else { // In the "members" section, we label "new" members as such when editing an existing group. diff --git a/SignalMessaging/utils/OWSMath.h b/SignalMessaging/utils/OWSMath.h index 82d82968e..370b4cf86 100644 --- a/SignalMessaging/utils/OWSMath.h +++ b/SignalMessaging/utils/OWSMath.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // NS_ASSUME_NONNULL_BEGIN @@ -27,6 +27,12 @@ static inline CGFloat CGFloatInverseLerp(CGFloat value, CGFloat minValue, CGFloa return (value - minValue) / (maxValue - minValue); } +// Ceil to an even number +static inline CGFloat CeilEven(CGFloat value) +{ + return 2.f * ceil(value * 0.5f); +} + void SetRandFunctionSeed(void); NS_ASSUME_NONNULL_END From 25e487fcdeb9bbf8ccec0a9275e5e7037580e044 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Apr 2018 09:34:15 -0400 Subject: [PATCH 2/6] Scale home view cells to reflect dynamic type size. --- Signal/src/ViewControllers/HomeView/HomeViewCell.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index 158c32a11..ac1d80ca8 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -340,8 +340,9 @@ NS_ASSUME_NONNULL_BEGIN const NSUInteger kReferenceFontSizeMin = 17.f; CGFloat referenceFontSize = UIFont.ows_dynamicTypeBodyFont.pointSize; - // We don't want to scale these values any smaller than their reference values. - CGFloat alpha = MAX(1.f, referenceFontSize / kReferenceFontSizeMin); + // We don't want to scale these values any smaller than their reference values, + // and we don't want to scale them more than some arbitrary cap. + CGFloat alpha = MIN(1.3f, MAX(1.f, referenceFontSize / kReferenceFontSizeMin)); return minValue * alpha; } From 543c898dbe414e2d73ff15d97022eae98c7dcb0e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Apr 2018 10:42:51 -0400 Subject: [PATCH 3/6] Scale home view cells to reflect dynamic type size. --- .../ViewControllers/HomeView/HomeViewCell.m | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index ac1d80ca8..2aff00cca 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @interface HomeViewCell () @property (nonatomic) AvatarImageView *avatarView; -@property (nonatomic) UIView *payloadView; +@property (nonatomic) UIStackView *payloadView; @property (nonatomic) UIStackView *topRowView; @property (nonatomic) UILabel *nameLabel; @property (nonatomic) UILabel *snippetLabel; @@ -78,10 +78,12 @@ NS_ASSUME_NONNULL_BEGIN [self.avatarView setContentHuggingHigh]; [self.avatarView setCompressionResistanceHigh]; - self.payloadView = [UIView containerView]; + self.payloadView = [UIStackView new]; + self.payloadView.axis = UILayoutConstraintAxisVertical; [self.contentView addSubview:self.payloadView]; [self.payloadView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:self.avatarHSpacing]; [self.payloadView autoVCenterInSuperview]; + [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; self.nameLabel = [UILabel new]; self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; @@ -99,20 +101,13 @@ NS_ASSUME_NONNULL_BEGIN ]]; self.topRowView = topRowView; topRowView.axis = UILayoutConstraintAxisHorizontal; - topRowView.spacing = 4; - [self.payloadView addSubview:topRowView]; - [topRowView autoPinLeadingToSuperviewMargin]; - [topRowView autoPinTrailingToSuperviewMargin]; - [topRowView autoPinTopToSuperviewMargin]; + [self.payloadView addArrangedSubview:topRowView]; self.snippetLabel = [UILabel new]; self.snippetLabel.font = [self snippetFont]; self.snippetLabel.numberOfLines = 1; self.snippetLabel.lineBreakMode = NSLineBreakByTruncatingTail; - [self.payloadView addSubview:self.snippetLabel]; - [self.snippetLabel autoPinLeadingToSuperviewMargin]; - [self.snippetLabel autoPinTrailingToSuperviewMargin]; - [self.snippetLabel autoPinBottomToSuperviewMargin]; + [self.payloadView addArrangedSubview:self.snippetLabel]; [self.snippetLabel setContentHuggingHorizontalLow]; [self.snippetLabel setCompressionResistanceHorizontalLow]; @@ -124,9 +119,6 @@ NS_ASSUME_NONNULL_BEGIN self.unreadBadge = [NeverClearView new]; self.unreadBadge.backgroundColor = [UIColor ows_materialBlueColor]; - [self.contentView addSubview:self.unreadBadge]; - [self.unreadBadge autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; - [self.unreadBadge autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.dateTimeLabel]; [self.unreadBadge setContentHuggingHigh]; [self.unreadBadge setCompressionResistanceHigh]; @@ -171,23 +163,22 @@ NS_ASSUME_NONNULL_BEGIN [self updateNameLabel]; [self updateAvatarView]; + self.payloadView.spacing = 0.f; + self.topRowView.spacing = ceil([HomeViewCell scaleValueWithDynamicType:5]); + // We update the fonts every time this cell is configured to ensure that // changes to the dynamic type settings are reflected. self.snippetLabel.font = [self snippetFont]; self.snippetLabel.attributedText = [self attributedSnippetForThread:thread blockedPhoneNumberSet:blockedPhoneNumberSet]; - self.dateTimeLabel.attributedText = [self attributedStringForDate:thread.lastMessageDate]; - CGFloat snippetHSpacing = ceil([HomeViewCell scaleValueWithDynamicType:6]); - [self.viewConstraints addObjectsFromArray:@[ - [self.snippetLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.topRowView withOffset:snippetHSpacing], - ]]; + self.dateTimeLabel.attributedText = [self attributedStringForDate:thread.lastMessageDate]; self.dateTimeLabel.textColor = hasUnreadMessages ? [UIColor ows_materialBlueColor] : [UIColor ows_darkGrayColor]; NSUInteger unreadCount = [[OWSMessageUtils sharedManager] unreadMessagesInThread:thread]; if (unreadCount > 0) { + [self.topRowView addArrangedSubview:self.unreadBadge]; - self.unreadBadge.hidden = NO; self.unreadLabel.font = [UIFont ows_dynamicTypeCaption1Font]; self.unreadLabel.text = [OWSFormat formatInt:MIN(99, (int)unreadCount)]; @@ -197,19 +188,11 @@ NS_ASSUME_NONNULL_BEGIN const int unreadBadgeSize = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f); self.unreadBadge.layer.cornerRadius = unreadBadgeSize / 2; - CGFloat unreadBadgeHSpacing = ceil([HomeViewCell scaleValueWithDynamicType:7]); - [self.viewConstraints addObjectsFromArray:@[ [self.unreadBadge autoSetDimension:ALDimensionWidth toSize:unreadBadgeSize], [self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeSize], - [self.unreadBadge autoPinLeadingToTrailingEdgeOfView:self.payloadView offset:unreadBadgeHSpacing], ]]; } else { - self.unreadBadge.hidden = YES; - - [self.viewConstraints addObjectsFromArray:@[ - [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin], - ]]; } } @@ -321,7 +304,7 @@ NS_ASSUME_NONNULL_BEGIN - (UIFont *)snippetFont { - return [UIFont ows_dynamicTypeBodyFont]; + return [UIFont ows_dynamicTypeFootnoteFont]; } - (UIFont *)nameFont @@ -380,6 +363,8 @@ NS_ASSUME_NONNULL_BEGIN self.thread = nil; self.contactsManager = nil; + [self.unreadBadge removeFromSuperview]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } From 3688d57eac8bd6adc0f4ba7ed17d9e6347f49e61 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Apr 2018 10:59:37 -0400 Subject: [PATCH 4/6] Scale home view cells to reflect dynamic type size. --- .../ViewControllers/HomeView/HomeViewCell.m | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index 2aff00cca..cae097a62 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -82,8 +82,17 @@ NS_ASSUME_NONNULL_BEGIN self.payloadView.axis = UILayoutConstraintAxisVertical; [self.contentView addSubview:self.payloadView]; [self.payloadView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:self.avatarHSpacing]; - [self.payloadView autoVCenterInSuperview]; [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; + [self.payloadView autoVCenterInSuperview]; + // Ensure that the cell's contents never overflow the cell bounds. + [self.payloadView.bottomAnchor + constraintLessThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.bottomAnchor] + .active + = YES; + [self.payloadView.topAnchor + constraintGreaterThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.topAnchor] + .active + = YES; self.nameLabel = [UILabel new]; self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; @@ -95,13 +104,13 @@ NS_ASSUME_NONNULL_BEGIN [self.dateTimeLabel setContentHuggingHorizontalHigh]; [self.dateTimeLabel setCompressionResistanceHorizontalHigh]; - UIStackView *topRowView = [[UIStackView alloc] initWithArrangedSubviews:@[ + self.topRowView = [[UIStackView alloc] initWithArrangedSubviews:@[ self.nameLabel, self.dateTimeLabel, ]]; - self.topRowView = topRowView; - topRowView.axis = UILayoutConstraintAxisHorizontal; - [self.payloadView addArrangedSubview:topRowView]; + self.topRowView.axis = UILayoutConstraintAxisHorizontal; + self.topRowView.alignment = UIStackViewAlignmentCenter; + [self.payloadView addArrangedSubview:self.topRowView]; self.snippetLabel = [UILabel new]; self.snippetLabel.font = [self snippetFont]; @@ -331,9 +340,7 @@ NS_ASSUME_NONNULL_BEGIN + (CGFloat)rowHeight { - const NSUInteger kMinCellHeight = 72; - - return CeilEven([self scaleValueWithDynamicType:kMinCellHeight]); + return 72; } - (NSUInteger)cellHMargin From c6df55b820e5ed56a41f8cc7554ebe1ec39403c2 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Apr 2018 11:07:17 -0400 Subject: [PATCH 5/6] Scale home view cells to reflect dynamic type size. --- Signal/src/ViewControllers/HomeView/HomeViewCell.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index cae097a62..c57af302f 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -201,7 +201,6 @@ NS_ASSUME_NONNULL_BEGIN [self.unreadBadge autoSetDimension:ALDimensionWidth toSize:unreadBadgeSize], [self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeSize], ]]; - } else { } } @@ -327,13 +326,18 @@ NS_ASSUME_NONNULL_BEGIN return [UIFont ows_dynamicTypeFootnoteFont]; } +// A simple function to scale dimensions to reflect dynamic type. Given a value +// we lerp it larger linearly to reflect size of dynamic type relative to a +// reference value for default dynamic type sizes. +// +// * We _NEVER_ scale values down. +// * We cap scaling. + (CGFloat)scaleValueWithDynamicType:(CGFloat)minValue { + // The default size of dynamic "body" type. const NSUInteger kReferenceFontSizeMin = 17.f; CGFloat referenceFontSize = UIFont.ows_dynamicTypeBodyFont.pointSize; - // We don't want to scale these values any smaller than their reference values, - // and we don't want to scale them more than some arbitrary cap. CGFloat alpha = MIN(1.3f, MAX(1.f, referenceFontSize / kReferenceFontSizeMin)); return minValue * alpha; } From 759b2a332f0c71f68fb1837bbc70b7fe63b11cfd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 11 Apr 2018 14:18:09 -0400 Subject: [PATCH 6/6] Respond to CR. --- .../ConversationView/Cells/OWSExpirationTimerView.m | 2 +- .../ConversationView/ConversationInputToolbar.m | 2 +- .../ConversationView/ConversationViewController.m | 4 ++-- Signal/src/ViewControllers/HomeView/HomeViewCell.m | 13 ++++--------- .../AttachmentApprovalViewController.swift | 2 +- SignalMessaging/categories/UIView+OWS.m | 2 +- SignalMessaging/utils/OWSMath.h | 8 ++++---- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m index 76bdf39e7..15532f8da 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSExpirationTimerView.m @@ -161,7 +161,7 @@ const CGFloat kExpirationTimerViewSize = 16.f; } CGFloat ratioRemaining = (CGFloat)timeUntilFlashing / (CGFloat)self.initialDurationSeconds; - CGFloat ratioComplete = Clamp((CGFloat)1.0 - ratioRemaining, 0, 1.0); + CGFloat ratioComplete = CGFloatClamp((CGFloat)1.0 - ratioRemaining, 0, 1.0); CGPoint startPosition = CGPointMake(0, self.fullHourglassImageView.height * ratioComplete); // We offset the bottom slightly to make sure the duration of the perceived animation is correct. diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 578d5c3f8..0571a1e42 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -316,7 +316,7 @@ static const CGFloat ConversationInputToolbarBorderViewHeight = 0.5; const CGFloat kMaxTextViewHeight = 98.f; const CGFloat textViewDesiredHeight = (self.inputTextView.contentSize.height + self.inputTextView.contentInset.top + self.inputTextView.contentInset.bottom); - const CGFloat textViewHeight = ceil(Clamp(textViewDesiredHeight, kMinTextViewHeight, kMaxTextViewHeight)); + const CGFloat textViewHeight = ceil(CGFloatClamp(textViewDesiredHeight, kMinTextViewHeight, kMaxTextViewHeight)); const CGFloat kMinContentHeight = kMinTextViewHeight + textViewVInset * 2; self.textViewHeight = textViewHeight; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 8db321fdf..cea1d46c2 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -3960,7 +3960,7 @@ typedef enum : NSUInteger { // keyboard, up to the limits of the content bounds. CGFloat insetChange = newInsets.bottom - oldInsets.bottom; CGFloat oldYOffset = self.collectionView.contentOffset.y; - CGFloat newYOffset = Clamp(oldYOffset + insetChange, 0, self.safeContentHeight); + CGFloat newYOffset = CGFloatClamp(oldYOffset + insetChange, 0, self.safeContentHeight); CGPoint newOffset = CGPointMake(0, newYOffset); // If the user is dismissing the keyboard via interactive scrolling, any additional conset offset feels @@ -4739,7 +4739,7 @@ typedef enum : NSUInteger { const CGFloat swipeTranslation = ([gestureRecognizer translationInView:self.view].x * (self.view.isRTL ? +1.f : -1.f)); - const CGFloat ratioComplete = Clamp(swipeTranslation / self.view.frame.size.width, 0, 1); + const CGFloat ratioComplete = CGFloatClamp(swipeTranslation / self.view.frame.size.width, 0, 1); switch (gestureRecognizer.state) { case UIGestureRecognizerStateBegan: { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index c57af302f..371e6393b 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -6,6 +6,7 @@ #import "OWSAvatarBuilder.h" #import "Signal-Swift.h" #import +#import #import #import #import @@ -85,14 +86,8 @@ NS_ASSUME_NONNULL_BEGIN [self.payloadView autoPinTrailingToSuperviewMarginWithInset:self.cellHMargin]; [self.payloadView autoVCenterInSuperview]; // Ensure that the cell's contents never overflow the cell bounds. - [self.payloadView.bottomAnchor - constraintLessThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.bottomAnchor] - .active - = YES; - [self.payloadView.topAnchor - constraintGreaterThanOrEqualToAnchor:self.payloadView.superview.layoutMarginsGuide.topAnchor] - .active - = YES; + [self.payloadView autoPinEdgeToSuperviewMargin:ALEdgeTop relation:NSLayoutRelationGreaterThanOrEqual]; + [self.payloadView autoPinEdgeToSuperviewMargin:ALEdgeBottom relation:NSLayoutRelationGreaterThanOrEqual]; self.nameLabel = [UILabel new]; self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail; @@ -338,7 +333,7 @@ NS_ASSUME_NONNULL_BEGIN const NSUInteger kReferenceFontSizeMin = 17.f; CGFloat referenceFontSize = UIFont.ows_dynamicTypeBodyFont.pointSize; - CGFloat alpha = MIN(1.3f, MAX(1.f, referenceFontSize / kReferenceFontSizeMin)); + CGFloat alpha = CGFloatClamp(referenceFontSize / kReferenceFontSizeMin, 1.f, 1.3f); return minValue * alpha; } diff --git a/SignalMessaging/attachments/AttachmentApprovalViewController.swift b/SignalMessaging/attachments/AttachmentApprovalViewController.swift index db24d8c87..ccaa6464d 100644 --- a/SignalMessaging/attachments/AttachmentApprovalViewController.swift +++ b/SignalMessaging/attachments/AttachmentApprovalViewController.swift @@ -686,6 +686,6 @@ class CaptioningToolbar: UIView, UITextViewDelegate { private func clampedTextViewHeight(fixedWidth: CGFloat) -> CGFloat { let contentSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude)) - return Clamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight) + return CGFloatClamp(contentSize.height, kMinTextViewHeight, maxTextViewHeight) } } diff --git a/SignalMessaging/categories/UIView+OWS.m b/SignalMessaging/categories/UIView+OWS.m index 4fcdaee9c..4ca3d2741 100644 --- a/SignalMessaging/categories/UIView+OWS.m +++ b/SignalMessaging/categories/UIView+OWS.m @@ -124,7 +124,7 @@ CGFloat ScaleFromIPhone5(CGFloat iPhone5Value) - (NSLayoutConstraint *)autoPinToAspectRatio:(CGFloat)ratio { // Clamp to ensure view has reasonable aspect ratio. - CGFloat clampedRatio = Clamp(ratio, 0.05, 95.0); + CGFloat clampedRatio = CGFloatClamp(ratio, 0.05, 95.0); if (clampedRatio != ratio) { OWSFail(@"Invalid aspect ratio: %f for view: %@", ratio, self); } diff --git a/SignalMessaging/utils/OWSMath.h b/SignalMessaging/utils/OWSMath.h index 370b4cf86..4d4826017 100644 --- a/SignalMessaging/utils/OWSMath.h +++ b/SignalMessaging/utils/OWSMath.h @@ -5,19 +5,19 @@ NS_ASSUME_NONNULL_BEGIN // TODO: We'll eventually want to promote these into an OWSMath.h header. -static inline CGFloat Clamp(CGFloat value, CGFloat minValue, CGFloat maxValue) +static inline CGFloat CGFloatClamp(CGFloat value, CGFloat minValue, CGFloat maxValue) { return MAX(minValue, MIN(maxValue, value)); } -static inline CGFloat Clamp01(CGFloat value) +static inline CGFloat CGFloatClamp01(CGFloat value) { - return Clamp(value, 0.f, 1.f); + return CGFloatClamp(value, 0.f, 1.f); } static inline CGFloat CGFloatLerp(CGFloat left, CGFloat right, CGFloat alpha) { - alpha = Clamp01(alpha); + alpha = CGFloatClamp01(alpha); return (left * (1.f - alpha)) + (right * alpha); }