From fa89a84daf9e580df145358e4328aeecee866ac1 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 6 Jul 2018 16:13:25 -0600 Subject: [PATCH] CR: move builder to BubbleView --- .../Cells/OWSBubbleShapeView.h | 8 --- .../Cells/OWSBubbleShapeView.m | 54 --------------- .../ConversationView/Cells/OWSBubbleView.h | 8 +++ .../ConversationView/Cells/OWSBubbleView.m | 69 ++++++++++++++++--- .../Cells/OWSQuotedMessageView.m | 16 ++--- 5 files changed, 77 insertions(+), 78 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.h b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.h index 6f9b879bf..f05cc46fe 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.h @@ -30,14 +30,6 @@ NS_ASSUME_NONNULL_BEGIN + (OWSBubbleShapeView *)bubbleShadowView; + (OWSBubbleShapeView *)bubbleClipView; -+ (UIBezierPath *)roundedBezierRectWithBubbleTop:(CGFloat)bubbleTop - bubbleLeft:(CGFloat)bubbleLeft - bubbleBottom:(CGFloat)bubbleBottom - bubbleRight:(CGFloat)bubbleRight - sharpCornerRadius:(CGFloat)sharpCornerRadius - wideCornerRadius:(CGFloat)wideCornerRadius - sharpCorners:(UIRectCorner)sharpCorners; - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.m index d6cba0e29..7d387696d 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleShapeView.m @@ -193,60 +193,6 @@ typedef NS_ENUM(NSUInteger, OWSBubbleShapeViewMode) { [CATransaction commit]; } -+ (UIBezierPath *)roundedBezierRectWithBubbleTop:(CGFloat)bubbleTop - bubbleLeft:(CGFloat)bubbleLeft - bubbleBottom:(CGFloat)bubbleBottom - bubbleRight:(CGFloat)bubbleRight - sharpCornerRadius:(CGFloat)sharpCornerRadius - wideCornerRadius:(CGFloat)wideCornerRadius - sharpCorners:(UIRectCorner)sharpCorners -{ - UIBezierPath *bezierPath = [UIBezierPath new]; - - const CGFloat topLeftRounding = (sharpCorners & UIRectCornerTopLeft) ? sharpCornerRadius : wideCornerRadius; - const CGFloat topRightRounding = (sharpCorners & UIRectCornerTopRight) ? sharpCornerRadius : wideCornerRadius; - - const CGFloat bottomRightRounding = (sharpCorners & UIRectCornerBottomRight) ? sharpCornerRadius : wideCornerRadius; - const CGFloat bottomLeftRounding = (sharpCorners & UIRectCornerBottomLeft) ? sharpCornerRadius : wideCornerRadius; - - const CGFloat topAngle = 3.0f * M_PI_2; - const CGFloat rightAngle = 0.0f; - const CGFloat bottomAngle = M_PI_2; - 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 right corner - [bezierPath addArcWithCenter:CGPointMake(bubbleRight - topRightRounding, bubbleTop + topRightRounding) - radius:topRightRounding - startAngle:topAngle - endAngle:rightAngle - clockwise:true]; - - // bottom right corner - [bezierPath addArcWithCenter:CGPointMake(bubbleRight - bottomRightRounding, bubbleBottom - bottomRightRounding) - radius:bottomRightRounding - startAngle:rightAngle - endAngle:bottomAngle - clockwise:true]; - - // bottom left corner - [bezierPath addArcWithCenter:CGPointMake(bubbleLeft + bottomLeftRounding, bubbleBottom - bottomLeftRounding) - radius:bottomLeftRounding - startAngle:bottomAngle - endAngle:leftAngle - clockwise:true]; - - // top left corner - [bezierPath addArcWithCenter:CGPointMake(bubbleLeft + topLeftRounding, bubbleTop + topLeftRounding) - radius:topLeftRounding - startAngle:leftAngle - endAngle:topAngle - clockwise:true]; - return bezierPath; -} - @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h index d5866b206..bd109daf3 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h @@ -23,6 +23,14 @@ extern const CGFloat kOWSMessageCellCornerRadius_Small; @interface OWSBubbleView : UIView ++ (UIBezierPath *)roundedBezierRectWithBubbleTop:(CGFloat)bubbleTop + bubbleLeft:(CGFloat)bubbleLeft + bubbleBottom:(CGFloat)bubbleBottom + bubbleRight:(CGFloat)bubbleRight + sharpCornerRadius:(CGFloat)sharpCornerRadius + wideCornerRadius:(CGFloat)wideCornerRadius + sharpCorners:(UIRectCorner)sharpCorners; + @property (nonatomic, nullable) UIColor *bubbleColor; @property (nonatomic) UIRectCorner sharpCorners; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m index 3e74a5acb..831ffb4b3 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m @@ -3,7 +3,6 @@ // #import "OWSBubbleView.h" -#import "OWSBubbleShapeView.h" #import NS_ASSUME_NONNULL_BEGIN @@ -148,13 +147,67 @@ const CGFloat kOWSMessageCellCornerRadius_Small = 4; CGFloat bubbleBottom = size.height; CGFloat bubbleRight = size.width; - return [OWSBubbleShapeView roundedBezierRectWithBubbleTop:bubbleTop - bubbleLeft:bubbleLeft - bubbleBottom:bubbleBottom - bubbleRight:bubbleRight - sharpCornerRadius:kOWSMessageCellCornerRadius_Small - wideCornerRadius:kOWSMessageCellCornerRadius_Large - sharpCorners:sharpCorners]; + return [OWSBubbleView roundedBezierRectWithBubbleTop:bubbleTop + bubbleLeft:bubbleLeft + bubbleBottom:bubbleBottom + bubbleRight:bubbleRight + sharpCornerRadius:kOWSMessageCellCornerRadius_Small + wideCornerRadius:kOWSMessageCellCornerRadius_Large + sharpCorners:sharpCorners]; +} + ++ (UIBezierPath *)roundedBezierRectWithBubbleTop:(CGFloat)bubbleTop + bubbleLeft:(CGFloat)bubbleLeft + bubbleBottom:(CGFloat)bubbleBottom + bubbleRight:(CGFloat)bubbleRight + sharpCornerRadius:(CGFloat)sharpCornerRadius + wideCornerRadius:(CGFloat)wideCornerRadius + sharpCorners:(UIRectCorner)sharpCorners +{ + UIBezierPath *bezierPath = [UIBezierPath new]; + + const CGFloat topLeftRounding = (sharpCorners & UIRectCornerTopLeft) ? sharpCornerRadius : wideCornerRadius; + const CGFloat topRightRounding = (sharpCorners & UIRectCornerTopRight) ? sharpCornerRadius : wideCornerRadius; + + const CGFloat bottomRightRounding = (sharpCorners & UIRectCornerBottomRight) ? sharpCornerRadius : wideCornerRadius; + const CGFloat bottomLeftRounding = (sharpCorners & UIRectCornerBottomLeft) ? sharpCornerRadius : wideCornerRadius; + + const CGFloat topAngle = 3.0f * M_PI_2; + const CGFloat rightAngle = 0.0f; + const CGFloat bottomAngle = M_PI_2; + 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 right corner + [bezierPath addArcWithCenter:CGPointMake(bubbleRight - topRightRounding, bubbleTop + topRightRounding) + radius:topRightRounding + startAngle:topAngle + endAngle:rightAngle + clockwise:true]; + + // bottom right corner + [bezierPath addArcWithCenter:CGPointMake(bubbleRight - bottomRightRounding, bubbleBottom - bottomRightRounding) + radius:bottomRightRounding + startAngle:rightAngle + endAngle:bottomAngle + clockwise:true]; + + // bottom left corner + [bezierPath addArcWithCenter:CGPointMake(bubbleLeft + bottomLeftRounding, bubbleBottom - bottomLeftRounding) + radius:bottomLeftRounding + startAngle:bottomAngle + endAngle:leftAngle + clockwise:true]; + + // top left corner + [bezierPath addArcWithCenter:CGPointMake(bubbleLeft + topLeftRounding, bubbleTop + topLeftRounding) + radius:topLeftRounding + startAngle:leftAngle + endAngle:topAngle + clockwise:true]; + return bezierPath; } #pragma mark - Coordination diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m index 96003d0eb..3451e7d99 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m @@ -5,7 +5,7 @@ #import "OWSQuotedMessageView.h" #import "ConversationViewItem.h" #import "Environment.h" -#import "OWSBubbleShapeView.h" +#import "OWSBubbleView.h" #import "Signal-Swift.h" #import #import @@ -166,13 +166,13 @@ NS_ASSUME_NONNULL_BEGIN const CGFloat sharpCornerRadius = 4; const CGFloat wideCornerRadius = 10; - UIBezierPath *bezierPath = [OWSBubbleShapeView roundedBezierRectWithBubbleTop:bubbleTop - bubbleLeft:bubbleLeft - bubbleBottom:bubbleBottom - bubbleRight:bubbleRight - sharpCornerRadius:sharpCornerRadius - wideCornerRadius:wideCornerRadius - sharpCorners:sharpCorners]; + UIBezierPath *bezierPath = [OWSBubbleView roundedBezierRectWithBubbleTop:bubbleTop + bubbleLeft:bubbleLeft + bubbleBottom:bubbleBottom + bubbleRight:bubbleRight + sharpCornerRadius:sharpCornerRadius + wideCornerRadius:wideCornerRadius + sharpCorners:sharpCorners]; maskLayer.path = bezierPath.CGPath; }];