import SwiftUI import WebKit struct SVGImageHtml: UIViewRepresentable { let svgName: String func makeUIView(context: Context) -> WKWebView { let webView = WKWebView() webView.isOpaque = false webView.backgroundColor = .clear webView.scrollView.isScrollEnabled = false webView.scrollView.contentInsetAdjustmentBehavior = .never // 1. Get the URL for the SVG file guard let path = Bundle.main.path(forResource: svgName, ofType: "svg") else { print("❌ Cannot find SVG file: \(svgName).svg in bundle") return webView } let fileURL = URL(fileURLWithPath: path) do { // 2. Read the SVG content directly let svgString = try String(contentsOf: fileURL, encoding: .utf8) // 3. Create HTML with inline SVG for better reliability let htmlString = """ \(svgString) """ // 4. Load the HTML with base URL as the main bundle's resource path if let resourcePath = Bundle.main.resourceURL { webView.loadHTMLString(htmlString, baseURL: resourcePath) } else { webView.loadHTMLString(htmlString, baseURL: nil) } } catch { print("❌ Error loading SVG file: \(error.localizedDescription)") } return webView } func updateUIView(_ uiView: WKWebView, context: Context) {} }