Browse Source

Merge pull request #1262 from deltachat/fix_chat_cell_layout

Fix chat cell layout
cyBerta 4 years ago
parent
commit
eb58c49ded
1 changed files with 10 additions and 5 deletions
  1. 10 5
      deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

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

@@ -110,6 +110,7 @@ class ImageTextCell: BaseMessageCell {
 
 
         self.imageHeightConstraint?.isActive = false
         self.imageHeightConstraint?.isActive = false
         self.imageWidthConstraint?.isActive = false
         self.imageWidthConstraint?.isActive = false
+        self.contentImageView.contentMode = .scaleAspectFit
 
 
         // check if sticker has the allowed minimal width
         // check if sticker has the allowed minimal width
         if width < minImageWidth {
         if width < minImageWidth {
@@ -144,7 +145,8 @@ class ImageTextCell: BaseMessageCell {
         let orientation = UIApplication.shared.statusBarOrientation
         let orientation = UIApplication.shared.statusBarOrientation
         self.imageHeightConstraint?.isActive = false
         self.imageHeightConstraint?.isActive = false
         self.imageWidthConstraint?.isActive = false
         self.imageWidthConstraint?.isActive = false
-        
+        var scaleType = ContentMode.scaleAspectFill
+
         // check if image has the allowed minimal width
         // check if image has the allowed minimal width
         if width < minImageWidth {
         if width < minImageWidth {
             height = (height / width) * minImageWidth
             height = (height / width) * minImageWidth
@@ -176,16 +178,19 @@ class ImageTextCell: BaseMessageCell {
                 if width < squareSize {
                 if width < squareSize {
                     // very small width images should be forced to not be scaled down further
                     // very small width images should be forced to not be scaled down further
                     self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(greaterThanOrEqualToConstant: width)
                     self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(greaterThanOrEqualToConstant: width)
+                    self.imageHeightConstraint = self.contentImageView.heightAnchor.constraint(equalToConstant: height)
+                    scaleType = ContentMode.scaleAspectFit
                 } else {
                 } else {
                     // large width images might scale down until the max allowed text width
                     // large width images might scale down until the max allowed text width
                     self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualToConstant: width)
                     self.imageWidthConstraint = self.contentImageView.widthAnchor.constraint(lessThanOrEqualToConstant: width)
+                    self.imageHeightConstraint = self.contentImageView.heightAnchor.constraint(
+                        lessThanOrEqualTo: self.contentImageView.widthAnchor,
+                        multiplier: height / width
+                    )
                 }
                 }
-                self.imageHeightConstraint = self.contentImageView.heightAnchor.constraint(
-                    lessThanOrEqualTo: self.contentImageView.widthAnchor,
-                    multiplier: height / width
-                )
             }
             }
         }
         }
+        self.contentImageView.contentMode = scaleType
         self.imageHeightConstraint?.isActive = true
         self.imageHeightConstraint?.isActive = true
         self.imageWidthConstraint?.isActive = true
         self.imageWidthConstraint?.isActive = true
     }
     }