@0x0006e/hybrid-js-sdk 中文文档教程
Hybrid JS-SDK
Core
Web -> Native
Native 将全局函数注入浏览器:
- iOS: window.webkit.messageHandlers.nativeApp.postMessage
- Android: window.nativeApp.sendToNative
Native -> Web
Web 为窗口定义了两种方法:
- window.webApp.callback
- window.webApp.dispatch
Install & API
使用 npm:
$ npm install @0x0006e/hybrid-js-sdk
或使用 yarn:
$ yarn add @0x0006e/hybrid-js-sdk
Web -> Native
- Web dispatch
event
to native
hybrid.dispatch(event, params).then(console.log);
- Web handle native dispatch
event
const unsubscribe1 = hybrid.listen(event, callback);
const unsubscribe2 = hybrid.listen(event, callback);
- unsubscribe
event
unsubscribe1()
Native -> Web
- Native dispatch
event
to web
webApp.dispatch(event, params);
- Native handle web dispatch
event
setTimeout(() => {
webApp.callBack(eventId, params);
});
Preview
git clone https://github.com/0x0006e/Hybrid-JS-SDK.git
cd Hybrid-JS-SDK/examples
yarn && yarn start
TODO
- [ ] tests
- [x] workflow CI CD
- [ ] lint
Others
- PR thanks!
Hybrid JS-SDK
Core
Web -> Native
Native inject global function into browser:
- iOS: window.webkit.messageHandlers.nativeApp.postMessage
- Android: window.nativeApp.sendToNative
Native -> Web
Web define two methods to window:
- window.webApp.callback
- window.webApp.dispatch
Install & API
by using npm:
$ npm install @0x0006e/hybrid-js-sdk
or by using yarn:
$ yarn add @0x0006e/hybrid-js-sdk
Web -> Native
- Web dispatch
event
to native
hybrid.dispatch(event, params).then(console.log);
- Web handle native dispatch
event
const unsubscribe1 = hybrid.listen(event, callback);
const unsubscribe2 = hybrid.listen(event, callback);
- unsubscribe
event
unsubscribe1()
Native -> Web
- Native dispatch
event
to web
webApp.dispatch(event, params);
- Native handle web dispatch
event
setTimeout(() => {
webApp.callBack(eventId, params);
});
Preview
git clone https://github.com/0x0006e/Hybrid-JS-SDK.git
cd Hybrid-JS-SDK/examples
yarn && yarn start
TODO
- [ ] tests
- [x] workflow CI CD
- [ ] lint
Others
- PR thanks!
更多
你可能也喜欢
- 2gis-maps 中文文档教程
- 334-stopwatch-game 中文文档教程
- 7seasofcrypto-pirates-uikit 中文文档教程
- @0bie/pattern-lib-react 中文文档教程
- @0x-lerna-fork/collect-uncommitted 中文文档教程
- @168496714/create-react-component 中文文档教程
- @51xuanshi/wxapp_component 中文文档教程
- @9troisquarts/antd-form.ant-form 中文文档教程
- @a8k/nunjucks-loader 中文文档教程
- @aave/safety-module 中文文档教程