-
As the title suggest, I'm looking for suggestions as to how to model interactions with a UIViewRepresentable and its Coordinator so that it gracefully integrates with TCA. I've seen some examples (one in composable-core-location) using bindings but it doesn't quite fit what I'm trying to do here. For some context; I have a If it's of any help, here's what my WebView and its Coordinator look like: struct WebView: UIViewRepresentable {
class Coordinator: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
var webView: WKWebView?
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.webView = webView
}
func makeUIView(context: Context) -> WKWebView {
let coordinator = makeCoordinator()
let userContentController = WKUserContentController()
userContentController.add(coordinator, name: "bridge")
let configuration = WKWebViewConfiguration()
configuration.userContentController = userContentController
let _wkwebview = WKWebView(frame: .zero, configuration: configuration)
_wkwebview.navigationDelegate = coordinator
return _wkwebview
}
// receive message from wkwebview
func userContentController(
_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage
) {
// We got a message from the webview!
// How should I send an action to a TCA store from here?
print(message.body)
}
}
} I've toyed with the ideal of passing a TCA Store to the WebView, but that still doesn't really give me a ViewStore accessible from within the coordinator in order to send actions to the store 🤔 Any ideas/suggestions would be appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This is how I did |
Beta Was this translation helpful? Give feedback.
-
If you pass ViewStore(store.stateless).send(.didReceive(message)) PS. If you hold a reference from |
Beta Was this translation helpful? Give feedback.
This is how I did
https://github.com/AddaMeSPB/AddaMeIOS/blob/siteRouter/AddameSPM/Sources/SettingsFeature/TermsAndPrivacyWebView.swift#L21