1.0.0 • Published 1 month ago
js-bridge-gateway v1.0.0
JS Bridge Gateway
JS Bridge Gateway is a bridge tha make JS easily talk to native app and vice versa
Install
yarn
yarn add js-bridge-gateway
npm
npm i js-bridge-gateway
Init Bridge
Make sure window object is not undefined when call init.
Init Option
Prop | Default | Type | Description |
---|---|---|---|
debug | false | boolean | To enable log info in debug mode |
mock | false | boolean | For testing mode and will return empty data on callHandler or registerHandler |
delay | 200 | number | Specify the delay(ms) on register hanlder function |
// root.ts
import JsBridgeCmcb from "js-bridge-gateway";
JsBridgeCmcb.init({ debug: true, delay: 200 });
Usage
Register a handler function so that native app can call
JsBridgeCmcb.registerHandler("hanlderName", (data: any, callback: any) => {
// Do sth...
});
Call handler to native app
const data = await JsBridgeCmcb.callHandler("hanlderName", { param: "fromWeb" });
Set Toolbar
await JsBridgeCmcb.setToolBar({
title: 'Sample',
backButtonColor: '#000000',
titleColor: '#000000',
backgroundColor: '#000000'
})
Goto Home Screen App
await JsBridgeCmcb.goToHome();
Listen back press event from native app and exit Mini App
JsBridgeCmcb.onBackPressed(async () => {
if (confirm("Do u want to exit?")) {
await JsBridgeCmcb.exit();
}
});