40 行
1.1 KiB
Kotlin
40 行
1.1 KiB
Kotlin
|
|
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()
|
||
|
|
override fun goBack() {
|
||
|
|
currentController?.goBack()
|
||
|
|
}
|
||
|
|
|
||
|
|
override fun goForward() {
|
||
|
|
currentController?.goForward()
|
||
|
|
}
|
||
|
|
|
||
|
|
override fun reload() {
|
||
|
|
currentController?.reload()
|
||
|
|
}
|
||
|
|
|
||
|
|
override fun loadUrl(url: String) {
|
||
|
|
currentController?.loadUrl(url)
|
||
|
|
}
|
||
|
|
}
|