Installations
npm install react-native-webview-invoke
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
12.16.1
NPM Version
6.14.5
Score
80.9
Supply Chain
99.6
Quality
76.2
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (51.57%)
Java (15.82%)
Ruby (13.15%)
Objective-C (10.75%)
HTML (7.23%)
Starlark (1.48%)
Developer
pinqy520
Download Statistics
Total Downloads
283,217
Last Day
89
Last Week
1,889
Last Month
15,808
Last Year
138,763
GitHub Statistics
242 Stars
124 Commits
44 Forks
10 Watching
1 Branches
4 Contributors
Package Meta Information
Latest Version
0.6.2
Package Id
react-native-webview-invoke@0.6.2
Unpacked Size
46.86 kB
Size
8.19 kB
File Count
18
NPM Version
6.14.5
Node Version
12.16.1
Total Downloads
Cumulative downloads
Total Downloads
283,217
Last day
-84%
89
Compared to previous day
Last week
-36%
1,889
Compared to previous week
Last month
-11.5%
15,808
Compared to previous month
Last year
290.5%
138,763
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
react-native-webview-invoke
Invoke functions between React Native and WebView directly
react-native-webview-bridge
Support
Just like:
1// Side A 2const answer = await ask(question) 3 4// Side B 5function ask(question) { return 'I don\'t know' }
Before using like that, you should firstly define the function you want to expose.
1// Side A 2const ask = invoke.bind('ask') 3 4// Side B 5invoke.define('ask', ask)
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
1import createInvoke from 'react-native-webview-invoke/native'
Create invoke
1class SomePage extends React.Component { 2 webview: WebView 3 invoke = createInvoke(() => this.webview) 4 render() { 5 // Note: add 'useWebKit' property for rn > 0.59 6 return <Webview useWebKit 7 ref={webview => this.webview = webview} 8 onMessage={this.invoke.listener} 9 source={require('./index.html')} 10 /> 11 } 12}
Now, we can start to expose functions for Web, and get the function from Web. (See Start to use)
Web Side
Import
1import invoke from 'react-native-webview-invoke/browser'
Or use <script>
in .html
1<script src="./node_modules/react-native-webview-invoke/dist/browser.umd.js"></script> 2<script> 3var invoke = window.WebViewInvoke 4</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.
1function whatIsTheNameOfA() { 2 return 'A' 3} 4 5function tellAYouArea(someone: string, prefix: string) { 6 return 'Hi, ' + prefix + someone + '!' 7}
Expose them for B side.
1invoke 2 .define('whatIsTheNameOfA', whatIsTheNameOfA) 3 .define('tellAYouArea', tellAYouArea)
OK, Go to the B side:
Firstly, bind some functions which exposed from A
.
1const whatIsTheNameOfA = invoke.bind('whatIsTheNameOfA') 2const tellAYouArea = invoke.bind('tellAYouArea')
Now, we can use them.
1await whatIsTheNameOfA() 2// 'A' 3await tellAYouArea('B', 'Mr.') 4// 'Hi, Mr.B'
In addition, you can use them without definition too.
1await invoke.fn.whatIsTheNameOfA() 2// 'A' 3await invoke.fn.tellAYouArea('B', 'Mr.') 4// 'Hi, Mr.B'
API
createInvoke(getWebViewInstance)
(RN only) create
invoke
with theWebview
instance.
Args:
- getWebViewInstance [
() => React.WebView
] getter forWebview
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
1// A side 2invoke.define('test', test) 3 4// B side 5invoke.fn.test()
invoke.listener
(RN only) the handler for the
onMessage
property ofWebView
element.
Usage:
1<WebView onMessage={invoke.listener} />
No vulnerabilities found.
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
binaries present in source code
Details
- Warn: binary detected: dev/android/gradle/wrapper/gradle-wrapper.jar:1
Reason
Found 2/25 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
2.9
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-native-webview-invoke
@icanbwell/react-native-webview-invoke
Invoke functions between React Native and WebView directly
@tuya/react-native-webview-invoke
Invoke functions between React Native and WebView directly
react-native-postmessage-cat
Passing object and type between React Native main process and WebView process simply via proxy.
react-native-webview-bridge-seamless
make it easy to invoke functions on webview and in react