Grow unread badge into pill

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 2bc072fe8e
commit bba2bcefe2

@ -189,18 +189,34 @@ NS_ASSUME_NONNULL_BEGIN
} else { } else {
[self.contentView addSubview:self.unreadBadge]; [self.contentView addSubview:self.unreadBadge];
self.unreadLabel.text = [OWSFormat formatInt:MIN(99, (int)unreadCount)]; self.unreadLabel.text = [OWSFormat formatInt:unreadCount];
// TODO: Will this localize? It assumes that the worst case // TODO: Will this localize? It assumes that the worst case
// unread count (99) will fit horizontally into some multiple // unread count (99) will fit horizontally into some multiple
// N of the font's line height. // N of the font's line height.
const int unreadBadgeSize = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f); const int unreadBadgeHeight = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f);
self.unreadBadge.layer.cornerRadius = unreadBadgeSize / 2; self.unreadBadge.layer.cornerRadius = unreadBadgeHeight / 2;
[NSLayoutConstraint autoSetPriority:UILayoutPriorityDefaultHigh
forConstraints:^{
// This is a bit arbitrary, but it should scale with the size of dynamic text
CGFloat minMargin = CeilEven(unreadBadgeHeight * .5);
// Spec check. Should be 12pts (6pt on each side) when using default font size.
OWSAssert(UIFont.ows_dynamicTypeBodyFont.pointSize != 17 || minMargin == 12);
[self.viewConstraints addObject:[self.unreadBadge autoMatchDimension:ALDimensionWidth
toDimension:ALDimensionWidth
ofView:self.unreadLabel
withOffset:minMargin]];
}];
[self.viewConstraints addObjectsFromArray:@[ [self.viewConstraints addObjectsFromArray:@[
// badge sizing // badge sizing
[self.unreadBadge autoSetDimension:ALDimensionWidth toSize:unreadBadgeSize], [self.unreadBadge autoSetDimension:ALDimensionWidth
[self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeSize], toSize:unreadBadgeHeight
relation:NSLayoutRelationGreaterThanOrEqual],
[self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeHeight],
// Horizontally, badge is inserted after the tail of the payloadView, pushing back the date *and* snippet // Horizontally, badge is inserted after the tail of the payloadView, pushing back the date *and* snippet
// view // view

Loading…
Cancel
Save