Skip to content

afeiship/rn-module-webview-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

rn-module-webview-bridge

Rn module webview bridge.

h5 call native:

function callNative(inData){
  window.postMessage( JSON.stringify(inData) )
}

btn2.addEventListener('click', (e) => {
  callNative({
    invoke:'do',
    name:'msg',
    data:{
      content:'message from h5 by postMessage method btn2.'
    }
  });
});

native call h5:

const { webview } = this.refs;
webview.injectJavaScript('window.h5Method()')

set query data:

_onLoadStart = e => {
  const { webview } = this.refs;
  const webviewParams = {
      user_id:1234,
      data:1234,
      otherData:['123','23']
  };
  webview.injectJavaScript(`window.__PARAMS__ =${JSON.stringify(webviewParams)}`);
}

resources:

demo: