It is based on this repository.
A new pull-request has been sent to the original repository, though it is still pending.
-
it supports customizing bridge name
-
BridgeWebViewClient
supports setting a customedWebViewClient
to do extra filtering or something -
in
BridgeWebViewClient #onPageFinished()
, copy startmessages and set it to null to prevent furthermore message being stored in startmessages -
bug fix: if
WebViewJavascriptBridge.init(..)
method is not called from the content page, all response callbacks would not be dispatched.In the original code,
receiveMessageQueue
is used to store messages sent from java before a default handler is registered.In the fixed code,
receiveMessageQueue
is renamed tounhandledMessageQueue
and the timepoint at which a message without handler is queued is defered to_dispatchMessageFromNative(..)
-
Set a custom name to your bridge:
The default name of bridge you can use in h5 page is WebViewJavascriptBridge.
If you want to rename it to haha, use
bridge_name
attr as below:<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"> <com.github.ziv.lib.jsbridge.BridgeWebView android:id="@+id/webView" android:layout_width="match_parent" android:layout_height="match_parent" app:bridge_name="haha"> </com.github.ziv.lib.jsbridge.BridgeWebView> </LinearLayout>
-
Set your own
WebViewClient
toBridgeWebView
webView.getBridgeWebViewClient().setExtraWebViewClient(new MxWebViewClient());
In your project root build.gradle, add jitpack to your repositories
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
and in the build.gradle of your app module:
compile 'com.github.ziv-zh:js-bridge:0.4.0'
-keep class com.github.ziv.lib.jsbridge.Message{*;}