feat: webview manager and js bridge skeleton
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package top.yeij.hearth.webview
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebSettings
|
||||
import android.webkit.WebViewClient
|
||||
|
||||
class WebViewManager(private val activity: Activity) {
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
fun attach(bridge: JsBridge): WebView {
|
||||
val webView = WebView(activity)
|
||||
webView.settings.apply {
|
||||
javaScriptEnabled = true
|
||||
useWideViewPort = true
|
||||
loadWithOverviewMode = true
|
||||
setSupportZoom(false)
|
||||
domStorageEnabled = true
|
||||
}
|
||||
webView.addJavascriptInterface(bridge, "HearthBridge")
|
||||
webView.webViewClient = WebViewClient()
|
||||
webView.loadUrl("file:///android_asset/h5/index.html")
|
||||
activity.setContentView(webView)
|
||||
return webView
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user