项目作者: HongKongDoll

项目描述 :
Hybrid JS-SDK
高级语言: TypeScript
项目地址: git://github.com/HongKongDoll/Hybrid-JS-SDK.git
创建时间: 2019-07-13T16:27:50Z
项目社区:https://github.com/HongKongDoll/Hybrid-JS-SDK

开源协议:

下载


Hybrid JS-SDK

截屏2025-05-10 13 25 13

Examples

Install

  1. yarn
  2. yarn build
  3. cd examples
  4. yarn
  5. yarn start

Xcode build

  • xcode open examples folder and build with simulator

Core

Web -> Native

Native inject global function into browser:

  • nativeBridge.sendMessage

Native -> Web

Web define two methods to window:

  • window.webApp.callback
  • window.webApp.dispatch

API

Web -> Native

examples/src/index.js

  • Web dispatch event to native
  1. hybrid.dispatch(event, params).then(console.log);
  • Web handle native dispatch event
  1. const unsubscribe1 = hybrid.listen(event, callback);
  2. const unsubscribe2 = hybrid.listen(event, callback);
  • unsubscribe event
  1. unsubscribe1()

Native -> Web

examples/src/index.js

  • Native dispatch event to web
  1. webApp.dispatch(event, params);
  • Native handle web dispatch event
  1. setTimeout(() => {
  2. webApp.callBack(eventId, params);
  3. });