← Back to index

EmlViewerView

Spots
CodeWhat It DoesHow It Does It
▶ IMPORTS
import SwiftUI import WebKitFramework importsImports SwiftUI, WebKit.
struct EmlViewerView: View { let emlPath: String @Environment(\.dismiss) var dismiss var body: some View { NavigationStack { Group { if let html = EmlParser.renderSelfContainedHTML(from: emlPath) { EmlWebView(html: html) } else { ContentUnavailableView( "Unable to Display Email", systemImage: "envelope.badge.shield.half.filled", description: Text("The email content could not be read.") ) } } .navigationTitle("Confirmation Email") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } .font(.system(size: 16)) } } } } }`EmlViewerView` structDefines the `EmlViewerView` struct. Conforms to View.
▶ WKWEBVIEW WRAPPER
struct EmlWebView: UIViewRepresentable { let html: String func makeUIView(context: Context) -> WKWebView { let config = WKWebViewConfiguration() // data: URIs are loaded from Swift so we don't need to allow file access config.dataDetectorTypes = [.phoneNumber, .link, .address] let webView = WKWebView(frame: .zero, configuration: config) webView.backgroundColor = UIColor.systemBackground webView.isOpaque = false webView.scrollView.bouncesZoom = true return webView } func updateUIView(_ webView: WKWebView, context: Context) { // baseURL nil is fine — all images are inlined as data: URIs webView.loadHTMLString(html, baseURL: nil) } }`EmlWebView` structDefines the `EmlWebView` struct. Conforms to UIViewRepresentable.