ソースを参照

set font sizes at the right place

cyberta 2 年 前
コミット
c4b84753dc

+ 1 - 1
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -452,7 +452,7 @@ public class BaseMessageCell: UITableViewCell {
             quoteView.isHidden = true
         }
 
-        messageLabel.attributedText = MessageUtils.getFormattedSearchResultMessage(messageText: msg.text,
+        messageLabel.attributedText = MessageUtils.getFormattedTextMessage(messageText: msg.text,
                                                                                    searchText: searchText,
                                                                                    highlight: highlight)
 

+ 0 - 22
deltachat-ios/Chat/Views/Cells/TextMessageCell.swift

@@ -13,28 +13,6 @@ class TextMessageCell: BaseMessageCell {
 
     override func update(dcContext: DcContext, msg: DcMsg, messageStyle: UIRectCorner, showAvatar: Bool, showName: Bool, searchText: String?, highlight: Bool) {
         messageLabel.text = msg.text
-        
-        var fontSize = UIFont.preferredFont(for: .body, weight: .regular).pointSize
-        // calculate jumbomoji size
-        if msg.text != nil {
-            let text = msg.text! // simon: not sure how we can get rid of this `!`
-            let charCount = text.count
-            // simon: as far as I understood, this iterates over the whole string to find out how many unicode clusters there are,
-            // so we might wanna cache it here instead of calculating it twice
-            if charCount <= 8 && text.containsOnlyEmoji {
-                if charCount <= 2 {
-                    fontSize *= 3.0
-                } else if charCount <= 4 {
-                    fontSize *= 2.5
-                } else if charCount <= 6 {
-                    fontSize *= 1.75
-                } else {
-                    fontSize *= 1.35
-                }
-            }
-        }
-        messageLabel.font = messageLabel.font.withSize(fontSize)
-        // messageLabel.traitCollection
 
         super.update(dcContext: dcContext,
                      msg: msg,

+ 18 - 2
deltachat-ios/Helper/MessageUtils.swift

@@ -122,10 +122,26 @@ public class MessageUtils {
         return "\(date) \(padlock) \(sendingState)"
     }
 
-    public static func getFormattedSearchResultMessage(messageText: String?, searchText: String?, highlight: Bool) -> NSAttributedString? {
+    public static func getFormattedTextMessage(messageText: String?, searchText: String?, highlight: Bool) -> NSAttributedString? {
         if let messageText = messageText {
+
+            var fontSize = UIFont.preferredFont(for: .body, weight: .regular).pointSize
+            // calculate jumbomoji size
+            let charCount = messageText.count
+            if charCount <= 8 && messageText.containsOnlyEmoji {
+                if charCount <= 2 {
+                    fontSize *= 3.0
+                } else if charCount <= 4 {
+                    fontSize *= 2.5
+                } else if charCount <= 6 {
+                    fontSize *= 1.75
+                } else {
+                    fontSize *= 1.35
+                }
+            }
+
             let fontAttributes: [NSAttributedString.Key: Any] = [
-                .font: UIFont.preferredFont(for: .body, weight: .regular),
+                .font: UIFont.systemFont(ofSize: fontSize),
                 .foregroundColor: DcColors.defaultTextColor
             ]
             let mutableAttributedString = NSMutableAttributedString(string: messageText, attributes: fontAttributes)