Bubble collapse.

pull/1/head
Matthew Chen 7 years ago
parent 3ca2c08b06
commit 4f9085a761

@ -21,6 +21,7 @@ extern const CGFloat kBubbleTextVInset;
@property (nonatomic) BOOL isOutgoing; @property (nonatomic) BOOL isOutgoing;
@property (nonatomic) BOOL hideTail; @property (nonatomic) BOOL hideTail;
@property (nonatomic) BOOL isTruncated;
@property (nonatomic, nullable) UIColor *bubbleColor; @property (nonatomic, nullable) UIColor *bubbleColor;

@ -51,6 +51,17 @@ const CGFloat kBubbleTextVInset = 10.f;
} }
} }
- (void)setIsTruncated:(BOOL)isTruncated
{
BOOL didChange = _isTruncated != isTruncated;
_isTruncated = isTruncated;
if (didChange || !self.shapeLayer) {
[self updateLayers];
}
}
- (void)setFrame:(CGRect)frame - (void)setFrame:(CGRect)frame
{ {
BOOL didChange = !CGSizeEqualToSize(self.frame.size, frame.size); BOOL didChange = !CGSizeEqualToSize(self.frame.size, frame.size);
@ -121,15 +132,20 @@ const CGFloat kBubbleTextVInset = 10.f;
return [self.class maskPathForSize:self.bounds.size return [self.class maskPathForSize:self.bounds.size
isOutgoing:self.isOutgoing isOutgoing:self.isOutgoing
hideTail:self.hideTail hideTail:self.hideTail
isTruncated:self.isTruncated
isRTL:self.isRTL]; isRTL:self.isRTL];
} }
+ (UIBezierPath *)maskPathForSize:(CGSize)size isOutgoing:(BOOL)isOutgoing hideTail:(BOOL)hideTail isRTL:(BOOL)isRTL + (UIBezierPath *)maskPathForSize:(CGSize)size
isOutgoing:(BOOL)isOutgoing
hideTail:(BOOL)hideTail
isTruncated:(BOOL)isTruncated
isRTL:(BOOL)isRTL
{ {
UIBezierPath *bezierPath = [UIBezierPath new]; UIBezierPath *bezierPath = [UIBezierPath new];
CGFloat bubbleLeft = 0.f; CGFloat bubbleLeft = 0.f;
CGFloat bubbleRight = size.width - (hideTail ? 0.f : kBubbleThornSideInset); CGFloat bubbleRight = size.width - kBubbleThornSideInset;
CGFloat bubbleTop = 0.f; CGFloat bubbleTop = 0.f;
CGFloat bubbleBottom = size.height - kBubbleThornVInset; CGFloat bubbleBottom = size.height - kBubbleThornVInset;

@ -465,22 +465,6 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
bottomMargin = self.textBottomMargin; bottomMargin = self.textBottomMargin;
} }
#ifdef DEBUG
DDLogVerbose(
@"%@ --- bodyMediaView: %@ [%@].", self.logTag, bodyMediaView, NSStringFromCGSize(bodyMediaContentSize));
DDLogVerbose(@"%@ --- bodyTextView: %@ (%zd) [%@].",
self.logTag,
bodyTextView.text,
bodyTextView.text.length,
NSStringFromCGSize(bodyTextContentSize));
[bodyMediaView logFrameLaterWithLabel:@"bodyMediaView"];
[bodyTextView logFrameLaterWithLabel:@"bodyTextView"];
[self.bubbleView logFrameLaterWithLabel:@"bubbleView"];
[self.contentView logFrameLaterWithLabel:@"contentView"];
// [bodyMediaView addRedBorder];
// [bodyTextView addRedBorder];
#endif
UIView *_Nullable tapForMoreLabel = [self createTapForMoreLabelIfNecessary]; UIView *_Nullable tapForMoreLabel = [self createTapForMoreLabelIfNecessary];
if (tapForMoreLabel) { if (tapForMoreLabel) {
OWSAssert(lastSubview); OWSAssert(lastSubview);
@ -765,12 +749,20 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
textView.shouldIgnoreEvents = shouldIgnoreEvents; textView.shouldIgnoreEvents = shouldIgnoreEvents;
} }
- (nullable UIView *)createTapForMoreLabelIfNecessary - (BOOL)hasTapForMore
{ {
if (!self.hasBodyText) { if (!self.hasBodyText) {
return nil; return NO;
} else if (!self.displayableBodyText.isTextTruncated) {
return NO;
} else {
return YES;
} }
if (!self.displayableBodyText.isTextTruncated) { }
- (nullable UIView *)createTapForMoreLabelIfNecessary
{
if (!self.hasTapForMore) {
return nil; return nil;
} }
@ -1124,7 +1116,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
cellSize.height += self.dateHeaderHeight; cellSize.height += self.dateHeaderHeight;
cellSize.height += self.footerHeight; cellSize.height += self.footerHeight;
if (self.hasBodyText && self.displayableBodyText.isTextTruncated) { if (self.hasTapForMore) {
cellSize.height += self.tapForMoreHeight; cellSize.height += self.tapForMoreHeight;
} }
@ -1134,14 +1126,6 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
cellSize = CGSizeCeil(cellSize); cellSize = CGSizeCeil(cellSize);
DDLogVerbose(@"%@ --- cellSizeForViewWidth: %@ + %@ + %f + %f = %@.",
self.logTag,
NSStringFromCGSize(mediaContentSize),
NSStringFromCGSize(textContentSize),
self.dateHeaderHeight,
self.footerHeight,
NSStringFromCGSize(cellSize));
return cellSize; return cellSize;
} }
@ -1170,7 +1154,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
- (CGFloat)textLeadingMargin - (CGFloat)textLeadingMargin
{ {
CGFloat result = kBubbleTextHInset; CGFloat result = kBubbleTextHInset;
if (self.isIncoming && !self.viewItem.shouldHideBubbleTail) { if (self.isIncoming) {
result += kBubbleThornSideInset; result += kBubbleThornSideInset;
} }
return result; return result;
@ -1179,7 +1163,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
- (CGFloat)textTrailingMargin - (CGFloat)textTrailingMargin
{ {
CGFloat result = kBubbleTextHInset; CGFloat result = kBubbleTextHInset;
if (!self.isIncoming && !self.viewItem.shouldHideBubbleTail) { if (!self.isIncoming) {
result += kBubbleThornSideInset; result += kBubbleThornSideInset;
} }
return result; return result;
@ -1334,7 +1318,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
} }
} }
if (self.hasBodyText && self.displayableBodyText.isTextTruncated) { if (self.hasTapForMore) {
[self.delegate didTapTruncatedTextMessage:self.viewItem]; [self.delegate didTapTruncatedTextMessage:self.viewItem];
return; return;
} }
@ -1365,7 +1349,7 @@ CG_INLINE CGSize CGSizeCeil(CGSize size)
break; break;
case OWSMessageCellType_TextMessage: case OWSMessageCellType_TextMessage:
case OWSMessageCellType_OversizeTextMessage: case OWSMessageCellType_OversizeTextMessage:
if (self.displayableBodyText.isTextTruncated) { if (self.hasTapForMore) {
[self.delegate didTapTruncatedTextMessage:self.viewItem]; [self.delegate didTapTruncatedTextMessage:self.viewItem];
return; return;
} }

@ -411,12 +411,6 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
} }
} }
DDLogVerbose(@"%@ --- message. hasAttachments: %d, body: %@ (%zd).",
self.logTag,
message.hasAttachments,
message.body,
message.body.length);
// Ignore message body for oversize text attachments. // Ignore message body for oversize text attachments.
if (message.body.length > 0) { if (message.body.length > 0) {
if (self.hasBodyText) { if (self.hasBodyText) {

@ -59,6 +59,8 @@ NS_ASSUME_NONNULL_BEGIN
// Fake Text // Fake Text
[DebugUIMessages fakeAllTextAction:thread], [DebugUIMessages fakeAllTextAction:thread],
[DebugUIMessages fakeRandomTextAction:thread], [DebugUIMessages fakeRandomTextAction:thread],
// Sequences
[DebugUIMessages allFakeSequencesAction:thread],
// Exemplary // Exemplary
[DebugUIMessages allFakeAction:thread], [DebugUIMessages allFakeAction:thread],
]) { ]) {
@ -1788,11 +1790,12 @@ NS_ASSUME_NONNULL_BEGIN
return [DebugUIMessagesSingleAction return [DebugUIMessagesSingleAction
actionWithLabel:[NSString stringWithFormat:@"Fake Incoming Text Message (%@)", text] actionWithLabel:[NSString stringWithFormat:@"Fake Incoming Text Message (%@)", text]
unstaggeredActionBlock:^(NSUInteger index, YapDatabaseReadWriteTransaction *transaction) { unstaggeredActionBlock:^(NSUInteger index, YapDatabaseReadWriteTransaction *transaction) {
NSString *messageBody = [[@(index).stringValue stringByAppendingString:@" "] stringByAppendingString:text];
TSIncomingMessage *message = [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSIncomingMessage *message = [[TSIncomingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
authorId:@"+19174054215" authorId:@"+19174054215"
sourceDeviceId:0 sourceDeviceId:0
messageBody:text]; messageBody:messageBody];
[message markAsReadWithTransaction:transaction sendReadReceipt:NO updateExpiration:NO]; [message markAsReadWithTransaction:transaction sendReadReceipt:NO updateExpiration:NO];
}]; }];
} }
@ -1806,9 +1809,10 @@ NS_ASSUME_NONNULL_BEGIN
return [DebugUIMessagesSingleAction return [DebugUIMessagesSingleAction
actionWithLabel:[NSString stringWithFormat:@"Fake Incoming Text Message (%@)", text] actionWithLabel:[NSString stringWithFormat:@"Fake Incoming Text Message (%@)", text]
unstaggeredActionBlock:^(NSUInteger index, YapDatabaseReadWriteTransaction *transaction) { unstaggeredActionBlock:^(NSUInteger index, YapDatabaseReadWriteTransaction *transaction) {
NSString *messageBody = [[@(index).stringValue stringByAppendingString:@" "] stringByAppendingString:text];
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
messageBody:text]; messageBody:messageBody];
[message saveWithTransaction:transaction]; [message saveWithTransaction:transaction];
[message updateWithMessageState:messageState transaction:transaction]; [message updateWithMessageState:messageState transaction:transaction];
}]; }];
@ -1824,6 +1828,19 @@ NS_ASSUME_NONNULL_BEGIN
messageState:(TSOutgoingMessageState)messageState messageState:(TSOutgoingMessageState)messageState
isDelivered:(BOOL)isDelivered isDelivered:(BOOL)isDelivered
isRead:(BOOL)isRead isRead:(BOOL)isRead
{
return [self fakeShortOutgoingTextMessageAction:(TSThread *)thread
text:[self randomText]
messageState:messageState
isDelivered:isDelivered
isRead:isRead];
}
+ (DebugUIMessagesAction *)fakeShortOutgoingTextMessageAction:(TSThread *)thread
text:(NSString *)text
messageState:(TSOutgoingMessageState)messageState
isDelivered:(BOOL)isDelivered
isRead:(BOOL)isRead
{ {
OWSAssert(thread); OWSAssert(thread);
@ -1847,8 +1864,7 @@ NS_ASSUME_NONNULL_BEGIN
return [DebugUIMessagesSingleAction return [DebugUIMessagesSingleAction
actionWithLabel:label actionWithLabel:label
unstaggeredActionBlock:^(NSUInteger index, YapDatabaseReadWriteTransaction *transaction) { unstaggeredActionBlock:^(NSUInteger index, YapDatabaseReadWriteTransaction *transaction) {
NSString *messageBody = NSString *messageBody = [[@(index).stringValue stringByAppendingString:@" "] stringByAppendingString:text];
[[@(index).stringValue stringByAppendingString:@" "] stringByAppendingString:[self randomText]];
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
inThread:thread inThread:thread
messageBody:messageBody]; messageBody:messageBody];
@ -1951,6 +1967,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<DebugUIMessagesAction *> *actions = [NSMutableArray new]; NSMutableArray<DebugUIMessagesAction *> *actions = [NSMutableArray new];
[actions addObjectsFromArray:[self allFakeMediaActions:thread includeLabels:includeLabels]]; [actions addObjectsFromArray:[self allFakeMediaActions:thread includeLabels:includeLabels]];
[actions addObjectsFromArray:[self allFakeTextActions:thread includeLabels:includeLabels]]; [actions addObjectsFromArray:[self allFakeTextActions:thread includeLabels:includeLabels]];
[actions addObjectsFromArray:[self allFakeSequenceActions:thread includeLabels:includeLabels]];
return actions; return actions;
} }
@ -1989,6 +2006,139 @@ NS_ASSUME_NONNULL_BEGIN
[fromViewController presentViewController:alert animated:YES completion:nil]; [fromViewController presentViewController:alert animated:YES completion:nil];
} }
#pragma mark - Sequences
+ (NSArray<DebugUIMessagesAction *> *)allFakeSequenceActions:(TSThread *)thread includeLabels:(BOOL)includeLabels
{
OWSAssert(thread);
NSMutableArray<DebugUIMessagesAction *> *actions = [NSMutableArray new];
if (includeLabels) {
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:@"⚠️ Short Message Sequences ⚠️"]];
}
[actions addObject:[self fakeIncomingTextMessageAction:thread text:@"Incoming"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:@"Outgoing"]];
[actions addObject:[self fakeIncomingTextMessageAction:thread text:@"Incoming 1"]];
[actions addObject:[self fakeIncomingTextMessageAction:thread text:@"Incoming 2"]];
[actions addObject:[self fakeIncomingTextMessageAction:thread text:@"Incoming 3"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateUnsent
text:@"Outgoing Unsent 1"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateUnsent
text:@"Outgoing Unsent 2"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateAttemptingOut
text:@"Outgoing Sending 1"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateAttemptingOut
text:@"Outgoing Sending 2"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:@"Outgoing Sent 1"]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:@"Outgoing Sent 2"]];
[actions addObject:[self fakeShortOutgoingTextMessageAction:thread
text:@"Outgoing Delivered 1"
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:NO]];
[actions addObject:[self fakeShortOutgoingTextMessageAction:thread
text:@"Outgoing Delivered 2"
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:NO]];
[actions addObject:[self fakeShortOutgoingTextMessageAction:thread
text:@"Outgoing Read 1"
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:YES]];
[actions addObject:[self fakeShortOutgoingTextMessageAction:thread
text:@"Outgoing Read 2"
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:YES]];
[actions addObject:[self fakeIncomingTextMessageAction:thread text:@"Incoming"]];
if (includeLabels) {
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:@"⚠️ Long Message Sequences ⚠️"]];
}
NSString *longText = @"\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rutrum, nulla "
@"vitae pretium hendrerit, tellus turpis pharetra libero...";
[actions addObject:[self fakeIncomingTextMessageAction:thread text:[@"Incoming" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:[@"Outgoing" stringByAppendingString:longText]]];
[actions
addObject:[self fakeIncomingTextMessageAction:thread text:[@"Incoming 1" stringByAppendingString:longText]]];
[actions
addObject:[self fakeIncomingTextMessageAction:thread text:[@"Incoming 2" stringByAppendingString:longText]]];
[actions
addObject:[self fakeIncomingTextMessageAction:thread text:[@"Incoming 3" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateUnsent
text:[@"Outgoing Unsent 1" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateUnsent
text:[@"Outgoing Unsent 2" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateAttemptingOut
text:[@"Outgoing Sending 1" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateAttemptingOut
text:[@"Outgoing Sending 2" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:[@"Outgoing Sent 1" stringByAppendingString:longText]]];
[actions addObject:[self fakeOutgoingTextMessageAction:thread
messageState:TSOutgoingMessageStateSentToService
text:[@"Outgoing Sent 2" stringByAppendingString:longText]]];
[actions
addObject:[self fakeShortOutgoingTextMessageAction:thread
text:[@"Outgoing Delivered 1" stringByAppendingString:longText]
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:NO]];
[actions
addObject:[self fakeShortOutgoingTextMessageAction:thread
text:[@"Outgoing Delivered 2" stringByAppendingString:longText]
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:NO]];
[actions addObject:[self fakeShortOutgoingTextMessageAction:thread
text:[@"Outgoing Read 1" stringByAppendingString:longText]
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:YES]];
[actions addObject:[self fakeShortOutgoingTextMessageAction:thread
text:[@"Outgoing Read 2" stringByAppendingString:longText]
messageState:TSOutgoingMessageStateSentToService
isDelivered:YES
isRead:YES]];
[actions addObject:[self fakeIncomingTextMessageAction:thread text:[@"Incoming" stringByAppendingString:longText]]];
return actions;
}
+ (DebugUIMessagesAction *)allFakeSequencesAction:(TSThread *)thread
{
OWSAssert(thread);
return [DebugUIMessagesGroupAction allGroupActionWithLabel:@"All Fake Sequences"
subactions:[self allFakeSequenceActions:thread includeLabels:YES]];
}
#pragma mark - #pragma mark -
+ (void)sendOversizeTextMessage:(TSThread *)thread + (void)sendOversizeTextMessage:(TSThread *)thread

Loading…
Cancel
Save