From c91bc71ebdd36ac248f0c18c37443f49bc0b2be9 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 9 Aug 2018 10:47:20 -0400 Subject: [PATCH 1/3] Cache sender name size. --- Signal.xcodeproj/project.pbxproj | 6 ++ .../ConversationView/Cells/OWSLabel.h | 11 +++ .../ConversationView/Cells/OWSLabel.m | 76 +++++++++++++++++++ .../Cells/OWSMessageBubbleView.m | 3 +- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.h create mode 100644 Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index ed22b3fcb7..50bb367529 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -207,6 +207,7 @@ 34AC0A1E211B39EA00997B47 /* ThreadViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC0A0B211B39EA00997B47 /* ThreadViewHelper.m */; }; 34AC0A1F211B39EA00997B47 /* AvatarImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34AC0A0C211B39EA00997B47 /* AvatarImageView.swift */; }; 34AC0A20211B39EA00997B47 /* ThreadViewHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 34AC0A0D211B39EA00997B47 /* ThreadViewHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 34AC0A23211C829F00997B47 /* OWSLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 34AC0A21211C829E00997B47 /* OWSLabel.m */; }; 34B0796D1FCF46B100E248C2 /* MainAppContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 34B0796B1FCF46B000E248C2 /* MainAppContext.m */; }; 34B3F8751E8DF1700035BE1A /* CallViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F83B1E8DF1700035BE1A /* CallViewController.swift */; }; 34B3F8771E8DF1700035BE1A /* ContactsPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B3F83E1E8DF1700035BE1A /* ContactsPicker.swift */; }; @@ -841,6 +842,8 @@ 34AC0A0B211B39EA00997B47 /* ThreadViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadViewHelper.m; sourceTree = ""; }; 34AC0A0C211B39EA00997B47 /* AvatarImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AvatarImageView.swift; sourceTree = ""; }; 34AC0A0D211B39EA00997B47 /* ThreadViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadViewHelper.h; sourceTree = ""; }; + 34AC0A21211C829E00997B47 /* OWSLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSLabel.m; sourceTree = ""; }; + 34AC0A22211C829E00997B47 /* OWSLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSLabel.h; sourceTree = ""; }; 34B0796B1FCF46B000E248C2 /* MainAppContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MainAppContext.m; sourceTree = ""; }; 34B0796C1FCF46B000E248C2 /* MainAppContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainAppContext.h; sourceTree = ""; }; 34B0796E1FD07B1E00E248C2 /* SignalShareExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SignalShareExtension.entitlements; sourceTree = ""; }; @@ -1819,6 +1822,8 @@ 34CA631A2097806E00E526A0 /* OWSContactShareView.m */, 34D1F0B51F87F8850066283D /* OWSGenericAttachmentView.h */, 34D1F0B61F87F8850066283D /* OWSGenericAttachmentView.m */, + 34AC0A22211C829E00997B47 /* OWSLabel.h */, + 34AC0A21211C829E00997B47 /* OWSLabel.m */, 3496744B2076768600080B5F /* OWSMessageBubbleView.h */, 3496744C2076768700080B5F /* OWSMessageBubbleView.m */, 34D1F0A11F867BFC0066283D /* OWSMessageCell.h */, @@ -3390,6 +3395,7 @@ 457F671B20746193000EABCD /* QuotedReplyPreview.swift in Sources */, 34DBF004206BD5A500025978 /* OWSBubbleView.m in Sources */, 34E88D262098C5AE00A608F4 /* ContactViewController.swift in Sources */, + 34AC0A23211C829F00997B47 /* OWSLabel.m in Sources */, 76EB054018170B33006006FC /* AppDelegate.m in Sources */, 34D1F0831F8678AA0066283D /* ConversationInputTextView.m in Sources */, 340FC8B6204DAC8D007AEB0F /* OWSQRCodeScanningViewController.m in Sources */, diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.h b/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.h new file mode 100644 index 0000000000..89992ef6fb --- /dev/null +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.h @@ -0,0 +1,11 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +NS_ASSUME_NONNULL_BEGIN + +@interface OWSLabel : UILabel + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m new file mode 100644 index 0000000000..f456999220 --- /dev/null +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m @@ -0,0 +1,76 @@ +// +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. +// + +#import "OWSLabel.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWSLabel () + +@property (nonatomic, nullable) NSValue *cachedSize; + +@end + +#pragma mark - + +@implementation OWSLabel + +- (void)setText:(nullable NSString *)text +{ + if ([NSObject isNullableObject:text equalTo:self.text]) { + return; + } + [super setText:text]; + self.cachedSize = nil; +} + +- (void)setAttributedText:(nullable NSAttributedString *)attributedText +{ + if ([NSObject isNullableObject:attributedText equalTo:self.attributedText]) { + return; + } + [super setAttributedText:attributedText]; + self.cachedSize = nil; +} + +- (void)setTextColor:(nullable UIColor *)textColor +{ + if ([NSObject isNullableObject:textColor equalTo:self.textColor]) { + return; + } + [super setTextColor:textColor]; + // No need to clear cached size here. +} + +- (void)setFont:(nullable UIFont *)font +{ + if ([NSObject isNullableObject:font equalTo:self.font]) { + return; + } + [super setFont:font]; + self.cachedSize = nil; +} + +- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode +{ + if (self.lineBreakMode == lineBreakMode) { + return; + } + [super setLineBreakMode:lineBreakMode]; + self.cachedSize = nil; +} + +- (CGSize)sizeThatFits:(CGSize)size +{ + if (self.cachedSize) { + return self.cachedSize.CGSizeValue; + } + CGSize result = [super sizeThatFits:size]; + self.cachedSize = [NSValue valueWithCGSize:result]; + return result; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index 7d52929175..32572d33ab 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -11,6 +11,7 @@ #import "OWSContactShareButtonsView.h" #import "OWSContactShareView.h" #import "OWSGenericAttachmentView.h" +#import "OWSLabel.h" #import "OWSMessageFooterView.h" #import "OWSMessageTextView.h" #import "OWSQuotedMessageView.h" @@ -85,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN self.stackView = [UIStackView new]; self.stackView.axis = UILayoutConstraintAxisVertical; - self.senderNameLabel = [UILabel new]; + self.senderNameLabel = [OWSLabel new]; self.senderNameContainer = [UIView new]; self.senderNameContainer.layoutMargins = UIEdgeInsetsMake(0, 0, self.senderNameBottomSpacing, 0); [self.senderNameContainer addSubview:self.senderNameLabel]; From 2fecb270e620e02cae483dc4f5db11618ba3c2bd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 9 Aug 2018 10:55:38 -0400 Subject: [PATCH 2/3] Cache footer timestamp size. --- .../ConversationView/Cells/OWSMessageFooterView.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m index 73effa78d1..3aae464db8 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m @@ -4,6 +4,7 @@ #import "OWSMessageFooterView.h" #import "DateUtil.h" +#import "OWSLabel.h" #import "OWSMessageTimerView.h" #import "Signal-Swift.h" #import @@ -48,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN [self addArrangedSubview:leftStackView]; [leftStackView setContentHuggingHigh]; - self.timestampLabel = [UILabel new]; + self.timestampLabel = [OWSLabel new]; [leftStackView addArrangedSubview:self.timestampLabel]; self.messageTimerView = [OWSMessageTimerView new]; From 4096d2e0d826019d2907d40688b07e3d35cd5868 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 9 Aug 2018 14:05:21 -0400 Subject: [PATCH 3/3] Respond to CR. --- .../ConversationView/Cells/OWSLabel.m | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m index f456999220..6708ed4004 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSLabel.m @@ -61,6 +61,42 @@ NS_ASSUME_NONNULL_BEGIN self.cachedSize = nil; } +- (void)setNumberOfLines:(NSInteger)numberOfLines +{ + if (self.numberOfLines == numberOfLines) { + return; + } + [super setNumberOfLines:numberOfLines]; + self.cachedSize = nil; +} + +- (void)setAdjustsFontSizeToFitWidth:(BOOL)adjustsFontSizeToFitWidth +{ + if (self.adjustsFontSizeToFitWidth == adjustsFontSizeToFitWidth) { + return; + } + [super setAdjustsFontSizeToFitWidth:adjustsFontSizeToFitWidth]; + self.cachedSize = nil; +} + +- (void)setMinimumScaleFactor:(CGFloat)minimumScaleFactor +{ + if (self.minimumScaleFactor == minimumScaleFactor) { + return; + } + [super setMinimumScaleFactor:minimumScaleFactor]; + self.cachedSize = nil; +} + +- (void)setMinimumFontSize:(CGFloat)minimumFontSize +{ + if (self.minimumFontSize == minimumFontSize) { + return; + } + [super setMinimumFontSize:minimumFontSize]; + self.cachedSize = nil; +} + - (CGSize)sizeThatFits:(CGSize)size { if (self.cachedSize) {