Skip to content
Open
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
24 changes: 24 additions & 0 deletions Sources/MarkdownWebView/MarkdownWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ import WebKit
#elseif os(iOS)
public func makeUIView(context: Context) -> CustomWebView { context.coordinator.platformView }
#endif

#if os(macOS)
public static func dismantleNSView(_ nsView: CustomWebView, coordinator: Coordinator) {
let platformView = coordinator.platformView

platformView.configuration.userContentController.removeScriptMessageHandler(
forName: "sizeChangeHandler")
platformView.configuration.userContentController.removeScriptMessageHandler(
forName: "renderedContentHandler")
platformView.configuration.userContentController.removeScriptMessageHandler(
forName: "copyToPasteboard")
}
#elseif os(iOS)
public static func dismantleUIView(_ uiView: CustomWebView, coordinator: Coordinator) {
let platformView = coordinator.platformView

platformView.configuration.userContentController.removeScriptMessageHandler(
forName: "sizeChangeHandler")
platformView.configuration.userContentController.removeScriptMessageHandler(
forName: "renderedContentHandler")
platformView.configuration.userContentController.removeScriptMessageHandler(
forName: "copyToPasteboard")
}
#endif

func updatePlatformView(_ platformView: CustomWebView, context _: Context) {
guard !platformView.isLoading else { return } /// This function might be called when the page is still loading, at which time `window.proxy` is not available yet.
Expand Down