Post

Replies

Boosts

Views

Activity

Reply to How to gain access to the UIView of a UIViewRepresentable
My solution to this was to instantiate the underlying web view on instantiation of the struct - not as part of the makeUIView method, although it is still returned by that. I'm unsure how this may contravene any view lifecycle rules. Here's the code anyhow: struct WebView: UIViewRepresentable { let url: URL let webView = WKWebView() func makeUIView(context: Context) -> WKWebView { let request = URLRequest(url: url) webView.load(request) return webView } func reload() { webView.reload() } func updateUIView(_ webView: WKWebView, context: Context) { } }
Apr ’24