Streamline usage of quoted message view.

This commit is contained in:
Matthew Chen 2018-04-11 18:15:38 -04:00
parent f8b11c57cc
commit 195d357370
2 changed files with 37 additions and 26 deletions

View file

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

View file

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