npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

react-native-promisable-webview

1.0.2 • Public • Published

PromisableWebView

A ReactNative WebView with a Promise-adapter.

This component is based on WKWebView which provides a bridge between ReactNative context and the WebView context. That adapter allows you to evaluateJavaScript() code inside the WebView, and postMessage() back to ReactNative. Note that evaluateJavaScript() does not return any value, so in order to synchronize the ReactNative side needs to wait for some message to return from the WebView.

This component wraps the WKWebView bridge and allows you to evaluate JS code within the WebView and get a Promise back:

this.webview.evaluateJavaScriptWithPromise('Promise.resolve()')
  .then(() => console.log('resolved!'))

Handling Page Loads

The WebView might unload the page while a Promise is in "pending" state - either because the JavaScript code that evaluateJavaScriptWithPromise() evaluates navigates away from the page, or because the web page decides to reload or navigate away for some other reason.

In such cases the PromisableWebView rejects any pending promises with "WEBVIEW_RELOADED" as the reason.

install

npm i react-native-promisable-webview

Downloadsweekly downloads

0

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability