- 引入XWebViewActivity以提供完整的WebView界面 - 在AndroidManifest.xml中注册新的WebView活动 - 更新桥接功能以支持上下文启动活动 - 将内部函数和类可见性调整为internal以便组件间访问 - 增加发布版本号从0.4.3到0.4.9
37 行
1.3 KiB
Kotlin
37 行
1.3 KiB
Kotlin
package com.xuqm.sdk.webview
|
|
|
|
import android.content.Context
|
|
import android.content.Intent
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
private val currentConfig = mutableStateOf(XWebViewConfig())
|
|
private var currentController: XWebViewController? = null
|
|
|
|
fun openXWebView(config: XWebViewConfig) {
|
|
currentConfig.value = config
|
|
}
|
|
|
|
fun openXWebView(context: Context, config: XWebViewConfig) {
|
|
currentConfig.value = config
|
|
context.startActivity(Intent(context, XWebViewActivity::class.java))
|
|
}
|
|
|
|
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) }
|
|
override fun postMessageToWeb(js: String) { currentController?.postMessageToWeb(js) }
|
|
}
|