فهرست منبع

Merge pull request #1186 from deltachat/chat_bubbles2

adapt chat bubble size
cyBerta 4 سال پیش
والد
کامیت
749f1ea39c
1فایلهای تغییر یافته به همراه10 افزوده شده و 9 حذف شده
  1. 10 9
      deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

+ 10 - 9
deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

@@ -4,7 +4,7 @@ import DcCore
 import SDWebImage
 
 class ImageTextCell: BaseMessageCell {
-    let minImageWidth: CGFloat = 175
+    let minImageWidth: CGFloat = 125
     var imageHeightConstraint: NSLayoutConstraint?
     var imageWidthConstraint: NSLayoutConstraint?
 
@@ -117,14 +117,15 @@ class ImageTextCell: BaseMessageCell {
             width = minImageWidth
         }
         
+        // in some cases we show images in square sizes
+        // restrict width to half of the screen in device landscape and to 5 / 6 in portrait
+        // it results in a good balance between message text width and image size
+        let factor: CGFloat = orientation.isLandscape ? 1 / 2 : 5 / 6
+        var squareSize  = UIScreen.main.bounds.width * factor
+        
         if  height > width {
             // show square image for portrait images
-            // restrict width to half of the screen in device landscape and to 5 / 6 in portrait
-            // it results in a good balance between message text width and image size
-            let factor: CGFloat = orientation.isLandscape ? 1 / 2 : 5 / 6
-            var squareSize  = UIScreen.main.bounds.width * factor
-
-            //reduce the image square size if there's no message text so that it fits best in the viewable area
+            // reduce the image square size if there's no message text so that it fits best in the viewable area
             if squareSize > UIScreen.main.bounds.height * 5 / 8 && (messageLabel.text?.isEmpty ?? true) {
                 squareSize = UIScreen.main.bounds.height * 5 / 8
             }
@@ -138,9 +139,9 @@ class ImageTextCell: BaseMessageCell {
                 self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualTo: self.contentImageView.heightAnchor,
                                                                                          multiplier: width/height)
             } else {
-                if width == minImageWidth {
+                if width < squareSize {
                     // very small width images should be forced to not be scaled down further
-                    self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(equalToConstant: width)
+                    self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(greaterThanOrEqualToConstant: width)
                 } else {
                     // large width images might scale down until the max allowed text width
                     self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualToConstant: width)