Merge branch 'charlesmchen/converationColorsUnreadBadges'

pull/1/head
Matthew Chen 7 years ago
commit f0155c529e

@ -26,7 +26,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UIView *unreadBadge; @property (nonatomic) UIView *unreadBadge;
@property (nonatomic) UILabel *unreadLabel; @property (nonatomic) UILabel *unreadLabel;
@property (nonatomic) UIView *unreadBadgeContainer;
@property (nonatomic, nullable) ThreadViewModel *thread; @property (nonatomic, nullable) ThreadViewModel *thread;
@property (nonatomic, nullable) OWSContactsManager *contactsManager; @property (nonatomic, nullable) OWSContactsManager *contactsManager;
@ -113,6 +112,16 @@ NS_ASSUME_NONNULL_BEGIN
]]; ]];
vStackView.axis = UILayoutConstraintAxisVertical; vStackView.axis = UILayoutConstraintAxisVertical;
[self.contentView addSubview:vStackView];
[vStackView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:self.avatarHSpacing];
[vStackView autoVCenterInSuperview];
// Ensure that the cell's contents never overflow the cell bounds.
[vStackView autoPinEdgeToSuperviewMargin:ALEdgeTop relation:NSLayoutRelationGreaterThanOrEqual];
[vStackView autoPinEdgeToSuperviewMargin:ALEdgeBottom relation:NSLayoutRelationGreaterThanOrEqual];
[vStackView autoPinTrailingToSuperviewMargin];
vStackView.userInteractionEnabled = NO;
self.unreadLabel = [UILabel new]; self.unreadLabel = [UILabel new];
self.unreadLabel.textColor = [UIColor ows_whiteColor]; self.unreadLabel.textColor = [UIColor ows_whiteColor];
self.unreadLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.unreadLabel.lineBreakMode = NSLineBreakByTruncatingTail;
@ -127,29 +136,8 @@ NS_ASSUME_NONNULL_BEGIN
[self.unreadBadge setContentHuggingHigh]; [self.unreadBadge setContentHuggingHigh];
[self.unreadBadge setCompressionResistanceHigh]; [self.unreadBadge setCompressionResistanceHigh];
self.unreadBadgeContainer = [UIView containerView]; [self.contentView addSubview:self.unreadBadge];
[self.unreadBadgeContainer addSubview:self.unreadBadge];
[self.unreadBadge autoPinWidthToSuperview];
[self.unreadBadgeContainer setContentHuggingHigh];
[self.unreadBadgeContainer setCompressionResistanceHigh];
UIStackView *hStackView = [[UIStackView alloc] initWithArrangedSubviews:@[
vStackView,
self.unreadBadgeContainer,
]];
hStackView.axis = UILayoutConstraintAxisHorizontal;
hStackView.spacing = 6.f;
[self.contentView addSubview:hStackView];
[hStackView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:self.avatarHSpacing];
[hStackView autoVCenterInSuperview];
// Ensure that the cell's contents never overflow the cell bounds.
[hStackView autoPinEdgeToSuperviewMargin:ALEdgeTop relation:NSLayoutRelationGreaterThanOrEqual];
[hStackView autoPinEdgeToSuperviewMargin:ALEdgeBottom relation:NSLayoutRelationGreaterThanOrEqual];
[hStackView autoPinTrailingToSuperviewMargin];
[self.unreadBadge autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.nameLabel]; [self.unreadBadge autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.nameLabel];
hStackView.userInteractionEnabled = NO;
} }
- (void)dealloc - (void)dealloc
@ -233,18 +221,20 @@ NS_ASSUME_NONNULL_BEGIN
if (overrideSnippet) { if (overrideSnippet) {
// If we're using the home view cell to render search results, // If we're using the home view cell to render search results,
// don't show "unread badge" or "message status" indicator. // don't show "unread badge" or "message status" indicator.
self.unreadBadgeContainer.hidden = YES; self.unreadBadge.hidden = YES;
self.messageStatusView.hidden = YES; self.messageStatusView.hidden = YES;
} else if (unreadCount > 0) { } else if (unreadCount > 0) {
// If there are unread messages, show the "unread badge." // If there are unread messages, show the "unread badge."
// The "message status" indicators is redundant. // The "message status" indicators is redundant.
self.unreadBadgeContainer.hidden = NO; self.unreadBadge.hidden = NO;
self.messageStatusView.hidden = YES; self.messageStatusView.hidden = YES;
self.unreadLabel.text = [OWSFormat formatInt:(int)unreadCount]; self.unreadLabel.text = [OWSFormat formatInt:(int)unreadCount];
self.unreadLabel.font = self.unreadFont; self.unreadLabel.font = self.unreadFont;
const int unreadBadgeHeight = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f); const int unreadBadgeHeight = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f);
self.unreadBadge.layer.cornerRadius = unreadBadgeHeight / 2; self.unreadBadge.layer.cornerRadius = unreadBadgeHeight / 2;
self.unreadBadge.layer.borderColor = Theme.backgroundColor.CGColor;
self.unreadBadge.layer.borderWidth = 1.f;
[NSLayoutConstraint autoSetPriority:UILayoutPriorityDefaultHigh [NSLayoutConstraint autoSetPriority:UILayoutPriorityDefaultHigh
forConstraints:^{ forConstraints:^{
@ -264,6 +254,10 @@ NS_ASSUME_NONNULL_BEGIN
toSize:unreadBadgeHeight toSize:unreadBadgeHeight
relation:NSLayoutRelationGreaterThanOrEqual], relation:NSLayoutRelationGreaterThanOrEqual],
[self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeHeight], [self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeHeight],
[self.unreadBadge autoPinEdge:ALEdgeTrailing
toEdge:ALEdgeTrailing
ofView:self.avatarView
withOffset:6.f],
]]; ]];
}]; }];
} else { } else {
@ -302,7 +296,7 @@ NS_ASSUME_NONNULL_BEGIN
self.messageStatusView.image = [statusIndicatorImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; self.messageStatusView.image = [statusIndicatorImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.messageStatusView.tintColor = messageStatusViewTintColor; self.messageStatusView.tintColor = messageStatusViewTintColor;
self.messageStatusView.hidden = statusIndicatorImage == nil; self.messageStatusView.hidden = statusIndicatorImage == nil;
self.unreadBadgeContainer.hidden = YES; self.unreadBadge.hidden = YES;
if (shouldAnimateStatusIcon) { if (shouldAnimateStatusIcon) {
CABasicAnimation *animation; CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

Loading…
Cancel
Save