Merge branch 'charlesmchen/quoteReplyTweaks'

pull/1/head
Matthew Chen 7 years ago
commit d821942f02

@ -54,6 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)commontInit - (void)commontInit
{ {
// Ensure only called once.
OWSAssert(!self.bodyTextView); OWSAssert(!self.bodyTextView);
_viewConstraints = [NSMutableArray new]; _viewConstraints = [NSMutableArray new];

@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)commontInit - (void)commontInit
{ {
// Ensure only called once.
OWSAssert(!self.messageBubbleView); OWSAssert(!self.messageBubbleView);
_viewConstraints = [NSMutableArray new]; _viewConstraints = [NSMutableArray new];

@ -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,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)createContents - (void)createContents
{ {
// Ensure only called once.
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 +164,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];
@ -204,7 +213,7 @@ NS_ASSUME_NONNULL_BEGIN
[quoteStripView setCompressionResistanceHigh]; [quoteStripView setCompressionResistanceHigh];
// Text. // Text.
UILabel *quotedTextLabel = [self createQuotedTextLabel]; UILabel *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);

@ -14,7 +14,7 @@ class QuotedReplyPreview: UIView {
public weak var delegate: QuotedReplyPreviewDelegate? public weak var delegate: QuotedReplyPreviewDelegate?
private let quotedReply: OWSQuotedReplyModel private let quotedReply: OWSQuotedReplyModel
private var quotedMessageView: OWSQuotedMessageView private var quotedMessageView: OWSQuotedMessageView?
private var heightConstraint: NSLayoutConstraint! private var heightConstraint: NSLayoutConstraint!
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
@ -23,7 +23,6 @@ class QuotedReplyPreview: UIView {
init(quotedReply: OWSQuotedReplyModel) { init(quotedReply: OWSQuotedReplyModel) {
self.quotedReply = quotedReply self.quotedReply = quotedReply
self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
super.init(frame: .zero) super.init(frame: .zero)
@ -36,7 +35,12 @@ class QuotedReplyPreview: UIView {
func updateContents() { func updateContents() {
subviews.forEach { $0.removeFromSuperview() } subviews.forEach { $0.removeFromSuperview() }
self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
// We instantiate quotedMessageView late to ensure that it is updated
// every time contentSizeCategoryDidChange (i.e. when dynamic type
// sizes changes).
let quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
self.quotedMessageView = quotedMessageView
quotedMessageView.backgroundColor = .clear quotedMessageView.backgroundColor = .clear
@ -71,7 +75,11 @@ class QuotedReplyPreview: UIView {
// MARK: Sizing // MARK: Sizing
func updateHeight() { func updateHeight() {
let size = self.quotedMessageView.size(forMaxWidth: CGFloat.infinity) guard let quotedMessageView = quotedMessageView else {
owsFail("\(logTag) missing quotedMessageView")
return
}
let size = quotedMessageView.size(forMaxWidth: CGFloat.infinity)
self.heightConstraint.constant = size.height self.heightConstraint.constant = size.height
} }

Loading…
Cancel
Save