2026-05-07 19:39:48 +08:00
|
|
|
import Foundation
|
2026-06-05 15:48:08 +08:00
|
|
|
import XuqmFileSDK
|
2026-05-07 19:39:48 +08:00
|
|
|
|
|
|
|
|
public struct XWebViewConfig: Sendable {
|
|
|
|
|
public var url: String
|
|
|
|
|
public var title: String
|
|
|
|
|
public var hideToolbar: Bool
|
|
|
|
|
public var hideStatusBar: Bool
|
|
|
|
|
public var userAgent: String?
|
2026-05-11 15:21:54 +08:00
|
|
|
public var injectedJavaScript: String?
|
2026-06-29 11:28:18 +08:00
|
|
|
/// Native message handler name registered in WKUserContentController.
|
|
|
|
|
/// H5 side calls `window.webkit.messageHandlers.<jsBridgeName>.postMessage(json)`.
|
|
|
|
|
public var jsBridgeName: String
|
2026-06-05 15:48:08 +08:00
|
|
|
/// Where intercepted WebView downloads are saved.
|
|
|
|
|
public var downloadDestination: FileDownloadDestination
|
2026-06-29 11:28:18 +08:00
|
|
|
/// Custom message callback — receives raw JSON string from H5 via jsBridgeName bridge.
|
2026-05-11 15:21:54 +08:00
|
|
|
public var onMessage: (@Sendable (String) -> Void)?
|
2026-06-29 11:28:18 +08:00
|
|
|
/// Called when the WebView container should close (xuqm.closeWebView JSBridge command).
|
|
|
|
|
public var onClose: (@Sendable () -> Void)?
|
|
|
|
|
/// Called on page load error. Receives a human-readable error description.
|
|
|
|
|
public var onPageError: (@Sendable (String) -> Void)?
|
|
|
|
|
/// Called as the page loads. Progress is 0–100.
|
|
|
|
|
public var onProgressChanged: (@Sendable (Int) -> Void)?
|
|
|
|
|
/// Called when the navigation stack changes. (canGoBack, canGoForward)
|
|
|
|
|
public var onNavigationChanged: (@Sendable (Bool, Bool) -> Void)?
|
2026-05-07 19:39:48 +08:00
|
|
|
|
|
|
|
|
public init(
|
|
|
|
|
url: String = "",
|
|
|
|
|
title: String = "",
|
|
|
|
|
hideToolbar: Bool = false,
|
|
|
|
|
hideStatusBar: Bool = false,
|
2026-05-11 15:21:54 +08:00
|
|
|
userAgent: String? = nil,
|
|
|
|
|
injectedJavaScript: String? = nil,
|
2026-06-29 11:28:18 +08:00
|
|
|
jsBridgeName: String = "SZYX_APP",
|
2026-06-05 15:48:08 +08:00
|
|
|
downloadDestination: FileDownloadDestination = .sandbox,
|
2026-06-29 11:28:18 +08:00
|
|
|
onMessage: (@Sendable (String) -> Void)? = nil,
|
|
|
|
|
onClose: (@Sendable () -> Void)? = nil,
|
|
|
|
|
onPageError: (@Sendable (String) -> Void)? = nil,
|
|
|
|
|
onProgressChanged: (@Sendable (Int) -> Void)? = nil,
|
|
|
|
|
onNavigationChanged: (@Sendable (Bool, Bool) -> Void)? = nil
|
2026-05-07 19:39:48 +08:00
|
|
|
) {
|
|
|
|
|
self.url = url
|
|
|
|
|
self.title = title
|
|
|
|
|
self.hideToolbar = hideToolbar
|
|
|
|
|
self.hideStatusBar = hideStatusBar
|
|
|
|
|
self.userAgent = userAgent
|
2026-05-11 15:21:54 +08:00
|
|
|
self.injectedJavaScript = injectedJavaScript
|
2026-06-29 11:28:18 +08:00
|
|
|
self.jsBridgeName = jsBridgeName
|
2026-06-05 15:48:08 +08:00
|
|
|
self.downloadDestination = downloadDestination
|
2026-05-11 15:21:54 +08:00
|
|
|
self.onMessage = onMessage
|
2026-06-29 11:28:18 +08:00
|
|
|
self.onClose = onClose
|
|
|
|
|
self.onPageError = onPageError
|
|
|
|
|
self.onProgressChanged = onProgressChanged
|
|
|
|
|
self.onNavigationChanged = onNavigationChanged
|
2026-05-07 19:39:48 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public protocol XWebViewController: AnyObject {
|
|
|
|
|
func canGoBack() -> Bool
|
|
|
|
|
func canGoForward() -> Bool
|
|
|
|
|
func currentUrl() -> String?
|
|
|
|
|
func goBack()
|
|
|
|
|
func goForward()
|
|
|
|
|
func reload()
|
|
|
|
|
func load(url: String)
|
2026-05-11 15:21:54 +08:00
|
|
|
func postMessageToWeb(js: String)
|
2026-05-07 19:39:48 +08:00
|
|
|
}
|