sirencode / RainbowBridge

A safe JsBridge framework!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RainbowBridge

A safe JsBridge framework!


Gif

JsBridge

Js invoke Native protocol

rainbow://class:port/method?params

params is a json string.

Return to the Js data format

resultData = {
    status: {
        code: 0,//0:Success,1:Failure
        msg: 'request timeout'//Failure to display a message, success can be null
    },
    data: {}//resultData,can be null
};

Call the Js callback format

javascript:RainbowBridge.onComplete('port','resultData');

The method`s format can be invoked by Js

public static void ***(WebView webView, JSONObject data, JsCallback callback) {
	 //...
	 JsCallback.invokeJsCallback(callback, true, result, null);
}

If the native method is time consuming operation.Such use:

public static void ***(WebView webView, JSONObject data, JsCallback callback) {
	 AsyncTaskExecutor.runOnAsyncThread(new Runnable() {
        @Override
        public void run() {
            //IO、decode、sqlite... 
            JsCallback.invokeJsCallback(callback, true, result, null);
        }
    });
}
        

About

A safe JsBridge framework!


Languages

Language:Java 71.6%Language:HTML 14.5%Language:JavaScript 14.0%