fixup quote corners

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 68c7abcbb9
commit 287da9c30a

@ -8,7 +8,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
const CGFloat kOWSMessageCellCornerRadius_Large = 18; const CGFloat kOWSMessageCellCornerRadius_Large = 18;
const CGFloat kOWSMessageCellCornerRadius_Small = 2; const CGFloat kOWSMessageCellCornerRadius_Small = 4;
@interface OWSBubbleView () @interface OWSBubbleView ()

@ -276,7 +276,7 @@ NS_ASSUME_NONNULL_BEGIN
displayableQuotedText:displayableQuotedText displayableQuotedText:displayableQuotedText
conversationStyle:self.conversationStyle conversationStyle:self.conversationStyle
isOutgoing:self.isOutgoing isOutgoing:self.isOutgoing
sharesTopBorderWithMessageBubble:!self.shouldShowSenderName]; sharpCorners:self.sharpCornersForQuotedMessage];
quotedMessageView.delegate = self; quotedMessageView.delegate = self;
self.quotedMessageView = quotedMessageView; self.quotedMessageView = quotedMessageView;
@ -558,7 +558,7 @@ NS_ASSUME_NONNULL_BEGIN
return 12.f; return 12.f;
} }
- (void)configureBubbleRounding - (UIRectCorner)sharpCorners
{ {
UIRectCorner sharpCorners = 0; UIRectCorner sharpCorners = 0;
@ -570,7 +570,21 @@ NS_ASSUME_NONNULL_BEGIN
sharpCorners = sharpCorners | (self.isIncoming ? UIRectCornerBottomLeft : UIRectCornerBottomRight); sharpCorners = sharpCorners | (self.isIncoming ? UIRectCornerBottomLeft : UIRectCornerBottomRight);
} }
self.bubbleView.sharpCorners = sharpCorners; return sharpCorners;
}
- (UIRectCorner)sharpCornersForQuotedMessage
{
if (self.viewItem.senderName) {
return UIRectCornerAllCorners;
} else {
return self.sharpCorners & UIRectCornerAllCorners;
}
}
- (void)configureBubbleRounding
{
self.bubbleView.sharpCorners = self.sharpCorners;
} }
- (void)updateBubbleColor - (void)updateBubbleColor
@ -1213,7 +1227,7 @@ NS_ASSUME_NONNULL_BEGIN
displayableQuotedText:displayableQuotedText displayableQuotedText:displayableQuotedText
conversationStyle:self.conversationStyle conversationStyle:self.conversationStyle
isOutgoing:self.isOutgoing isOutgoing:self.isOutgoing
sharesTopBorderWithMessageBubble:NO]; sharpCorners:self.sharpCornersForQuotedMessage];
CGSize result = [quotedMessageView sizeForMaxWidth:self.conversationStyle.maxMessageWidth]; CGSize result = [quotedMessageView sizeForMaxWidth:self.conversationStyle.maxMessageWidth];
return [NSValue valueWithCGSize:CGSizeCeil(result)]; return [NSValue valueWithCGSize:CGSizeCeil(result)];
} }

@ -35,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
displayableQuotedText:(nullable DisplayableText *)displayableQuotedText displayableQuotedText:(nullable DisplayableText *)displayableQuotedText
conversationStyle:(ConversationStyle *)conversationStyle conversationStyle:(ConversationStyle *)conversationStyle
isOutgoing:(BOOL)isOutgoing isOutgoing:(BOOL)isOutgoing
sharesTopBorderWithMessageBubble:(BOOL)sharesTopBorderWithMessageBubble; sharpCorners:(UIRectCorner)sharpCorners;
// Factory method for "message compose" views. // Factory method for "message compose" views.
+ (OWSQuotedMessageView *)quotedMessageViewForPreview:(OWSQuotedReplyModel *)quotedMessage + (OWSQuotedMessageView *)quotedMessageViewForPreview:(OWSQuotedReplyModel *)quotedMessage

@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) BOOL isForPreview; @property (nonatomic, readonly) BOOL isForPreview;
@property (nonatomic, readonly) BOOL isOutgoing; @property (nonatomic, readonly) BOOL isOutgoing;
@property (nonatomic, readonly) BOOL sharesTopBorderWithMessageBubble; @property (nonatomic, readonly) UIRectCorner sharpCorners;
@property (nonatomic, readonly) UILabel *quotedAuthorLabel; @property (nonatomic, readonly) UILabel *quotedAuthorLabel;
@property (nonatomic, readonly) UILabel *quotedTextLabel; @property (nonatomic, readonly) UILabel *quotedTextLabel;
@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN
displayableQuotedText:(nullable DisplayableText *)displayableQuotedText displayableQuotedText:(nullable DisplayableText *)displayableQuotedText
conversationStyle:(ConversationStyle *)conversationStyle conversationStyle:(ConversationStyle *)conversationStyle
isOutgoing:(BOOL)isOutgoing isOutgoing:(BOOL)isOutgoing
sharesTopBorderWithMessageBubble:(BOOL)sharesTopBorderWithMessageBubble sharpCorners:(UIRectCorner)sharpCorners
{ {
OWSAssert(quotedMessage); OWSAssert(quotedMessage);
@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
conversationStyle:conversationStyle conversationStyle:conversationStyle
isForPreview:NO isForPreview:NO
isOutgoing:isOutgoing isOutgoing:isOutgoing
sharesTopBorderWithMessageBubble:sharesTopBorderWithMessageBubble]; sharpCorners:sharpCorners];
} }
+ (OWSQuotedMessageView *)quotedMessageViewForPreview:(OWSQuotedReplyModel *)quotedMessage + (OWSQuotedMessageView *)quotedMessageViewForPreview:(OWSQuotedReplyModel *)quotedMessage
@ -67,7 +67,7 @@ NS_ASSUME_NONNULL_BEGIN
conversationStyle:conversationStyle conversationStyle:conversationStyle
isForPreview:YES isForPreview:YES
isOutgoing:YES isOutgoing:YES
sharesTopBorderWithMessageBubble:NO]; sharpCorners:UIRectCornerAllCorners];
[instance createContents]; [instance createContents];
return instance; return instance;
} }
@ -77,7 +77,7 @@ NS_ASSUME_NONNULL_BEGIN
conversationStyle:(ConversationStyle *)conversationStyle conversationStyle:(ConversationStyle *)conversationStyle
isForPreview:(BOOL)isForPreview isForPreview:(BOOL)isForPreview
isOutgoing:(BOOL)isOutgoing isOutgoing:(BOOL)isOutgoing
sharesTopBorderWithMessageBubble:(BOOL)sharesTopBorderWithMessageBubble sharpCorners:(UIRectCorner)sharpCorners
{ {
self = [super init]; self = [super init];
@ -92,7 +92,7 @@ NS_ASSUME_NONNULL_BEGIN
_isForPreview = isForPreview; _isForPreview = isForPreview;
_conversationStyle = conversationStyle; _conversationStyle = conversationStyle;
_isOutgoing = isOutgoing; _isOutgoing = isOutgoing;
_sharesTopBorderWithMessageBubble = sharesTopBorderWithMessageBubble; _sharpCorners = sharpCorners;
_quotedAuthorLabel = [UILabel new]; _quotedAuthorLabel = [UILabel new];
_quotedTextLabel = [UILabel new]; _quotedTextLabel = [UILabel new];
@ -151,7 +151,8 @@ NS_ASSUME_NONNULL_BEGIN
self.clipsToBounds = YES; self.clipsToBounds = YES;
CAShapeLayer *maskLayer = [CAShapeLayer new]; CAShapeLayer *maskLayer = [CAShapeLayer new];
BOOL sharesTopBorderWithMessageBubble = self.sharesTopBorderWithMessageBubble; UIRectCorner sharpCorners = self.sharpCorners;
OWSLayerView *innerBubbleView = [[OWSLayerView alloc] OWSLayerView *innerBubbleView = [[OWSLayerView alloc]
initWithFrame:CGRectZero initWithFrame:CGRectZero
layoutCallback:^(UIView *layerView) { layoutCallback:^(UIView *layerView) {
@ -159,26 +160,70 @@ NS_ASSUME_NONNULL_BEGIN
UIBezierPath *bezierPath = [UIBezierPath new]; UIBezierPath *bezierPath = [UIBezierPath new];
CGFloat bubbleLeft = 0.f; const CGFloat bubbleLeft = 0.f;
CGFloat bubbleRight = layerFrame.size.width; const CGFloat bubbleRight = layerFrame.size.width;
CGFloat bubbleTop = 0.f; const CGFloat bubbleTop = 0.f;
CGFloat bubbleBottom = layerFrame.size.height; const CGFloat bubbleBottom = layerFrame.size.height;
CGFloat bubbleTopRounding = (sharesTopBorderWithMessageBubble ? 10.f : 4.f);
CGFloat bubbleBottomRounding = 4.f; const CGFloat sharpCornerRadius = 4;
const CGFloat wideCornerRadius = 10;
[bezierPath moveToPoint:CGPointMake(bubbleLeft + bubbleTopRounding, bubbleTop)];
[bezierPath addLineToPoint:CGPointMake(bubbleRight - bubbleTopRounding, bubbleTop)]; const CGFloat topLeftRounding = (sharpCorners & UIRectCornerTopLeft) ? sharpCornerRadius : wideCornerRadius;
[bezierPath addQuadCurveToPoint:CGPointMake(bubbleRight, bubbleTop + bubbleTopRounding) const CGFloat topRightRounding
controlPoint:CGPointMake(bubbleRight, bubbleTop)]; = (sharpCorners & UIRectCornerTopRight) ? sharpCornerRadius : wideCornerRadius;
[bezierPath addLineToPoint:CGPointMake(bubbleRight, bubbleBottom - bubbleBottomRounding)];
[bezierPath addQuadCurveToPoint:CGPointMake(bubbleRight - bubbleBottomRounding, bubbleBottom) // bottom corners are always sharp
controlPoint:CGPointMake(bubbleRight, bubbleBottom)]; const CGFloat bottomRightRounding = sharpCornerRadius;
[bezierPath addLineToPoint:CGPointMake(bubbleLeft + bubbleBottomRounding, bubbleBottom)]; const CGFloat bottomLeftRounding = sharpCornerRadius;
[bezierPath addQuadCurveToPoint:CGPointMake(bubbleLeft, bubbleBottom - bubbleBottomRounding)
controlPoint:CGPointMake(bubbleLeft, bubbleBottom)]; const CGFloat topAngle = 3.0f * M_PI / 2.0f;
[bezierPath addLineToPoint:CGPointMake(bubbleLeft, bubbleTop + bubbleTopRounding)]; const CGFloat rightAngle = 0.0f;
[bezierPath addQuadCurveToPoint:CGPointMake(bubbleLeft + bubbleTopRounding, bubbleTop) const CGFloat bottomAngle = M_PI / 2.0f;
controlPoint:CGPointMake(bubbleLeft, bubbleTop)]; const CGFloat leftAngle = M_PI;
// starting just to the right of the top left corner and working clockwise
[bezierPath moveToPoint:CGPointMake(bubbleLeft + topLeftRounding, bubbleTop)];
// top line
[bezierPath addLineToPoint:CGPointMake(bubbleRight - topRightRounding, bubbleTop)];
// top right corner
[bezierPath addArcWithCenter:CGPointMake(bubbleRight - topRightRounding, bubbleTop + topRightRounding)
radius:topRightRounding
startAngle:topAngle
endAngle:rightAngle
clockwise:true];
// right line
[bezierPath addLineToPoint:CGPointMake(bubbleRight, bubbleBottom - bottomRightRounding)];
// bottom right corner
[bezierPath
addArcWithCenter:CGPointMake(bubbleRight - bottomRightRounding, bubbleBottom - bottomRightRounding)
radius:bottomRightRounding
startAngle:rightAngle
endAngle:bottomAngle
clockwise:true];
// bottom line
[bezierPath addLineToPoint:CGPointMake(bubbleLeft + bottomLeftRounding, bubbleBottom)];
// bottom left corner
[bezierPath addArcWithCenter:CGPointMake(bubbleLeft + bottomLeftRounding, bubbleBottom - bottomLeftRounding)
radius:bottomLeftRounding
startAngle:bottomAngle
endAngle:leftAngle
clockwise:true];
// left line
[bezierPath addLineToPoint:CGPointMake(bubbleLeft, bubbleTop + topLeftRounding)];
// top left corner
[bezierPath addArcWithCenter:CGPointMake(bubbleLeft + topLeftRounding, bubbleTop + topLeftRounding)
radius:topLeftRounding
startAngle:leftAngle
endAngle:topAngle
clockwise:true];
maskLayer.path = bezierPath.CGPath; maskLayer.path = bezierPath.CGPath;
}]; }];

Loading…
Cancel
Save