Explorar o código

Load SVG icons for Hovercard

Also, small optimisation in `convertSVGtoPNGWriteToUserData`

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch %!s(int64=3) %!d(string=hai) anos
pai
achega
fd8674ea5f

+ 3 - 2
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -27,6 +27,7 @@ import UIKit
 import FloatingPanel
 import NCCommunication
 import Queuer
+import SVGKit
 
 extension UIViewController {
     func handleProfileAction(_ action: NCHovercard.Action, for userId: String) {
@@ -64,8 +65,8 @@ extension UIViewController {
             
             let actions = card.actions.map { action -> NCMenuAction in
                 var image = UIImage()
-                if let url = URL(string: action.icon), let loadedImage = try? UIImage(data: Data(contentsOf: url)) {
-                    image = loadedImage
+                if let url = URL(string: action.icon), let svg = SVGKImage(contentsOf: url) {
+                    image = svg.uiImage
                 }
                 return NCMenuAction(
                     title: action.title,

+ 5 - 7
iOSClient/Utility/NCUtility.swift

@@ -111,17 +111,15 @@ class NCUtility: NSObject {
         
         var fileNamePNG = ""
         
-        guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
-            return closure(nil)
-        }
-        guard let iconURL = URL(string: svgUrlString) else {
+        guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
+              let iconURL = URL(string: svgUrlString) else {
             return closure(nil)
         }
         
-        if fileName == nil {
-            fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
+        if let fileName = fileName {
+            fileNamePNG = fileName
         } else {
-            fileNamePNG = fileName!
+            fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
         }
         
         let imageNamePath = CCUtility.getDirectoryUserData() + "/" + fileNamePNG