| Code | What It Does | How It Does It |
| ▶ IMPORTS | ||
| import SwiftUI import WebKit | Framework imports | Imports 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` struct | Defines 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` struct | Defines the `EmlWebView` struct. Conforms to UIViewRepresentable. |