Streamline usage of quoted message view.

pull/1/head
Matthew Chen 7 years ago
parent f8b11c57cc
commit 195d357370

@ -26,6 +26,9 @@ 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) UILabel *quotedAuthorLabel;
@property (nonatomic, readonly) UILabel *quotedTextLabel;
@end @end
#pragma mark - #pragma mark -
@ -53,10 +56,12 @@ NS_ASSUME_NONNULL_BEGIN
displayableQuotedText = [DisplayableText displayableText:quotedMessage.body]; displayableQuotedText = [DisplayableText displayableText:quotedMessage.body];
} }
return [[OWSQuotedMessageView alloc] initWithQuotedMessage:quotedMessage OWSQuotedMessageView *instance = [[OWSQuotedMessageView alloc] initWithQuotedMessage:quotedMessage
displayableQuotedText:displayableQuotedText displayableQuotedText:displayableQuotedText
isForPreview:YES isForPreview:YES
isOutgoing:YES]; isOutgoing:YES];
[instance createContents];
return instance;
} }
- (instancetype)initWithQuotedMessage:(OWSQuotedReplyModel *)quotedMessage - (instancetype)initWithQuotedMessage:(OWSQuotedReplyModel *)quotedMessage
@ -77,7 +82,8 @@ NS_ASSUME_NONNULL_BEGIN
_isForPreview = isForPreview; _isForPreview = isForPreview;
_isOutgoing = isOutgoing; _isOutgoing = isOutgoing;
[self createContents]; _quotedAuthorLabel = [UILabel new];
_quotedTextLabel = [UILabel new];
return self; return self;
} }
@ -106,6 +112,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)createContents - (void)createContents
{ {
OWSAssert(!self.boundsStrokeView);
self.backgroundColor = [UIColor whiteColor]; self.backgroundColor = [UIColor whiteColor];
self.userInteractionEnabled = NO; self.userInteractionEnabled = NO;
self.layoutMargins = UIEdgeInsetsZero; self.layoutMargins = UIEdgeInsetsZero;
@ -155,7 +163,7 @@ NS_ASSUME_NONNULL_BEGIN
[quotedAttachmentView setCompressionResistanceHigh]; [quotedAttachmentView setCompressionResistanceHigh];
} }
UILabel *quotedAuthorLabel = [self createQuotedAuthorLabel]; UILabel *quotedAuthorLabel = [self configureQuotedAuthorLabel];
{ {
[self addSubview:quotedAuthorLabel]; [self addSubview:quotedAuthorLabel];
[quotedAuthorLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.quotedAuthorTopInset]; [quotedAuthorLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.quotedAuthorTopInset];
@ -171,6 +179,7 @@ NS_ASSUME_NONNULL_BEGIN
[quotedAuthorLabel setCompressionResistanceLow]; [quotedAuthorLabel setCompressionResistanceLow];
} }
UILabel *quotedTextLabel;
{ {
// Stripe and text container. // Stripe and text container.
UIView *stripeAndTextContainer = [UIView containerView]; UIView *stripeAndTextContainer = [UIView containerView];
@ -204,7 +213,7 @@ NS_ASSUME_NONNULL_BEGIN
[quoteStripView setCompressionResistanceHigh]; [quoteStripView setCompressionResistanceHigh];
// Text. // Text.
UILabel *quotedTextLabel = [self createQuotedTextLabel]; quotedTextLabel = [self configureQuotedTextLabel];
[stripeAndTextContainer addSubview:quotedTextLabel]; [stripeAndTextContainer addSubview:quotedTextLabel];
[quotedTextLabel autoPinTopToSuperviewMarginWithInset:self.quotedReplyStripeVExtension]; [quotedTextLabel autoPinTopToSuperviewMarginWithInset:self.quotedReplyStripeVExtension];
[quotedTextLabel autoPinBottomToSuperviewMarginWithInset:self.quotedReplyStripeVExtension]; [quotedTextLabel autoPinBottomToSuperviewMarginWithInset:self.quotedReplyStripeVExtension];
@ -243,8 +252,10 @@ NS_ASSUME_NONNULL_BEGIN
return imageView; return imageView;
} }
- (UILabel *)createQuotedTextLabel - (UILabel *)configureQuotedTextLabel
{ {
OWSAssert(self.quotedTextLabel);
UIColor *textColor = self.quotedTextColor; UIColor *textColor = self.quotedTextColor;
UIFont *font = self.quotedTextFont; UIFont *font = self.quotedTextFont;
NSString *text = @""; NSString *text = @"";
@ -271,14 +282,13 @@ NS_ASSUME_NONNULL_BEGIN
font = self.fileTypeFont; font = self.fileTypeFont;
} }
UILabel *quotedTextLabel = [UILabel new]; self.quotedTextLabel.numberOfLines = self.isForPreview ? 1 : 3;
quotedTextLabel.numberOfLines = self.isForPreview ? 1 : 3; self.quotedTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
quotedTextLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.quotedTextLabel.text = text;
quotedTextLabel.text = text; self.quotedTextLabel.textColor = textColor;
quotedTextLabel.textColor = textColor; self.quotedTextLabel.font = font;
quotedTextLabel.font = font;
return quotedTextLabel; return self.quotedTextLabel;
} }
- (nullable NSString *)fileTypeForSnippet - (nullable NSString *)fileTypeForSnippet
@ -305,8 +315,10 @@ NS_ASSUME_NONNULL_BEGIN
return nil; return nil;
} }
- (UILabel *)createQuotedAuthorLabel - (UILabel *)configureQuotedAuthorLabel
{ {
OWSAssert(self.quotedAuthorLabel);
NSString *_Nullable localNumber = [TSAccountManager localNumber]; NSString *_Nullable localNumber = [TSAccountManager localNumber];
NSString *quotedAuthorText; NSString *quotedAuthorText;
if ([localNumber isEqualToString:self.quotedMessage.authorId]) { if ([localNumber isEqualToString:self.quotedMessage.authorId]) {
@ -328,13 +340,13 @@ NS_ASSUME_NONNULL_BEGIN
quotedAuthor]; quotedAuthor];
} }
UILabel *quotedAuthorLabel = [UILabel new]; self.quotedAuthorLabel.text = quotedAuthorText;
quotedAuthorLabel.text = quotedAuthorText; self.quotedAuthorLabel.font = self.quotedAuthorFont;
quotedAuthorLabel.font = self.quotedAuthorFont; self.quotedAuthorLabel.textColor = [self quotedAuthorColor];
quotedAuthorLabel.textColor = [self quotedAuthorColor]; self.quotedAuthorLabel.lineBreakMode = NSLineBreakByTruncatingTail;
quotedAuthorLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.quotedAuthorLabel.numberOfLines = 1;
quotedAuthorLabel.numberOfLines = 1;
return quotedAuthorLabel; return self.quotedAuthorLabel;
} }
#pragma mark - Measurement #pragma mark - Measurement
@ -362,7 +374,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
CGFloat maxQuotedAuthorWidth = maxWidth - result.width; CGFloat maxQuotedAuthorWidth = maxWidth - result.width;
UILabel *quotedAuthorLabel = [self createQuotedAuthorLabel]; UILabel *quotedAuthorLabel = [self configureQuotedAuthorLabel];
CGSize quotedAuthorSize CGSize quotedAuthorSize
= CGSizeCeil([quotedAuthorLabel sizeThatFits:CGSizeMake(maxQuotedAuthorWidth, CGFLOAT_MAX)]); = CGSizeCeil([quotedAuthorLabel sizeThatFits:CGSizeMake(maxQuotedAuthorWidth, CGFLOAT_MAX)]);
@ -380,7 +392,7 @@ NS_ASSUME_NONNULL_BEGIN
CGFloat maxQuotedTextWidth CGFloat maxQuotedTextWidth
= (maxWidth - (result.width + self.quotedReplyStripeThickness + self.quotedReplyStripeHSpacing)); = (maxWidth - (result.width + self.quotedReplyStripeThickness + self.quotedReplyStripeHSpacing));
UILabel *quotedTextLabel = [self createQuotedTextLabel]; UILabel *quotedTextLabel = [self configureQuotedTextLabel];
CGSize textSize = CGSizeCeil([quotedTextLabel sizeThatFits:CGSizeMake(maxQuotedTextWidth, CGFLOAT_MAX)]); CGSize textSize = CGSizeCeil([quotedTextLabel sizeThatFits:CGSizeMake(maxQuotedTextWidth, CGFLOAT_MAX)]);
textSize.width = MIN(textSize.width, maxQuotedTextWidth); textSize.width = MIN(textSize.width, maxQuotedTextWidth);

@ -36,7 +36,6 @@ class QuotedReplyPreview: UIView {
func updateContents() { func updateContents() {
subviews.forEach { $0.removeFromSuperview() } subviews.forEach { $0.removeFromSuperview() }
self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
quotedMessageView.backgroundColor = .clear quotedMessageView.backgroundColor = .clear

Loading…
Cancel
Save