Merge branch 'charlesmchen/tweakTextInsets'

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

@ -8,10 +8,6 @@ NS_ASSUME_NONNULL_BEGIN
extern const CGFloat kOWSMessageCellCornerRadius; extern const CGFloat kOWSMessageCellCornerRadius;
extern const CGFloat kBubbleTextHInset;
extern const CGFloat kBubbleTextTopInset;
extern const CGFloat kBubbleTextBottomInset;
@class OWSBubbleView; @class OWSBubbleView;
@protocol OWSBubbleViewPartner <NSObject> @protocol OWSBubbleViewPartner <NSObject>

@ -9,10 +9,6 @@ NS_ASSUME_NONNULL_BEGIN
const CGFloat kOWSMessageCellCornerRadius = 18; const CGFloat kOWSMessageCellCornerRadius = 18;
const CGFloat kBubbleTextHInset = 10.f;
const CGFloat kBubbleTextTopInset = 8.f;
const CGFloat kBubbleTextBottomInset = 6.f;
@interface OWSBubbleView () @interface OWSBubbleView ()
@property (nonatomic) CAShapeLayer *maskLayer; @property (nonatomic) CAShapeLayer *maskLayer;

@ -66,8 +66,6 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
@property (nonatomic, nullable, readonly) UIView *bodyMediaView; @property (nonatomic, nullable, readonly) UIView *bodyMediaView;
@property (nonatomic) BOOL alwaysShowBubbleTail;
@property (nonatomic, weak) id<OWSMessageBubbleViewDelegate> delegate; @property (nonatomic, weak) id<OWSMessageBubbleViewDelegate> delegate;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;

@ -390,6 +390,9 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
OWSDirectionalEdgeInsets *textInsets = self.layoutInfo.textInsets;
OWSAssert(textInsets);
OWSMessageTextView *_Nullable bodyTextView = nil; OWSMessageTextView *_Nullable bodyTextView = nil;
// We render malformed messages as "empty text" messages, // We render malformed messages as "empty text" messages,
// so create a text view if there is no body media view. // so create a text view if there is no body media view.
@ -399,8 +402,8 @@ NS_ASSUME_NONNULL_BEGIN
if (bodyTextView) { if (bodyTextView) {
[self.bubbleView addSubview:bodyTextView]; [self.bubbleView addSubview:bodyTextView];
[self.viewConstraints addObjectsFromArray:@[ [self.viewConstraints addObjectsFromArray:@[
[bodyTextView autoPinLeadingToSuperviewMarginWithInset:self.textLeadingMargin], [bodyTextView autoPinLeadingToSuperviewMarginWithInset:textInsets.leading],
[bodyTextView autoPinTrailingToSuperviewMarginWithInset:self.textTrailingMargin], [bodyTextView autoPinTrailingToSuperviewMarginWithInset:textInsets.trailing],
]]; ]];
[self.viewConstraints [self.viewConstraints
addObject:[bodyTextView autoSetDimension:ALDimensionHeight toSize:bodyTextContentSize.height]]; addObject:[bodyTextView autoSetDimension:ALDimensionHeight toSize:bodyTextContentSize.height]];
@ -409,13 +412,13 @@ NS_ASSUME_NONNULL_BEGIN
[self.viewConstraints addObject:[bodyTextView autoPinEdge:ALEdgeTop [self.viewConstraints addObject:[bodyTextView autoPinEdge:ALEdgeTop
toEdge:ALEdgeBottom toEdge:ALEdgeBottom
ofView:lastSubview ofView:lastSubview
withOffset:self.textTopMargin]]; withOffset:textInsets.top]];
} else { } else {
[self.viewConstraints [self.viewConstraints
addObject:[bodyTextView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.textTopMargin]]; addObject:[bodyTextView autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:textInsets.top]];
} }
lastSubview = bodyTextView; lastSubview = bodyTextView;
bottomMargin = self.textBottomMargin; bottomMargin = textInsets.bottom;
} }
UIView *_Nullable tapForMoreLabel = [self createTapForMoreLabelIfNecessary]; UIView *_Nullable tapForMoreLabel = [self createTapForMoreLabelIfNecessary];
@ -424,13 +427,13 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(lastSubview == bodyTextView); OWSAssert(lastSubview == bodyTextView);
[self.bubbleView addSubview:tapForMoreLabel]; [self.bubbleView addSubview:tapForMoreLabel];
[self.viewConstraints addObjectsFromArray:@[ [self.viewConstraints addObjectsFromArray:@[
[tapForMoreLabel autoPinLeadingToSuperviewMarginWithInset:self.textLeadingMargin], [tapForMoreLabel autoPinLeadingToSuperviewMarginWithInset:textInsets.leading],
[tapForMoreLabel autoPinTrailingToSuperviewMarginWithInset:self.textTrailingMargin], [tapForMoreLabel autoPinTrailingToSuperviewMarginWithInset:textInsets.trailing],
[tapForMoreLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:lastSubview], [tapForMoreLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:lastSubview],
[tapForMoreLabel autoSetDimension:ALDimensionHeight toSize:self.tapForMoreHeight], [tapForMoreLabel autoSetDimension:ALDimensionHeight toSize:self.tapForMoreHeight],
]]; ]];
lastSubview = tapForMoreLabel; lastSubview = tapForMoreLabel;
bottomMargin = self.textBottomMargin; bottomMargin = textInsets.bottom;
} }
OWSAssert(lastSubview); OWSAssert(lastSubview);
@ -859,7 +862,10 @@ NS_ASSUME_NONNULL_BEGIN
return CGSizeZero; return CGSizeZero;
} }
CGFloat hMargins = self.textTrailingMargin + self.textLeadingMargin; OWSDirectionalEdgeInsets *textInsets = self.layoutInfo.textInsets;
OWSAssert(textInsets);
CGFloat hMargins = textInsets.leading + textInsets.trailing;
const int maxTextWidth = (int)floor(self.layoutInfo.maxMessageWidth - hMargins); const int maxTextWidth = (int)floor(self.layoutInfo.maxMessageWidth - hMargins);
@ -870,7 +876,7 @@ NS_ASSUME_NONNULL_BEGIN
if (includeMargins) { if (includeMargins) {
result.width += hMargins; result.width += hMargins;
result.height += self.textTopMargin + self.textBottomMargin; result.height += textInsets.top + textInsets.bottom;
} }
return CGSizeCeil(result); return CGSizeCeil(result);
@ -1018,28 +1024,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - #pragma mark -
- (CGFloat)textLeadingMargin
{
CGFloat result = kBubbleTextHInset;
return result;
}
- (CGFloat)textTrailingMargin
{
CGFloat result = kBubbleTextHInset;
return result;
}
- (CGFloat)textTopMargin
{
return kBubbleTextTopInset;
}
- (CGFloat)textBottomMargin
{
return kBubbleTextBottomInset;
}
- (UIColor *)bodyTextColor - (UIColor *)bodyTextColor
{ {
return self.isIncoming ? [UIColor blackColor] : [UIColor whiteColor]; return self.isIncoming ? [UIColor blackColor] : [UIColor whiteColor];

@ -4,6 +4,34 @@
import Foundation import Foundation
@objc
public class OWSDirectionalEdgeInsets: NSObject {
@objc public let leading: CGFloat
@objc public let trailing: CGFloat
@objc public let top: CGFloat
@objc public let bottom: CGFloat
@objc
public required init(top: CGFloat = 0,
leading: CGFloat = 0,
bottom: CGFloat = 0,
trailing: CGFloat = 0) {
self.leading = leading
self.trailing = trailing
self.top = top
self.bottom = bottom
super.init()
}
static var zero = OWSDirectionalEdgeInsets(top: 0,
leading: 0,
bottom: 0,
trailing: 0)
}
@objc @objc
public class ConversationLayoutInfo: NSObject { public class ConversationLayoutInfo: NSObject {
@ -40,6 +68,8 @@ public class ConversationLayoutInfo: NSObject {
@objc public var maxMessageWidth: CGFloat = 0 @objc public var maxMessageWidth: CGFloat = 0
@objc public var maxFooterWidth: CGFloat = 0 @objc public var maxFooterWidth: CGFloat = 0
@objc public var textInsets = OWSDirectionalEdgeInsets.zero
@objc @objc
public required init(thread: TSThread) { public required init(thread: TSThread) {
@ -49,8 +79,25 @@ public class ConversationLayoutInfo: NSObject {
super.init() super.init()
updateProperties() updateProperties()
NotificationCenter.default.addObserver(self,
selector: #selector(uiContentSizeCategoryDidChange),
name: NSNotification.Name.UIContentSizeCategoryDidChange,
object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
@objc func uiContentSizeCategoryDidChange() {
SwiftAssertIsOnMainThread(#function)
updateProperties()
} }
// MARK: -
private func updateProperties() { private func updateProperties() {
if thread.isGroupThread() { if thread.isGroupThread() {
gutterLeading = 40 gutterLeading = 40
@ -70,5 +117,19 @@ public class ConversationLayoutInfo: NSObject {
maxMessageWidth = floor(contentWidth * 0.8) maxMessageWidth = floor(contentWidth * 0.8)
// TODO: Should this be different? // TODO: Should this be different?
maxFooterWidth = maxMessageWidth - 10 maxFooterWidth = maxMessageWidth - 10
let messageTextFont = UIFont.ows_dynamicTypeBody
// Don't include the distance from the "cap height" to the top of the UILabel
// in the top margin.
let textInsetTop = max(0, 12 - (messageTextFont.ascender - messageTextFont.capHeight))
// Don't include the distance from the "baseline" to the bottom of the UILabel
// (e.g. the descender) in the top margin. Note that UIFont.descender is a
// negative value.
let textInsetBottom = max(0, 12 - abs(messageTextFont.descender))
textInsets = OWSDirectionalEdgeInsets(top: textInsetTop,
leading: 12,
bottom: textInsetBottom,
trailing: 12)
} }
} }

@ -346,7 +346,6 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
messageBubbleView.viewItem = viewItem messageBubbleView.viewItem = viewItem
messageBubbleView.cellMediaCache = NSCache() messageBubbleView.cellMediaCache = NSCache()
messageBubbleView.layoutInfo = self.conversationLayoutInfo messageBubbleView.layoutInfo = self.conversationLayoutInfo
messageBubbleView.alwaysShowBubbleTail = true
messageBubbleView.configureViews() messageBubbleView.configureViews()
messageBubbleView.loadContent() messageBubbleView.loadContent()

Loading…
Cancel
Save