All Projects → CRAlpha → React Native Wkwebview

CRAlpha / React Native Wkwebview

Licence: mit
WKWebview Component for React Native

Projects that are alternatives of or similar to React Native Wkwebview

Flutter browser app
A Full-Featured Mobile Browser App (such as the Google Chrome mobile browser) created using Flutter and the features offered by the flutter_inappwebview plugin.
Stars: ✭ 85 (-86.33%)
Mutual labels:  webview, wkwebview
Jxbwkwebview
An component WebView for iOS base on WKWebView
Stars: ✭ 646 (+3.86%)
Mutual labels:  webview, wkwebview
QuickWebKit
A great & strong plugin based WebViewController. 一款基于插件的 WebView 视图控制器,您可以基于它设计您的浏览器插件,然后像积木一样来组装它们。
Stars: ✭ 29 (-95.34%)
Mutual labels:  webview, wkwebview
Flutter inappwebview
A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
Stars: ✭ 1,259 (+102.41%)
Mutual labels:  webview, wkwebview
Mybrowser
我的浏览器,基于WKWebView实现的一个iOS浏览器,实现了无图模式、广告拦截、多窗口、扫描二维码、收藏夹/历史、无痕浏览、夜间模式等功能...
Stars: ✭ 127 (-79.58%)
Mutual labels:  webview, wkwebview
Lcwebview
www.strictfrog.com
Stars: ✭ 144 (-76.85%)
Mutual labels:  webview, wkwebview
VHLWebView
微信/支付宝样式的网络浏览器控件。WKwebview 封装,js bridge和拦截url方式两种方法实现 oc和js交互
Stars: ✭ 14 (-97.75%)
Mutual labels:  webview, wkwebview
Electron Tabs
Simple tabs for Electron applications
Stars: ✭ 350 (-43.73%)
Mutual labels:  webview
Cordova Plugin Ionic Webview
Web View plugin for Cordova, specialized for Ionic apps.
Stars: ✭ 419 (-32.64%)
Mutual labels:  webview
Aachartcore Kotlin
📈📊⛰⛰⛰An elegant modern declarative data visualization chart framework for Android . Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
Stars: ✭ 332 (-46.62%)
Mutual labels:  webview
Injuredandroid
A vulnerable Android application that shows simple examples of vulnerabilities in a ctf style.
Stars: ✭ 317 (-49.04%)
Mutual labels:  webview
Android Smartwebview
A webview integrated w/ native features to help create most advanced hybrid applications.
Stars: ✭ 357 (-42.6%)
Mutual labels:  webview
Aachartcore
📈📊☕️☕️☕️An elegant modern declarative data visualization chart framework for Android. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types.极其精美而又强大的 Android 数据可视化图表框架,支持柱状图、条形图、折线图、曲线图、折线填充图、曲线填充图、气泡图、扇形图、环形图、散点图、雷达图、混合图等各种类型的多达几十种的信息图图表,完全满足工作所需.
Stars: ✭ 424 (-31.83%)
Mutual labels:  webview
Customactionwebview
自定义webview长按文本弹出选项,并且点击后返回选项与所选中的文本,你的webview不再只支持系统的复制等功能了,长按web文本实现文本一键收藏、分享,就是这么简单。Demo中附带对webView的详细使用:api详解,配置详解,js多种通信方式详解。
Stars: ✭ 338 (-45.66%)
Mutual labels:  webview
Kkjsbridge
一站式解决 WKWebView 支持离线包,Ajax/Fetch 请求,表单请求和 Cookie 同步的问题 (基于 Ajax Hook,Fetch Hook 和 Cookie Hook)
Stars: ✭ 462 (-25.72%)
Mutual labels:  wkwebview
Androidfastscroll
Fast scroll for Android RecyclerView and more
Stars: ✭ 316 (-49.2%)
Mutual labels:  webview
Android Reports And Resources
A big list of Android Hackerone disclosed reports and other resources.
Stars: ✭ 590 (-5.14%)
Mutual labels:  webview
Aachartkit
📈📊🚀🚀🚀An elegant modern declarative data visualization chart framework for iOS, iPadOS and macOS. Extremely powerful, supports line, spline, area, areaspline, column, bar, pie, scatter, angular gauges, arearange, areasplinerange, columnrange, bubble, box plot, error bars, funnel, waterfall and polar chart types. 极其精美而又强大的跨平台数据可视化图表框架,支持柱状图、条形图、折…
Stars: ✭ 4,358 (+600.64%)
Mutual labels:  webview
React Native Autoheight Webview
An auto height webview for React Native
Stars: ✭ 385 (-38.1%)
Mutual labels:  webview
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (-39.87%)
Mutual labels:  webview

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 (which is React Native's current minimum deployment target anyway).

Install

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

Manual alternative

  1. Install from npm (note the postfix in the package name): npm install 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-reborn ➜ ios ➜ select RCTWKWebView.xcodeproj
  4. Go your build target ➜ Build Phases ➜ Link Binary With Libraries, click "+" and select libRCTWkWebView.a (see the following screenshot for reference) Linking
  5. Compile and profit (Remember to set Minimum Deployment Target = 8.0)

Usage

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

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

For React Native >= 0.57, use version 2.x; for React Native < 0.40, use version 0.x.

Compatibility with UIWebView

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

Since 1.14.0, WkWebView supports onMessage and postMessage as in the default WebView. You can refer to the React Native documentation or the example project. For advanced or customized usage, please refer to Advanced Communication between React Native and WkWebView.

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.

  • onNavigationResponse

A callback to get response headers, http status code and http localized status code.

  • openNewWindowInWebView

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. You can set cookies using react-native-cookies Default is false.

  • 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 }} />

You can also use the require syntax (sendCookies and userAgent will be ignored)

<WKWebView source={require('./index.html')} />
  • userAgent="MyUserAgent" (or customUserAgent="...")

Set a custom user agent for WKWebView. Note this only works on iOS 9+. Previous version will simply ignore this props.

  • hideKeyboardAccessoryView

This will hide the keyboard accessory view (< > and Done). Default is false.

  • allowsLinkPreview

A Boolean value that determines whether pressing on a link displays a preview of the destination for the link. This props is available on devices that support 3D Touch. In iOS 10 and later, the default value is true; before that, the default value is false.

  • contentInsetAdjustmentBehavior

This property specifies how the safe area insets are used to modify the content area of the scroll view. The default value of this property is "never". Available on iOS 11 and later. Possible values are "automatic", "scrollableAxes", "never", "always". New in 1.16.0

  • keyboardDisplayRequiresUserAction

Enables focusing an input inside a webview and showing the keyboard programatically. New in 1.20.0

  • keyboardDismissMode

Sets the manner in which the keyboard is dismissed when a drag begins in the scroll view. Possible values are "none", "on-drag" and "interactive". Default to "none".

  • injectJavaScript, injectJavaScriptForMainFrameOnly

Add JavaScript at document start, see WKUserScriptInjectionTimeAtDocumentStart. New in 1.20.0

  • injectedJavaScript, injectedJavaScriptForMainFrameOnly

Add JavaScript at document end. Since 1.20.0, the implementation has been changed to use WKUserScript.

  • allowsBackForwardNavigationGestures

Enable horizontal swipe gestures will trigger back-forward navigations. Derived from allowsBackForwardNavigationGestures property.

Currently supported props are:

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

Unsupported props are:

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

Advanced Communication between React Native and WkWebView

Communication from WKWebview to React Native

  • 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({message: 'hello!'});

or (since 1.14.0)

window.postMessage({message: 'hello!'});

Then you can access the nativeEvent in React Native using the event object returned

e.nativeEvent => {
  name: 'reactNative',
  data: {
    message: '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.

Communication from React Native to WkWebView

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={ref => { this.webview = ref; }} />
this.webview.evaluateJavaScript('receivedMessageFromReactNative("Hello from the other side.")');

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].