XuqmGroup-iOSSDK/Sources/XuqmWebViewSDK/XWebViewTypes.swift

68 行
2.7 KiB
Swift

2026-05-07 19:39:48 +08:00
import Foundation
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?
public var injectedJavaScript: String?
/// Native message handler name registered in WKUserContentController.
/// H5 side calls `window.webkit.messageHandlers.<jsBridgeName>.postMessage(json)`.
public var jsBridgeName: String
/// Where intercepted WebView downloads are saved.
public var downloadDestination: FileDownloadDestination
/// Custom message callback receives raw JSON string from H5 via jsBridgeName bridge.
public var onMessage: (@Sendable (String) -> Void)?
/// 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 0100.
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,
userAgent: String? = nil,
injectedJavaScript: String? = nil,
jsBridgeName: String = "SZYX_APP",
downloadDestination: FileDownloadDestination = .sandbox,
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
self.injectedJavaScript = injectedJavaScript
self.jsBridgeName = jsBridgeName
self.downloadDestination = downloadDestination
self.onMessage = onMessage
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)
func postMessageToWeb(js: String)
2026-05-07 19:39:48 +08:00
}