Browse Source

Fix `loadImage` image name

- can't use dot in image name for iOS 12 (e.g. to match SFSymbol name)

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
a098088480

+ 1 - 1
iOSClient/Main/NCFunctionCenter.swift

@@ -617,7 +617,7 @@ import SVGKit
         }
         let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: "")
         let titleLock = metadata.lock ? NSLocalizedString("_unlock_file_", comment: "") :  NSLocalizedString("_lock_file_", comment: "")
-        let iconLock = metadata.lock ? "lock.open" : "lock"
+        let iconLock = metadata.lock ? "lock_open" : "lock"
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { _ in
             self.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view)
         }

+ 1 - 1
iOSClient/Menu/NCMenuAction.swift

@@ -234,7 +234,7 @@ extension NCMenuAction {
         } else {
             titleKey = shouldLock ? "_lock_selected_files_" : "_unlock_selected_files_"
         }
-        let imageName = !shouldLock ? "lock.open" : "lock"
+        let imageName = !shouldLock ? "lock_open" : "lock"
         return NCMenuAction(
             title: NSLocalizedString(titleKey, comment: ""),
             icon: NCUtility.shared.loadImage(named: imageName),

+ 2 - 2
iOSClient/Settings/NCSettings.m

@@ -74,7 +74,7 @@
     // Lock active YES/NO
     row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
     row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.secondarySystemGroupedBackground;
-    [row.cellConfig setObject:[[UIImage imageNamed:@"lock.open"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
+    [row.cellConfig setObject:[[UIImage imageNamed:@"lock_open"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
     [row.cellConfig setObject:NCBrandColor.shared.label forKey:@"textLabel.textColor"];
     [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
@@ -239,7 +239,7 @@
         [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
     } else {
         rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
-        [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock.open"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
+        [rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"lock_open"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
     }
     
     if ([CCUtility getEnableTouchFaceID]) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0];

+ 9 - 7
iOSClient/Utility/NCUtility.swift

@@ -487,25 +487,27 @@ class NCUtility: NSObject {
         return ""
     }
 
-    func loadImage(named: String, color: UIColor = NCBrandColor.shared.gray, size: CGFloat = 50, symbolConfiguration: Any? = nil) -> UIImage {
+    func loadImage(named imageName: String, color: UIColor = NCBrandColor.shared.gray, size: CGFloat = 50, symbolConfiguration: Any? = nil) -> UIImage {
 
         var image: UIImage?
 
         if #available(iOS 13.0, *) {
+            // see https://stackoverflow.com/questions/71764255
+            let sfSymbolName = imageName.replacingOccurrences(of: "_", with: ".")
             if let symbolConfiguration = symbolConfiguration {
-                image = UIImage(systemName: named, withConfiguration: symbolConfiguration as? UIImage.Configuration)?.imageColor(color)
+                image = UIImage(systemName: sfSymbolName, withConfiguration: symbolConfiguration as? UIImage.Configuration)?.imageColor(color)
             } else {
-                image = UIImage(systemName: named)?.imageColor(color)
+                image = UIImage(systemName: sfSymbolName)?.imageColor(color)
             }
             if image == nil {
-                image = UIImage(named: named)?.image(color: color, size: size)
+                image = UIImage(named: imageName)?.image(color: color, size: size)
             }
         } else {
-            image = UIImage(named: named)?.image(color: color, size: size)
+            image = UIImage(named: imageName)?.image(color: color, size: size)
         }
 
-        if image != nil {
-            return image!
+        if let image = image {
+            return image
         }
 
         return  UIImage(named: "file")!.image(color: color, size: size)