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 kBubbleTextHInset;
extern const CGFloat kBubbleTextTopInset;
extern const CGFloat kBubbleTextBottomInset;
@class OWSBubbleView;
@protocol OWSBubbleViewPartner <NSObject>

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

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

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

@ -4,6 +4,34 @@
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
public class ConversationLayoutInfo: NSObject {
@ -40,6 +68,8 @@ public class ConversationLayoutInfo: NSObject {
@objc public var maxMessageWidth: CGFloat = 0
@objc public var maxFooterWidth: CGFloat = 0
@objc public var textInsets = OWSDirectionalEdgeInsets.zero
@objc
public required init(thread: TSThread) {
@ -49,8 +79,25 @@ public class ConversationLayoutInfo: NSObject {
super.init()
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() {
if thread.isGroupThread() {
gutterLeading = 40
@ -70,5 +117,19 @@ public class ConversationLayoutInfo: NSObject {
maxMessageWidth = floor(contentWidth * 0.8)
// TODO: Should this be different?
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.cellMediaCache = NSCache()
messageBubbleView.layoutInfo = self.conversationLayoutInfo
messageBubbleView.alwaysShowBubbleTail = true
messageBubbleView.configureViews()
messageBubbleView.loadContent()

Loading…
Cancel
Save