1.0.16 • Published 2 years ago
rabbitjs-bridge-gateway
Licence
ISC
Version
1.0.16
Deps
3
Size
12 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated
JS Bridge Gateway
JS Bridge Gateway is a bridge tha make JS easily talk to native app and vice versa
Install
yarn
yarn add rabbitjs-bridge-gateway
npm
npm i rabbitjs-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 |
| delay | 200 | number |
Specify the delay(ms) on register hanlder function |
// root.ts
import JsBridgeCmcb from "rabbitjs-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();
}
});