Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/Web/CrossmintWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public struct CrossmintWebView: UIViewRepresentable {
}

public func makeUIView(context: Context) -> WKWebView {
if let existingWebView = webViewCommunicationProxy.webView {
webViewCommunicationProxy.onWebViewMessage = onWebViewMessage
webViewCommunicationProxy.onUnknownMessage = onUnknownMessage
return existingWebView
}

let configuration = WKWebViewConfiguration()
let userContentController = WKUserContentController()

Expand Down Expand Up @@ -74,5 +80,7 @@ public struct CrossmintWebView: UIViewRepresentable {
}

public func updateUIView(_ webView: WKWebView, context: Context) {
webViewCommunicationProxy.onWebViewMessage = onWebViewMessage
webViewCommunicationProxy.onUnknownMessage = onUnknownMessage
}
}
9 changes: 8 additions & 1 deletion Sources/Web/WebViewCommunicationProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
public class DefaultWebViewCommunicationProxy: NSObject, ObservableObject, WKScriptMessageHandler, WebViewCommunicationProxy {
public let name = "crossmintMessageHandler"

public weak var webView: WKWebView?
public var webView: WKWebView?

public var onWebViewMessage: (any WebViewMessage) -> Void = { _ in }
public var onUnknownMessage: (String, Data) -> Void = { _, _ in }

Expand All @@ -48,6 +49,12 @@
}
}

deinit {
webView?.navigationDelegate = nil

Check failure on line 53 in Sources/Web/WebViewCommunicationProxy.swift

View workflow job for this annotation

GitHub Actions / Build and Test

main actor-isolated property 'navigationDelegate' can not be mutated from a nonisolated context
webView?.configuration.userContentController.removeScriptMessageHandler(forName: name)

Check failure on line 54 in Sources/Web/WebViewCommunicationProxy.swift

View workflow job for this annotation

GitHub Actions / Build and Test

main actor-isolated property 'configuration' can not be referenced from a nonisolated context

Check failure on line 54 in Sources/Web/WebViewCommunicationProxy.swift

View workflow job for this annotation

GitHub Actions / Build and Test

main actor-isolated property 'userContentController' can not be referenced from a nonisolated context

Check failure on line 54 in Sources/Web/WebViewCommunicationProxy.swift

View workflow job for this annotation

GitHub Actions / Build and Test

call to main actor-isolated instance method 'removeScriptMessageHandler(forName:)' in a synchronous nonisolated context
webView = nil
}

public func loadURL(_ url: URL) async throws {
guard let webView = webView else {

Expand Down
Loading