All Projects → pinqy520 → React Native Webview Invoke

pinqy520 / React Native Webview Invoke

Licence: mit
Invoke functions between React Native and WebView

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Webview Invoke

Aachartcore
📈📊☕️☕️☕️An elegant modern declarative data visualization chart framework for Android. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
Stars: ✭ 424 (+100.95%)
Mutual labels:  hybrid, webview
Agentweb
AgentWeb is a powerful library based on Android WebView.
Stars: ✭ 8,375 (+3869.19%)
Mutual labels:  hybrid, webview
Aachartkit
📈📊🚀🚀🚀An elegant modern declarative data visualization chart framework for iOS, iPadOS and macOS. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types. 极其精美而又强大的跨平台数据可视化图表框架,支持柱状图、条形图、折…
Stars: ✭ 4,358 (+1965.4%)
Mutual labels:  hybrid, webview
webviewhs
🌐 A Haskell binding to the webview library created by Serge Zaitsev.
Stars: ✭ 109 (-48.34%)
Mutual labels:  webview, native
Vassonic
VasSonic is a lightweight and high-performance Hybrid framework developed by tencent VAS team, which is intended to speed up the first screen of websites working on Android and iOS platform.
Stars: ✭ 11,466 (+5334.12%)
Mutual labels:  hybrid, webview
Nat
A powerful kit for adding native functionalities to your weex app.
Stars: ✭ 294 (+39.34%)
Mutual labels:  hybrid, native
Andorid Litehybrid Webview
A android hybrid framework, works for H5 and native interactions via webview.
Stars: ✭ 39 (-81.52%)
Mutual labels:  hybrid, webview
rn-webview-rpc
Add RPC capabilities to a React Native WebView component
Stars: ✭ 25 (-88.15%)
Mutual labels:  webview, bridge
Iamport React Native
React Native용 아임포트 일반.결제 및 휴대폰 본인인증 모듈입니다.
Stars: ✭ 88 (-58.29%)
Mutual labels:  native, webview
Nat Explorer
An example project using Nat & Weex.
Stars: ✭ 55 (-73.93%)
Mutual labels:  hybrid, native
RobustWebView
Android WebView H5 秒开方案总结
Stars: ✭ 38 (-81.99%)
Mutual labels:  webview, hybrid
Hybridfoundation
混合应用基础架构 跨平台热更新方案 Js双向通信 基础WebView
Stars: ✭ 164 (-22.27%)
Mutual labels:  hybrid, webview
FlexHybridApp-Android
WebView bridge interface with Promise pattern
Stars: ✭ 20 (-90.52%)
Mutual labels:  webview, bridge
Aachartcore Kotlin
📈📊⛰⛰⛰An elegant modern declarative data visualization chart framework for Android . Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
Stars: ✭ 332 (+57.35%)
Mutual labels:  hybrid, webview
Hybrid-Web-Platform
Full-fledged WebView as Xamarin.Forms plugin with cross-platform C# to JavaScript and JavaScript to C# calls support. Eventually invented for painless hybrid apps creation.
Stars: ✭ 19 (-91%)
Mutual labels:  webview, hybrid
Wkwebviewjavascriptbridge
🌉 A Bridge for Sending Messages between Swift and JavaScript in WKWebViews.
Stars: ✭ 863 (+309%)
Mutual labels:  bridge, hybrid
Google-Docs-for-Mac
Native Google Docs app for Mac
Stars: ✭ 33 (-84.36%)
Mutual labels:  webview, native
Android-WebView-in-Kotlin
Native Android WebView Example in Kotlin. Website to android app github open source template.
Stars: ✭ 87 (-58.77%)
Mutual labels:  webview, native
Vue Bridge Webview
javascript bridge android/ios webview
Stars: ✭ 52 (-75.36%)
Mutual labels:  bridge, webview
Easybridge
A design of easy js-bridge which provide the ability to communicate between java and javascript.It is based on the android webview's feature [addJavaScriptInterface]
Stars: ✭ 158 (-25.12%)
Mutual labels:  hybrid, webview

react-native-webview-invoke

中文文档

npm version

Invoke functions between React Native and WebView directly

react-native-webview-bridge Support

Just like:

// Side A
const answer = await ask(question) 

// Side B
function ask(question) { return 'I don\'t know' }

Before using like that, you should firstly define the function you want to expose.

// Side A
const ask = invoke.bind('ask')

// Side B
invoke.define('ask', ask)

rnwm

Installation

$ npm install react-native-webview-invoke --save

Requires:

  • React Native >= 0.37

Basic Usage

There are two sides: native and web.

React Native Side

Import

import createInvoke from 'react-native-webview-invoke/native'

Create invoke

class SomePage extends React.Component {
    webview: WebView
    invoke = createInvoke(() => this.webview)
    render() {
        // Note: add 'useWebKit' property for rn > 0.59
        return <Webview useWebKit
            ref={webview => this.webview = webview}
            onMessage={this.invoke.listener}
            source={require('./index.html')}
            />
    }
}

Now, we can start to expose functions for Web, and get the function from Web. (See Start to use)

Web Side

Import

import invoke from 'react-native-webview-invoke/browser'

Or use <script> in .html

<script src="./node_modules/react-native-webview-invoke/dist/browser.umd.js"></script>
<script>
var invoke = window.WebViewInvoke
</script>

Start to use

For better illumination, we define two sides named A and B. each of them can be React Native or Web, and if A is React Native, then B is Web.

Assume that there are some functions in A side.

function whatIsTheNameOfA() {
    return 'A'
}

function tellAYouArea(someone: string, prefix: string) {
    return 'Hi, ' + prefix + someone + '!'
}

Expose them for B side.

invoke
    .define('whatIsTheNameOfA', whatIsTheNameOfA)
    .define('tellAYouArea', tellAYouArea)

OK, Go to the B side:

Firstly, bind some functions which exposed from A.

const whatIsTheNameOfA = invoke.bind('whatIsTheNameOfA')
const tellAYouArea = invoke.bind('tellAYouArea')

Now, we can use them.

await whatIsTheNameOfA()
// 'A'
await tellAYouArea('B', 'Mr.')
// 'Hi, Mr.B'

In addition, you can use them without definition too.

await invoke.fn.whatIsTheNameOfA()
// 'A'
await invoke.fn.tellAYouArea('B', 'Mr.')
// 'Hi, Mr.B'

API

createInvoke(getWebViewInstance)

(RN only) create invoke with the Webview instance.

Args:

  • getWebViewInstance [() => React.WebView] getter for Webview instance

Return:

  • invoke [invoke] invoke object

invoke.define(name, fn)

expose function to another side.

Args:

  • name [string] function name
  • fn [Function]

invoke.bind(name)

get function from another side

Args:

  • name [string] function name

Return:

[(...args: any[]) => Promise<any>] function

invoke.fn

All functions that defined at the other side

Usage

// A side
invoke.define('test', test)

// B side
invoke.fn.test()

invoke.listener

(RN only) the handler for the onMessage property of WebView element.

Usage:

<WebView onMessage={invoke.listener} />
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].