Merge branch 'charlesmchen/quoteReplyTweaks'

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

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

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

@ -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,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)createContents
{
// Ensure only called once.
OWSAssert(!self.boundsStrokeView);
self.backgroundColor = [UIColor whiteColor];
self.userInteractionEnabled = NO;
self.layoutMargins = UIEdgeInsetsZero;
@ -155,7 +164,7 @@ NS_ASSUME_NONNULL_BEGIN
[quotedAttachmentView setCompressionResistanceHigh];
}
UILabel *quotedAuthorLabel = [self createQuotedAuthorLabel];
UILabel *quotedAuthorLabel = [self configureQuotedAuthorLabel];
{
[self addSubview:quotedAuthorLabel];
[quotedAuthorLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:self.quotedAuthorTopInset];
@ -204,7 +213,7 @@ NS_ASSUME_NONNULL_BEGIN
[quoteStripView setCompressionResistanceHigh];
// Text.
UILabel *quotedTextLabel = [self createQuotedTextLabel];
UILabel *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);

@ -14,7 +14,7 @@ class QuotedReplyPreview: UIView {
public weak var delegate: QuotedReplyPreviewDelegate?
private let quotedReply: OWSQuotedReplyModel
private var quotedMessageView: OWSQuotedMessageView
private var quotedMessageView: OWSQuotedMessageView?
private var heightConstraint: NSLayoutConstraint!
required init?(coder aDecoder: NSCoder) {
@ -23,7 +23,6 @@ class QuotedReplyPreview: UIView {
init(quotedReply: OWSQuotedReplyModel) {
self.quotedReply = quotedReply
self.quotedMessageView = OWSQuotedMessageView(forPreview: quotedReply)
super.init(frame: .zero)
@ -36,7 +35,12 @@ class QuotedReplyPreview: UIView {
func updateContents() {
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
@ -71,7 +75,11 @@ class QuotedReplyPreview: UIView {
// MARK: Sizing
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
}

Loading…
Cancel
Save