Skip to content

ZLBridge是为JS和原生WebView进行数据交互时提供更简单方便的小工具,目前已支持ZLBridge-Android,ZLBridge-iOS,ZLBridge-flutter,ZLBridge-RN

Notifications You must be signed in to change notification settings

FPJack/ZLBridge-JS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ZLBridge

说明

ZLBridge是为JS和原生WebView进行数据交互时提供更简单方便的小工具,目前支持平台有
ZLBridge-iOS
ZLBridge-Android
ZLBridge-JS
ZLBridge-flutter
ZLBridge-RN

安装

npm install zlbridge 

初始化

//导入之后也可通过全局window.zlbridge拿zlbridge对象
import zlbridge from "zlbridge";
或者
var zlbridge = require('zlbridge')

JS调用原生事件

无参数

window.zlbridge.call('test',(arg) => {

});

有参数参数

window.zlbridge.call('test',{key:"value"},(arg) => {

});

JS注册原生事件

//直接返回值到原生
window.zlbridge.register("jsMethod",(arg) => {
     return arg;
});

或者

//callback函数返回值到原生
window.zlbridge.registerWithCallback("jsMethod",(arg,callback) => {
 //ture代表原生只能接受一次JS回调结果,false可以连续监听,默认不传为true
 callback(arg,true);
});

通过本地注入JS脚本的,H5可以监听zlbridge对象初始化完成

document.addEventListener('ZLBridgeInitReady', function() {
    console.log('ZLBridge初始化完成');
},false);

Author

范鹏, [email protected]

License

ZLBridge is available under the MIT license. See the LICENSE file for more info.

About

ZLBridge是为JS和原生WebView进行数据交互时提供更简单方便的小工具,目前已支持ZLBridge-Android,ZLBridge-iOS,ZLBridge-flutter,ZLBridge-RN

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published