use shared webview and remove message handlers before each use

This commit is contained in:
Satindar Dhillon 2022-03-22 11:54:54 -07:00
parent 6bb8f76f40
commit e85558114c

View file

@ -28,7 +28,7 @@ struct WebReader: UIViewRepresentable {
}
func makeUIView(context: Context) -> WKWebView {
let webView = WebViewManager.create()
let webView = WebViewManager.shared()
let contentController = WKUserContentController()
webView.loadHTMLString(
@ -52,6 +52,8 @@ struct WebReader: UIViewRepresentable {
webView.scrollView.contentInset.top = readerViewNavBarHeight
webView.scrollView.verticalScrollIndicatorInsets.top = readerViewNavBarHeight
webView.configuration.userContentController.removeAllScriptMessageHandlers()
for action in WebViewAction.allCases {
webView.configuration.userContentController.add(context.coordinator, name: action.rawValue)
}