Browse Source

preview svgs in chat file messages

cyberta 3 năm trước cách đây
mục cha
commit
cae7e53b81

+ 17 - 3
deltachat-ios/Chat/Views/FileView.swift

@@ -134,12 +134,26 @@ public class FileView: UIView {
             fileImageView.image = pdfThumbnail
             fileImageView.image = pdfThumbnail
             horizontalLayout = allowLayoutChange ? false : horizontalLayout
             horizontalLayout = allowLayoutChange ? false : horizontalLayout
             ThumbnailCache.shared.storeImage(image: pdfThumbnail, key: url.absoluteString)
             ThumbnailCache.shared.storeImage(image: pdfThumbnail, key: url.absoluteString)
+        } else if url.pathExtension == "svg" {
+            fileImageView.sd_setImage(with: url) { img, error, cacheType, imageURL in
+                if error == nil, let img = img, let imageURL = imageURL {
+                    self.horizontalLayout = self.allowLayoutChange ? false : self.horizontalLayout
+                    ThumbnailCache.shared.storeImage(image: img, key: imageURL.absoluteString)
+                } else {
+                    self.loadDocumentThumbnail(url: url, placeholder: placeholder)
+                }
+                return
+            }
         } else {
         } else {
-            let controller = UIDocumentInteractionController(url: url)
-            fileImageView.image = controller.icons.first ?? placeholder
-            horizontalLayout = allowLayoutChange ? true : horizontalLayout
+            loadDocumentThumbnail(url: url, placeholder: placeholder)
         }
         }
     }
     }
+    
+    private func loadDocumentThumbnail(url: URL, placeholder: UIImage?) {
+        let controller = UIDocumentInteractionController(url: url)
+        fileImageView.image = controller.icons.first ?? placeholder
+        horizontalLayout = allowLayoutChange ? true : horizontalLayout
+    }
 
 
 
 
 }
 }