
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
@tuya/react-native-webview-invoke
Advanced tools
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)

$ npm install react-native-webview-invoke --save
Requires:
There are two sides: native and web.
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)
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>
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'
createInvoke(getWebViewInstance)(RN only) create
invokewith theWebviewinstance.
Args:
() => React.WebView] getter for Webview instanceReturn:
invoke] invoke objectinvoke.define(name, fn)expose function to another side.
Args:
string] function nameFunction]invoke.bind(name)get function from another side
Args:
string] function nameReturn:
[(...args: any[]) => Promise<any>] function
invoke.fnAll 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
onMessageproperty ofWebViewelement.
Usage:
<WebView onMessage={invoke.listener} />
FAQs
Invoke functions between React Native and WebView directly
The npm package @tuya/react-native-webview-invoke receives a total of 2 weekly downloads. As such, @tuya/react-native-webview-invoke popularity was classified as not popular.
We found that @tuya/react-native-webview-invoke demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.