npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fanapptic-react-native-wkwebview-reborn

v1.21.2

Published

React Native WKWebView for iOS

Downloads

4

Readme

WKWebView Component for React Native

npm version

React Native comes with WebView component, which uses UIWebView on iOS. This component uses WKWebView introduced in iOS 8 with all the performance boost. Deployment Target >= iOS 8.0 is required

Install

Alternative #1

  1. Install from npm (note the postfix in the package name): npm install fanapptic-react-native-wkwebview-reborn
  2. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  3. Go to node_modules ➜ react-native-wkwebview ➜ ios ➜ select RCTWKWebView folder and create a group
  4. Compile and profit (Remember to set Minimum Deployment Target = 8.0)

Alternative #2

  1. Install from npm (note the postfix in the package name): npm install fanapptic-react-native-wkwebview-reborn
  2. run rnpm link

Notes to iOS 8:

If you install from using Alterntive #2, you might encounter bugs in iOS 8.2 (We've only tested this version) where the app crashes with dyld_fatal_error. This can be solved using Alternative #1. We were still unable to find the cause of the first bug so I recommend that you link the library using Alternative #1.

Usage

import WKWebView from 'fanapptic-react-native-wkwebview-reborn';

Try replacing your existing WebView with WKWebView and it should work in most cases.

Note on version

React Native 0.40 breaks library compatibility, so we currently have two branches:

  • 0.X.X: for RN < 0.40
  • 1.X.X: for RN >= 0.40

Please choose accordingly. We will try to make sure both branches have the same set of features until most people have upraded to 0.40

Compatibility with UIWebView

WKWebView aims to be a drop-in replacement for UIWebView. However, some legacy UIWebView properties are not supported.

Additional props:

  • onProgress

A callback to get the loading progress of WKWebView. Derived from estimatedProgress property.

<WKWebView onProgress={(progress) => console.log(progress)} />

progress is a double between 0 and 1.

  • openNewWindowInWebView (New in 0.4.0)

If set to true, links with target="_blank" or window.open will be opened in the current webview, not in Safari. Default is false.

  • sendCookies

Set sendCookies to true to copy cookies from sharedHTTPCookieStorage when calling loadRequest. This emulates the behavior of react-native's WebView component.

  • source={{file: '', allowingReadAccessToURL: '' }}

This allows WKWebView loads a local HTML file. Please note the underlying API is only introduced in iOS 9+. So in iOS 8, it will simple ignores these two properties. It allows you to provide a fallback URL for iOS 8 users.

<WKWebView source={{ file: RNFS.MainBundlePath + '/data/index.html', allowingReadAccessToURL: RNFS.MainBundlePath }} />

From WKWebview -> React Native (New in 0.3.0)

  • onMessage

This utilizes the message handlers in WKWebView and allows you to post message from webview to React Native. For example:

<WKWebView onMessage={(e) => console.log(e)} />

Then in your webview, you can post message to React Native using

window.webkit.messageHandlers.reactNative.postMessage({data: 'hello!'});

Then your React Native should have

{name: 'reactNative', body: {data: 'hello!'}}

The data serialization flow is as follows:

JS --- (via WKWebView) --> ObjC --- (via React Native Bridge) ---> JS

So I recommend to keep your data simple and JSON-friendly.

From React Native -> WkWebView (New in 0.3.0)

There is a evaluateJavaScript method on WKWebView, which does exactly what its name suggests. To send message from React Native to WebView, you can define a callback method on your WebView:

window.receivedMessageFromReactNative = function(data) {
  // Code here
  console.log(data);
}

Then you can send message from React Native with this method call:

// <WKWebView ref="webview" />
this.refs.webview.evaluateJavaScript('receivedMessageFromReactNative("Hello from the other side.")');

Currently supported props are:

  • automaticallyAdjustContentInsets
  • contentInset
  • html (deprecated)
  • injectedJavaScript
  • onError
  • onLoad
  • onLoadEnd
  • onLoadStart
  • onNavigationStateChange
  • renderError
  • renderLoading
  • source
  • startInLoadingState
  • style
  • url (deprecated)
  • bounces
  • onShouldStartLoadWithRequest
  • pagingEnabled
  • scrollEnabled

Unsupported props are:

  • mediaPlaybackRequiresUserAction
  • scalesPageToFit
  • domStorageEnabled
  • javaScriptEnabled
  • allowsInlineMediaPlayback
  • decelerationRate

If you look at the source, the JavaScript side is mostly derived from React Native's WebView. The Objective C side mostly deals with the API difference between UIWebView and WKWebView.

Contribute

We battle test this component against our app. However, we haven't use all the props so if something does not work as expected, please open an issue or PR.