1.0.0 • Published 1 month ago

js-bridge-gateway v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

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

PropDefaultTypeDescription
debugfalsebooleanTo enable log info in debug mode
mockfalsebooleanFor testing mode and will return empty data on callHandler or registerHandler
delay200numberSpecify 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();
      }
});