Tweak date headers.

pull/1/head
Matthew Chen 7 years ago
parent fa5bfc25e1
commit dd28c01897

@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
// to always keep one around. // to always keep one around.
@property (nonatomic) OWSMessageBubbleView *messageBubbleView; @property (nonatomic) OWSMessageBubbleView *messageBubbleView;
@property (nonatomic) UIView *dateHeaderView; @property (nonatomic) UIStackView *dateHeaderView;
@property (nonatomic) UIView *dateStrokeView; @property (nonatomic) UIView *dateStrokeView;
@property (nonatomic) UILabel *dateHeaderLabel; @property (nonatomic) UILabel *dateHeaderLabel;
@property (nonatomic) AvatarImageView *avatarView; @property (nonatomic) AvatarImageView *avatarView;
@ -51,23 +51,21 @@ NS_ASSUME_NONNULL_BEGIN
self.messageBubbleView = [OWSMessageBubbleView new]; self.messageBubbleView = [OWSMessageBubbleView new];
[self.contentView addSubview:self.messageBubbleView]; [self.contentView addSubview:self.messageBubbleView];
self.dateHeaderView = [UIView new];
self.dateStrokeView = [UIView new]; self.dateStrokeView = [UIView new];
self.dateStrokeView.backgroundColor = [UIColor lightGrayColor]; self.dateStrokeView.backgroundColor = [UIColor ows_light45Color];
[self.dateHeaderView addSubview:self.dateStrokeView]; [self.dateStrokeView autoSetDimension:ALDimensionHeight toSize:self.dateHeaderStrokeThickness];
[self.dateStrokeView setContentHuggingHigh];
self.dateHeaderLabel = [UILabel new]; self.dateHeaderLabel = [UILabel new];
self.dateHeaderLabel.font = self.dateHeaderDateFont; self.dateHeaderLabel.font = self.dateHeaderFont;
self.dateHeaderLabel.textAlignment = NSTextAlignmentCenter; self.dateHeaderLabel.textAlignment = NSTextAlignmentCenter;
self.dateHeaderLabel.textColor = [UIColor lightGrayColor]; self.dateHeaderLabel.textColor = [UIColor ows_light60Color];
[self.dateHeaderView addSubview:self.dateHeaderLabel];
[self.dateStrokeView autoPinWidthToSuperview]; self.dateHeaderView = [[UIStackView alloc] initWithArrangedSubviews:@[
[self.dateStrokeView autoPinEdgeToSuperviewEdge:ALEdgeTop]; self.dateStrokeView,
[self.dateStrokeView autoSetDimension:ALDimensionHeight toSize:1.f]; self.dateHeaderLabel,
[self.dateHeaderLabel autoPinWidthToSuperview]; ]];
[self.dateHeaderLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.dateStrokeView]; self.dateHeaderView.axis = NSTextLayoutOrientationVertical;
self.avatarView = [[AvatarImageView alloc] init]; self.avatarView = [[AvatarImageView alloc] init];
[self.avatarView autoSetDimension:ALDimensionWidth toSize:self.avatarSize]; [self.avatarView autoSetDimension:ALDimensionWidth toSize:self.avatarSize];
@ -148,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN
[self.messageBubbleView loadContent]; [self.messageBubbleView loadContent];
// Update label fonts to honor dynamic type size. // Update label fonts to honor dynamic type size.
self.dateHeaderLabel.font = self.dateHeaderDateFont; self.dateHeaderLabel.font = self.dateHeaderFont;
if (self.isIncoming) { if (self.isIncoming) {
[self.viewConstraints addObjectsFromArray:@[ [self.viewConstraints addObjectsFromArray:@[
@ -227,18 +225,18 @@ NS_ASSUME_NONNULL_BEGIN
NSAttributedString *attributedText = [NSAttributedString new]; NSAttributedString *attributedText = [NSAttributedString new];
attributedText = [attributedText rtlSafeAppend:dateString.uppercaseString attributedText = [attributedText rtlSafeAppend:dateString.uppercaseString
attributes:@{ attributes:@{
NSFontAttributeName : self.dateHeaderDateFont, NSFontAttributeName : self.dateHeaderFont,
NSForegroundColorAttributeName : [UIColor lightGrayColor], NSForegroundColorAttributeName : [UIColor lightGrayColor],
} }
referenceView:self]; referenceView:self];
attributedText = [attributedText rtlSafeAppend:@" " attributedText = [attributedText rtlSafeAppend:@" "
attributes:@{ attributes:@{
NSFontAttributeName : self.dateHeaderDateFont, NSFontAttributeName : self.dateHeaderFont,
} }
referenceView:self]; referenceView:self];
attributedText = [attributedText rtlSafeAppend:timeString attributedText = [attributedText rtlSafeAppend:timeString
attributes:@{ attributes:@{
NSFontAttributeName : self.dateHeaderTimeFont, NSFontAttributeName : self.dateHeaderFont,
NSForegroundColorAttributeName : [UIColor lightGrayColor], NSForegroundColorAttributeName : [UIColor lightGrayColor],
} }
referenceView:self]; referenceView:self];
@ -250,9 +248,11 @@ NS_ASSUME_NONNULL_BEGIN
[self.dateHeaderView autoPinLeadingToSuperviewMarginWithInset:self.conversationStyle.gutterLeading], [self.dateHeaderView autoPinLeadingToSuperviewMarginWithInset:self.conversationStyle.gutterLeading],
[self.dateHeaderView autoPinTrailingToSuperviewMarginWithInset:self.conversationStyle.gutterTrailing], [self.dateHeaderView autoPinTrailingToSuperviewMarginWithInset:self.conversationStyle.gutterTrailing],
[self.dateHeaderView autoPinEdgeToSuperviewEdge:ALEdgeTop], [self.dateHeaderView autoPinEdgeToSuperviewEdge:ALEdgeTop],
[self.dateHeaderView autoSetDimension:ALDimensionHeight toSize:self.dateHeaderHeight],
[self.messageBubbleView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.dateHeaderView], [self.messageBubbleView autoPinEdge:ALEdgeTop
toEdge:ALEdgeTop
ofView:self.dateHeaderView
withOffset:self.dateHeaderHeight],
]]; ]];
} else { } else {
[self.viewConstraints addObjectsFromArray:@[ [self.viewConstraints addObjectsFromArray:@[
@ -261,12 +261,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
- (UIFont *)dateHeaderDateFont - (UIFont *)dateHeaderFont
{
return UIFont.ows_dynamicTypeCaption1Font.ows_mediumWeight;
}
- (UIFont *)dateHeaderTimeFont
{ {
return UIFont.ows_dynamicTypeCaption1Font; return UIFont.ows_dynamicTypeCaption1Font;
} }
@ -368,16 +363,21 @@ NS_ASSUME_NONNULL_BEGIN
return cellSize; return cellSize;
} }
- (CGFloat)dateHeaderStrokeThickness
{
return 1.f / UIScreen.mainScreen.scale;
}
- (CGFloat)dateHeaderBottomMargin - (CGFloat)dateHeaderBottomMargin
{ {
return 24.f; return 20.f;
} }
- (CGFloat)dateHeaderHeight - (CGFloat)dateHeaderHeight
{ {
if (self.viewItem.shouldShowDate) { if (self.viewItem.shouldShowDate) {
CGFloat textHeight = MAX(self.dateHeaderDateFont.capHeight, self.dateHeaderTimeFont.capHeight); CGFloat textHeight = self.dateHeaderFont.capHeight;
return (CGFloat)ceil(textHeight + self.dateHeaderBottomMargin); return (CGFloat)ceil(self.dateHeaderStrokeThickness + textHeight + self.dateHeaderBottomMargin);
} else { } else {
return 0.f; return 0.f;
} }

@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN
self.strokeView = [UIView new]; self.strokeView = [UIView new];
self.strokeView.backgroundColor = [UIColor ows_light60Color]; self.strokeView.backgroundColor = [UIColor ows_light60Color];
[self.strokeView autoSetDimension:ALDimensionHeight toSize:self.strokeHeight]; [self.strokeView autoSetDimension:ALDimensionHeight toSize:self.strokeThickness];
[self.strokeView setContentHuggingHigh]; [self.strokeView setContentHuggingHigh];
self.titleLabel = [UILabel new]; self.titleLabel = [UILabel new];
@ -126,9 +126,9 @@ NS_ASSUME_NONNULL_BEGIN
@"Messages that indicates that there are more unseen messages including safety number changes.")); @"Messages that indicates that there are more unseen messages including safety number changes."));
} }
- (CGFloat)strokeHeight - (CGFloat)strokeThickness
{ {
return 1.f; return 1.f / UIScreen.mainScreen.scale;
} }
- (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction - (CGSize)cellSizeWithTransaction:(YapDatabaseReadTransaction *)transaction
@ -139,8 +139,8 @@ NS_ASSUME_NONNULL_BEGIN
[self configureFonts]; [self configureFonts];
CGSize result CGSize result = CGSizeMake(
= CGSizeMake(self.conversationStyle.fullWidthContentWidth, self.strokeHeight + self.titleLabel.font.lineHeight); self.conversationStyle.fullWidthContentWidth, self.strokeThickness + self.titleLabel.font.lineHeight);
TSUnreadIndicatorInteraction *interaction = (TSUnreadIndicatorInteraction *)self.viewItem.interaction; TSUnreadIndicatorInteraction *interaction = (TSUnreadIndicatorInteraction *)self.viewItem.interaction;
self.subtitleLabel.text = [self subtitleForInteraction:interaction]; self.subtitleLabel.text = [self subtitleForInteraction:interaction];

Loading…
Cancel
Save