Cache naturalTextAlignment

This commit is contained in:
Nora Trapp 2019-07-19 12:43:58 -07:00
parent e4e8132af0
commit b1d6db7cd9
5 changed files with 11 additions and 3 deletions

View File

@ -738,7 +738,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *text = displayableText.displayText;
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.alignment = text.naturalTextAlignment;
paragraphStyle.alignment = displayableText.displayTextNaturalAlignment;
NSMutableAttributedString *attributedText =
[[NSMutableAttributedString alloc] initWithString:text

View File

@ -466,7 +466,7 @@ const CGFloat kRemotelySourcedContentRowSpacing = 3;
self.quotedTextLabel.numberOfLines = self.isForPreview ? 1 : 2;
self.quotedTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
self.quotedTextLabel.text = text;
self.quotedTextLabel.textAlignment = text.naturalTextAlignment;
self.quotedTextLabel.textAlignment = self.displayableQuotedText.displayTextNaturalAlignment;
self.quotedTextLabel.textColor = textColor;
self.quotedTextLabel.font = font;

View File

@ -131,7 +131,7 @@ public class LongTextViewController: OWSViewController {
messageTextView.textColor = Theme.primaryColor
if let displayableText = displayableText {
messageTextView.text = fullText
messageTextView.textAlignment = fullText.naturalTextAlignment
messageTextView.textAlignment = displayableText.fullTextNaturalAlignment
messageTextView.ensureShouldLinkifyText(displayableText.shouldAllowLinkification)
} else {
owsFailDebug("displayableText was unexpectedly nil")

View File

@ -7,7 +7,11 @@ import Foundation
@objc public class DisplayableText: NSObject {
@objc public let fullText: String
@objc public let fullTextNaturalAlignment: NSTextAlignment
@objc public let displayText: String
@objc public let displayTextNaturalAlignment: NSTextAlignment
@objc public let isTextTruncated: Bool
@objc public let jumbomojiCount: UInt
@ -24,7 +28,9 @@ import Foundation
@objc
public init(fullText: String, displayText: String, isTextTruncated: Bool) {
self.fullText = fullText
self.fullTextNaturalAlignment = fullText.naturalTextAlignment
self.displayText = displayText
self.displayTextNaturalAlignment = displayText.naturalTextAlignment
self.isTextTruncated = isTextTruncated
self.jumbomojiCount = DisplayableText.jumbomojiCount(in: fullText)
}

View File

@ -45,6 +45,8 @@ public extension NSString {
}
}
// MARK: - Attributed String Concatentation
public extension NSAttributedString {
@objc
func stringByAppendingString(_ string: String, attributes: [NSAttributedString.Key: Any] = [:]) -> NSAttributedString {