From 3b726bbac9dee0aa45e0814b5c578f5d20951cc0 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 2 Jul 2018 12:57:07 -0400 Subject: [PATCH 1/2] Small media corners. --- .../ConversationView/Cells/OWSBubbleView.h | 8 ++- .../ConversationView/Cells/OWSBubbleView.m | 61 ++++++++++++++++--- .../Cells/OWSMessageBubbleView.m | 14 ++++- .../MediaGalleryViewController.swift | 4 +- 4 files changed, 74 insertions(+), 13 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h index bb1a9f4f1..10799dc95 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.h @@ -6,7 +6,8 @@ NS_ASSUME_NONNULL_BEGIN -extern const CGFloat kOWSMessageCellCornerRadius; +extern const CGFloat kOWSMessageCellCornerRadius_Large; +extern const CGFloat kOWSMessageCellCornerRadius_Small; @class OWSBubbleView; @@ -24,6 +25,9 @@ extern const CGFloat kOWSMessageCellCornerRadius; @property (nonatomic, nullable) UIColor *bubbleColor; +@property (nonatomic) BOOL useSmallCorners_Top; +@property (nonatomic) BOOL useSmallCorners_Bottom; + - (UIBezierPath *)maskPath; #pragma mark - Coordination @@ -34,7 +38,7 @@ extern const CGFloat kOWSMessageCellCornerRadius; - (void)updatePartnerViews; -+ (CGFloat)minWidth; +- (CGFloat)minWidth; @end diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m index db7795629..268dfa328 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSBubbleView.m @@ -7,7 +7,8 @@ NS_ASSUME_NONNULL_BEGIN -const CGFloat kOWSMessageCellCornerRadius = 16; +const CGFloat kOWSMessageCellCornerRadius_Large = 16; +const CGFloat kOWSMessageCellCornerRadius_Small = 2; @interface OWSBubbleView () @@ -89,9 +90,7 @@ const CGFloat kOWSMessageCellCornerRadius = 16; { _bubbleColor = bubbleColor; - if (!self.shapeLayer) { - [self updateLayers]; - } + [self updateLayers]; // Prevent the shape layer from animating changes. [CATransaction begin]; @@ -102,6 +101,20 @@ const CGFloat kOWSMessageCellCornerRadius = 16; [CATransaction commit]; } +- (void)setUseSmallCorners_Top:(BOOL)useSmallCorners_Top +{ + _useSmallCorners_Top = useSmallCorners_Top; + + [self updateLayers]; +} + +- (void)setUseSmallCorners_Bottom:(BOOL)useSmallCorners_Bottom +{ + _useSmallCorners_Bottom = useSmallCorners_Bottom; + + [self updateLayers]; +} + - (void)updateLayers { if (!self.maskLayer) { @@ -126,14 +139,42 @@ const CGFloat kOWSMessageCellCornerRadius = 16; - (UIBezierPath *)maskPath { - return [self.class maskPathForSize:self.bounds.size]; + return [self.class maskPathForSize:self.bounds.size + useSmallCorners_Top:self.useSmallCorners_Top + useSmallCorners_Bottom:self.useSmallCorners_Bottom]; } + (UIBezierPath *)maskPathForSize:(CGSize)size + useSmallCorners_Top:(BOOL)useSmallCorners_Top + useSmallCorners_Bottom:(BOOL)useSmallCorners_Bottom { CGRect bounds = CGRectZero; bounds.size = size; - UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:kOWSMessageCellCornerRadius]; + + UIBezierPath *bezierPath = [UIBezierPath new]; + + CGFloat bubbleLeft = 0.f; + CGFloat bubbleRight = size.width; + CGFloat bubbleTop = 0.f; + CGFloat bubbleBottom = size.height; + CGFloat topRounding = (useSmallCorners_Top ? kOWSMessageCellCornerRadius_Small : kOWSMessageCellCornerRadius_Large); + CGFloat bottomRounding + = (useSmallCorners_Bottom ? kOWSMessageCellCornerRadius_Small : kOWSMessageCellCornerRadius_Large); + + [bezierPath moveToPoint:CGPointMake(bubbleLeft + topRounding, bubbleTop)]; + [bezierPath addLineToPoint:CGPointMake(bubbleRight - topRounding, bubbleTop)]; + [bezierPath addQuadCurveToPoint:CGPointMake(bubbleRight, bubbleTop + topRounding) + controlPoint:CGPointMake(bubbleRight, bubbleTop)]; + [bezierPath addLineToPoint:CGPointMake(bubbleRight, bubbleBottom - bottomRounding)]; + [bezierPath addQuadCurveToPoint:CGPointMake(bubbleRight - bottomRounding, bubbleBottom) + controlPoint:CGPointMake(bubbleRight, bubbleBottom)]; + [bezierPath addLineToPoint:CGPointMake(bubbleLeft + bottomRounding, bubbleBottom)]; + [bezierPath addQuadCurveToPoint:CGPointMake(bubbleLeft, bubbleBottom - bottomRounding) + controlPoint:CGPointMake(bubbleLeft, bubbleBottom)]; + [bezierPath addLineToPoint:CGPointMake(bubbleLeft, bubbleTop + topRounding)]; + [bezierPath addQuadCurveToPoint:CGPointMake(bubbleLeft + topRounding, bubbleTop) + controlPoint:CGPointMake(bubbleLeft, bubbleTop)]; + return bezierPath; } @@ -164,9 +205,13 @@ const CGFloat kOWSMessageCellCornerRadius = 16; } } -+ (CGFloat)minWidth +- (CGFloat)minWidth { - return (kOWSMessageCellCornerRadius * 2); + if (self.useSmallCorners_Top && self.useSmallCorners_Bottom) { + return (kOWSMessageCellCornerRadius_Small * 2); + } else { + return (kOWSMessageCellCornerRadius_Large * 2); + } } @end diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 43edf3f85..645118317 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -488,6 +488,16 @@ NS_ASSUME_NONNULL_BEGIN // If we're stroking the bubble edge, ensure the stroke // view is in front of its peers to prevent it from being occluded. [self.bubbleStrokeView.superview bringSubviewToFront:self.bubbleStrokeView]; + + [self configureBubbleRounding]; +} + +- (void)configureBubbleRounding +{ + self.bubbleView.useSmallCorners_Top + = (self.hasBodyMediaWithThumbnail && !self.shouldShowSenderName && !self.isQuotedReply); + self.bubbleView.useSmallCorners_Bottom + = (self.hasBodyMediaWithThumbnail && !self.hasBodyText && !self.hasBottomFooter); } - (void)updateBubbleColor @@ -1164,6 +1174,8 @@ NS_ASSUME_NONNULL_BEGIN CGSize cellSize = CGSizeZero; + [self configureBubbleRounding]; + NSMutableArray *textViewSizes = [NSMutableArray new]; NSValue *_Nullable senderNameSize = [self senderNameSize]; @@ -1221,7 +1233,7 @@ NS_ASSUME_NONNULL_BEGIN } // Make sure the bubble is always wide enough to complete it's bubble shape. - cellSize.width = MAX(cellSize.width, OWSBubbleView.minWidth); + cellSize.width = MAX(cellSize.width, self.bubbleView.minWidth); OWSAssert(cellSize.width > 0 && cellSize.height > 0); diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index fd5255920..fe63614c6 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -342,7 +342,7 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc detailView.backgroundColor = .clear self.view.backgroundColor = .clear - self.presentationView.layer.cornerRadius = kOWSMessageCellCornerRadius + self.presentationView.layer.cornerRadius = kOWSMessageCellCornerRadius_Large fromViewController.present(self, animated: false) { @@ -505,7 +505,7 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc if changedItems { self.presentationView.alpha = 0 } else { - self.presentationView.layer.cornerRadius = kOWSMessageCellCornerRadius + self.presentationView.layer.cornerRadius = kOWSMessageCellCornerRadius_Large } }, completion: { (_: Bool) in From fb0ac32171c4f236f98421413c999a1c1fa085be Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 2 Jul 2018 16:24:37 -0400 Subject: [PATCH 2/2] Respond to CR. --- Signal/src/ViewControllers/MediaGalleryViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Signal/src/ViewControllers/MediaGalleryViewController.swift b/Signal/src/ViewControllers/MediaGalleryViewController.swift index fe63614c6..c1bf2908c 100644 --- a/Signal/src/ViewControllers/MediaGalleryViewController.swift +++ b/Signal/src/ViewControllers/MediaGalleryViewController.swift @@ -342,6 +342,7 @@ class MediaGalleryViewController: OWSNavigationController, MediaGalleryDataSourc detailView.backgroundColor = .clear self.view.backgroundColor = .clear + // TODO: Sync with (possibly assymetrical) corner rounding in message bubbles. self.presentationView.layer.cornerRadius = kOWSMessageCellCornerRadius_Large fromViewController.present(self, animated: false) {