2026-05-07 19:39:38 +08:00
|
|
|
package com.xuqm.sdk.webview
|
|
|
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
|
|
|
|
|
private val currentConfig = mutableStateOf(XWebViewConfig())
|
|
|
|
|
private var currentController: XWebViewController? = null
|
|
|
|
|
|
|
|
|
|
fun openXWebView(config: XWebViewConfig) {
|
|
|
|
|
currentConfig.value = config
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getXWebViewConfig(): XWebViewConfig = currentConfig.value
|
|
|
|
|
|
|
|
|
|
fun setXWebViewController(controller: XWebViewController?) {
|
|
|
|
|
currentController = controller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getXWebViewController(): XWebViewController? = currentController
|
|
|
|
|
|
|
|
|
|
object XWebViewControl : XWebViewController {
|
|
|
|
|
override fun canGoBack(): Boolean = currentController?.canGoBack() ?: false
|
|
|
|
|
override fun canGoForward(): Boolean = currentController?.canGoForward() ?: false
|
|
|
|
|
override fun currentUrl(): String? = currentController?.currentUrl()
|
2026-05-11 15:21:54 +08:00
|
|
|
override fun goBack() { currentController?.goBack() }
|
|
|
|
|
override fun goForward() { currentController?.goForward() }
|
|
|
|
|
override fun reload() { currentController?.reload() }
|
|
|
|
|
override fun loadUrl(url: String) { currentController?.loadUrl(url) }
|
|
|
|
|
override fun postMessageToWeb(js: String) { currentController?.postMessageToWeb(js) }
|
2026-05-07 19:39:38 +08:00
|
|
|
}
|