marinofaggiana 5 years ago
parent
commit
8a40c0f949

+ 43 - 22
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -7,59 +7,80 @@
 //
 
 import Foundation
+import SwiftRichString
 
 @objc class NCViewRichWorkspace: UIView {
     
-    @IBOutlet weak var webView: WKWebView!
+    @IBOutlet weak var textLabel: UILabel!
     var richWorkspace: String = ""
 
     required init?(coder: NSCoder) {
         super.init(coder: coder)
         
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
-        self.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
+        self.backgroundColor = NCBrandColor.sharedInstance.backgroundView
     }
     
     @objc func changeTheming() {
-        self.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
+        self.backgroundColor = NCBrandColor.sharedInstance.backgroundView
         setRichWorkspaceText(richWorkspace)
     }
     
     @objc func setRichWorkspaceText(_ richWorkspace: String) {
         
-        var color =  "#000000"
-        if CCUtility.getDarkMode() {
-            color =  "#FFFFFF"
+        let h1 = Style {
+            $0.font = UIFont.systemFont(ofSize: 20, weight: .bold)
+            $0.color = NCBrandColor.sharedInstance.textView
         }
-    
+        let h2 = Style {
+            $0.font = UIFont.systemFont(ofSize: 18, weight: .bold)
+            $0.color = NCBrandColor.sharedInstance.textView
+        }
+        let h3 = Style {
+            $0.font = UIFont.systemFont(ofSize: 16, weight: .bold)
+            $0.color = NCBrandColor.sharedInstance.textView
+        }
+        let h4 = Style {
+            $0.font = UIFont.systemFont(ofSize: 14, weight: .bold)
+            $0.color = NCBrandColor.sharedInstance.textView
+        }
+        let h5 = Style {
+            $0.font = UIFont.systemFont(ofSize: 12, weight: .bold)
+            $0.color = NCBrandColor.sharedInstance.textView
+        }
+        let h6 = Style {
+            $0.font = UIFont.systemFont(ofSize: 10, weight: .bold)
+            $0.color = NCBrandColor.sharedInstance.textView
+        }
+        let normal = Style {
+            $0.font = UIFont.systemFont(ofSize: 10)
+            $0.color = NCBrandColor.sharedInstance.textView
+        }
+       
         self.richWorkspace = richWorkspace
-        var richWorkspaceHtml = ""
-        let richWorkspaceArray = richWorkspace.components(separatedBy: "\n")
+        var richWorkspaceStyling = ""
         
+        let richWorkspaceArray = richWorkspace.components(separatedBy: "\n")
         for string in richWorkspaceArray {
             if string.hasPrefix("# ") {
-                richWorkspaceHtml = richWorkspaceHtml + "<h1><span style=\"color: \(color);\">" + string.replacingOccurrences(of: "# ", with: "") + "</span></h1>"
+                richWorkspaceStyling = richWorkspaceStyling + "<h1>" + string.replacingOccurrences(of: "# ", with: "") + "</h1>\r\n"
             } else if string.hasPrefix("## ") {
-                richWorkspaceHtml = richWorkspaceHtml + "<h2><span style=\"color: \(color);\">" + string.replacingOccurrences(of: "## ", with: "") + "</span></h2>"
+                richWorkspaceStyling = richWorkspaceStyling + "<h2>" + string.replacingOccurrences(of: "## ", with: "") + "</h2>\r\n"
             } else if string.hasPrefix("### ") {
-                richWorkspaceHtml = richWorkspaceHtml + "<h3><span style=\"color: \(color);\">" + string.replacingOccurrences(of: "### ", with: "") + "</span></h3>"
+                richWorkspaceStyling = richWorkspaceStyling + "<h3>" + string.replacingOccurrences(of: "### ", with: "") + "</h3>\r\n"
             } else if string.hasPrefix("#### ") {
-                richWorkspaceHtml = richWorkspaceHtml + "<h4><span style=\"color: \(color);\">" + string.replacingOccurrences(of: "#### ", with: "") + "</span></h4>"
+                richWorkspaceStyling = richWorkspaceStyling + "<h4>" + string.replacingOccurrences(of: "#### ", with: "") + "</h4>\r\n"
             } else if string.hasPrefix("##### ") {
-                richWorkspaceHtml = richWorkspaceHtml + "<h5><span style=\"color: \(color);\">" + string.replacingOccurrences(of: "##### ", with: "") + "</span></h5>"
+                richWorkspaceStyling = richWorkspaceStyling + "<h5>" + string.replacingOccurrences(of: "##### ", with: "") + "</h5>\r\n"
             } else if string.hasPrefix("###### ") {
-                richWorkspaceHtml = richWorkspaceHtml + "<h6><span style=\"color: \(color);\">" + string.replacingOccurrences(of: "###### ", with: "") + "</span></h6>"
+                richWorkspaceStyling = richWorkspaceStyling + "<h6>" + string.replacingOccurrences(of: "###### ", with: "") + "</h6>\r\n"
             } else {
-                richWorkspaceHtml = richWorkspaceHtml + "<span style=\"color: \(color);\">" + string + "</span>"
+                richWorkspaceStyling = richWorkspaceStyling + string + "\r\n"
             }
-            richWorkspaceHtml = richWorkspaceHtml + "<br>"
         }
         
-        richWorkspaceHtml = "<!DOCTYPE html><html><body>" + richWorkspaceHtml + "</body></html>"
-        
-        webView.loadHTMLString(richWorkspaceHtml, baseURL: Bundle.main.bundleURL)
-        webView.isUserInteractionEnabled = false
-        webView.isOpaque = false
+        textLabel.attributedText = richWorkspaceStyling.set(style: StyleGroup(base: normal, ["h1": h1, "h2": h2, "h3": h3, "h4": h4, "h5": h5, "h6": h6]))
+        textLabel.isUserInteractionEnabled = false
     }
 }
 

+ 10 - 12
iOSClient/RichWorkspace/NCRichWorkspace.xib

@@ -14,25 +14,23 @@
             <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <wkWebView contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XXz-cr-h4j">
+                <label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dZp-91-Nnq">
                     <rect key="frame" x="15" y="5" width="295" height="470"/>
-                    <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
-                    <wkWebViewConfiguration key="configuration">
-                        <audiovisualMediaTypes key="mediaTypesRequiringUserActionForPlayback" none="YES"/>
-                        <wkPreferences key="preferences"/>
-                    </wkWebViewConfiguration>
-                </wkWebView>
+                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                    <nil key="textColor"/>
+                    <nil key="highlightedColor"/>
+                </label>
             </subviews>
             <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
             <constraints>
-                <constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="XXz-cr-h4j" secondAttribute="bottom" constant="5" id="0tw-2O-jd5"/>
-                <constraint firstItem="XXz-cr-h4j" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="15" id="DCK-aY-jxF"/>
-                <constraint firstItem="XXz-cr-h4j" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="5" id="FBk-U6-oyG"/>
-                <constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="XXz-cr-h4j" secondAttribute="trailing" constant="10" id="sSB-Ux-4JO"/>
+                <constraint firstItem="vUN-kp-3ea" firstAttribute="bottom" secondItem="dZp-91-Nnq" secondAttribute="bottom" constant="5" id="Fmt-BL-zWO"/>
+                <constraint firstItem="dZp-91-Nnq" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="5" id="Tpz-Mh-Qkc"/>
+                <constraint firstItem="dZp-91-Nnq" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="15" id="aQH-58-OaN"/>
+                <constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="dZp-91-Nnq" secondAttribute="trailing" constant="10" id="rz6-hD-xTs"/>
             </constraints>
             <viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
             <connections>
-                <outlet property="webView" destination="XXz-cr-h4j" id="Sx0-bC-A3Q"/>
+                <outlet property="textLabel" destination="dZp-91-Nnq" id="fly-de-eVa"/>
             </connections>
             <point key="canvasLocation" x="136.875" y="88.75"/>
         </view>