Skip to content

Commit

Permalink
1.完善
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinaLike committed Mar 10, 2022
1 parent e4ff2f2 commit a46eee9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class JsBridgeToast(private val context: Context) {
android:layout_width="match_parent"
android:layout_height="match_parent"/>
```
> 当然,如果没有特殊需要使用`JsBridgeWebView`就可以了,如果有定制WebView,则引入自己定制那个WebView就可以了,但是自定义的WebView需要继承[BaseWebView](https://github.com/ChinaLike/JsBridge/blob/main/library/src/main/java/com/core/web/base/BaseWebView.kt)
> 当然,如果没有特殊需要使用`JsBridgeWebView`就可以了,如果有定制WebView,则引入自己定制那个WebView就可以了,但是自定义的WebView需要继承[JsBridgeWebView](https://github.com/ChinaLike/JsBridge/blob/main/library/src/main/java/com/core/web/JsBridgeWebView.kt)
+ 在Activity中调用`addJavascriptInterface`添加

Expand Down
6 changes: 3 additions & 3 deletions library/src/main/java/com/core/web/JsBridgeWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import com.core.web.base.BaseWebView
* @author like
* @date 6/11/21 10:45 AM
*/
class JsBridgeWebView : BaseWebView {
open class JsBridgeWebView : BaseWebView {


constructor(context: Context) : super(context)

constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
context,
attrs,
defStyle
Expand Down
8 changes: 3 additions & 5 deletions library/src/main/java/com/core/web/base/BaseWebView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.core.web.*
* @author like
* @date 5/24/21 4:19 PM
*/
open class BaseWebView : WebView, IWebView {
abstract class BaseWebView : WebView, IWebView {

/**
* js回调管理
Expand All @@ -38,11 +38,11 @@ open class BaseWebView : WebView, IWebView {
initWebView()
}

constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
initWebView()
}

constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
context,
attrs,
defStyle
Expand All @@ -51,8 +51,6 @@ open class BaseWebView : WebView, IWebView {
}

private fun initWebView() {
isVerticalScrollBarEnabled = false
isHorizontalScrollBarEnabled = false
settings.javaScriptEnabled = true
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setWebContentsDebuggingEnabled(true)
Expand Down
5 changes: 3 additions & 2 deletions library/src/main/java/com/core/web/base/BaseWebViewClient.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.core.web.base

import android.graphics.Bitmap
import android.util.Log
import android.webkit.WebView
import android.webkit.WebViewClient
Expand All @@ -22,8 +23,8 @@ open class BaseWebViewClient : WebViewClient() {
private val injectUrl = mutableListOf<String>()

@CallSuper
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
override fun onPageStarted(view: WebView?, url: String, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
if (view is BaseWebView && !injectUrl.contains(url)) {
if (jsInject == null) {
jsInject = JsInject(view)
Expand Down

0 comments on commit a46eee9

Please sign in to comment.