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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    9
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    9
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i react-native-promisable-webview

Weekly Downloads

9

Version

1.0.2

License

MIT

Last publish

Collaborators

  • benzaita