Skip to content

Commit

Permalink
fix(iOS): UIWebView Removal (react-native-webview#828)
Browse files Browse the repository at this point in the history
Apple required us to remove this (see react-native-webview#819)

BREAKING CHANGE: UIWebView has been removed
BREAKING CHANGE: useWebkit prop removal
BREAKING CHANGE: scalesPageToFit prop removal on iOS (since it's not compatible with WKWebview)
BREAKING CHANGE: Renamed RNCWKWebView to RNCWebView on iOS
  • Loading branch information
Titozzz authored Aug 30, 2019
1 parent 3517d2d commit 8549be5
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 815 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# React Native WebView - a Modern, Cross-Platform WebView for React Native

[![star this repo](http://githubbadges.com/star.svg?user=react-native-community&repo=react-native-webview&style=flat)](https://github.com/react-native-community/react-native-webview)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
[![star this repo](http://githubbadges.com/star.svg?user=react-native-community&repo=react-native-webview&style=flat)](https://github.com/react-native-community/react-native-webview)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
[![Known Vulnerabilities](https://snyk.io/test/github/react-native-community/react-native-webview/badge.svg?style=flat-square)](https://snyk.io/test/github/react-native-community/react-native-webview)
<a href="https://www.npmjs.com/package/react-native-webview"><img src="https://img.shields.io/npm/v/react-native-webview.svg"></a>

Expand All @@ -17,7 +17,7 @@ _This project is maintained for free by these people using both their free time

## Platforms Supported

- [x] iOS (both UIWebView and WKWebView)
- [x] iOS
- [x] Android

_Note: Expo support for React Native WebView started with [Expo SDK v33.0.0](https://blog.expo.io/expo-sdk-v33-0-0-is-now-available-52d1c99dfe4c)._
Expand All @@ -34,18 +34,17 @@ This project follows [semantic versioning](https://semver.org/). We do not hesit

Current Version: ![version](https://img.shields.io/npm/v/react-native-webview.svg)

yarn add react-native-webview@androidx
- [7.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v7.0.0 - Removed UIWebView

- [6.0.**2**](https://github.com/react-native-community/react-native-webview/releases/tag/v6.0.2) - Update to AndroidX. Make sure to enable it in your project's `android/gradle.properties`. See [Getting Started Guide](docs/Getting-Started.md).

yarn add react-native-webview
- [5.0.**1**](https://github.com/react-native-community/react-native-webview/releases/tag/v5.0.0) - Refactored the old postMessage implementation for communication from webview to native.
- [4.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v4.0.0) - Added cache (enabled by default).
- [3.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v3.0.0) - WKWebview: Add shared process pool so cookies and localStorage are shared across webviews in iOS (enabled by default).
- [2.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v2.0.0) - First release this is a replica of the core webview component

**Upcoming:**

- UIWebView removal
- this.webView.postMessage() removal (never documented and less flexible than injectJavascript)
- Kotlin rewrite
- Maybe Swift rewrite
Expand Down Expand Up @@ -73,7 +72,7 @@ For more, read the [API Reference](./docs/Reference.md) and [Guide](./docs/Guide

## Common issues

- If you're getting `Invariant Violation: Native component for "RNCWKWebView does not exist"` it likely means you forgot to run `react-native link` or there was some error with the linking process
- If you're getting `Invariant Violation: Native component for "RNCWebView does not exist"` it likely means you forgot to run `react-native link` or there was some error with the linking process

## Contributing

Expand Down
1 change: 0 additions & 1 deletion docs/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ $ yarn add ../react-native-webview && react-native link react-native-webview
## Notes

- We use TypeScript.
- We don't intend to support UIWebView and will remove it soon.
- After pulling this repo and installing all dependencies, you can run tests using the command: `yarn ci`
2 changes: 1 addition & 1 deletion docs/Custom-iOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Once these are exposed, you can reference them in your custom web view class.
If you open webpages that needs a Client Certificate for Authentication, you can create a credential and pass it to the webview:

```
[RNCWKWebView setClientAuthenticationCredential:credential];
[RNCWebView setClientAuthenticationCredential:credential];
```

This can be paired with a call from Javascript to pass a string label for the certificate stored in keychain and use native calls to fetch the certificate to create a credential object. This call can be made anywhere that makes sense for your application (e.g. as part of the user authentication stack). The only requirement is to make this call before displaying any webviews.
Expand Down
4 changes: 2 additions & 2 deletions docs/Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ This runs the JavaScript in the `runFirst` string once the page is loaded. In th

_Under the hood_

> On iOS, `injectedJavaScript` runs a method on WKWebView called `evaluateJavaScript:completionHandler:`
> On iOS, `injectedJavaScript` runs a method on WebView called `evaluateJavaScript:completionHandler:`
> On Android, `injectedJavaScript` runs a method on the Android WebView called `evaluateJavascriptWithFallback`
#### The `injectJavaScript` method
Expand Down Expand Up @@ -341,7 +341,7 @@ After 3 seconds, this code turns the background blue:

_Under the hood_

> On iOS, `injectJavaScript` calls WKWebView's `evaluateJS:andThen:`
> On iOS, `injectJavaScript` calls WebView's `evaluateJS:andThen:`
> On Android, `injectJavaScript` calls Android WebView's `evaluateJavascriptWithFallback` method
#### The `window.ReactNativeWebView.postMessage` method and `onMessage` prop
Expand Down
67 changes: 25 additions & 42 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ This document lays out the current public properties and methods for the React N
- [`geolocationEnabled`](Reference.md#geolocationenabled)
- [`allowUniversalAccessFromFileURLs`](Reference.md#allowUniversalAccessFromFileURLs)
- [`allowingReadAccessToURL`](Reference.md#allowingReadAccessToURL)
- [`useWebKit`](Reference.md#usewebkit)
- [`url`](Reference.md#url)
- [`html`](Reference.md#html)
- [`keyboardDisplayRequiresUserAction`](Reference.md#keyboardDisplayRequiresUserAction)
Expand Down Expand Up @@ -132,7 +131,7 @@ const INJECTED_JAVASCRIPT = `(function() {
source={{ uri: 'https://facebook.github.io/react-native' }}
injectedJavaScript={INJECTED_JAVASCRIPT}
onMessage={this.onMessage}
/>
/>;
```

---
Expand Down Expand Up @@ -312,7 +311,6 @@ Function that is invoked when the `WebView` is loading.

> **_Note_**
>
> On iOS, when useWebKit=false, this prop will not work.
> On android, You can't get the url property, meaning that `event.nativeEvent.url` will be null.
| Type | Required |
Expand Down Expand Up @@ -459,11 +457,9 @@ Example:

Boolean that controls whether the web content is scaled to fit the view and enables the user to change the scale. The default value is `true`.

On iOS, when [`useWebKit=true`](Reference.md#usewebkit), this prop will not work.

| Type | Required |
| ---- | -------- |
| bool | No |
| Type | Required | Platform |
| ---- | -------- | -------- |
| bool | No | Android |

---

Expand Down Expand Up @@ -605,26 +601,26 @@ Boolean value to enable third party cookies in the `WebView`. Used on Android Lo

### `userAgent`

Sets the user-agent for the `WebView`. This will only work for iOS if you are using WKWebView, not UIWebView (see https://developer.apple.com/documentation/webkit/wkwebview/1414950-customuseragent).
Sets the user-agent for the `WebView`.

| Type | Required | Platform |
| ------ | -------- | ---------------------- |
| string | No | Android, iOS WKWebView |
| Type | Required |
| ------ | -------- |
| string | No |

---

### `applicationNameForUserAgent`

Append to the existing user-agent. This will only work for iOS if you are using WKWebView, not UIWebView. Setting `userAgent` will override this.
Append to the existing user-agent. Setting `userAgent` will override this.

| Type | Required | Platform |
| ------ | -------- | ------------- |
| string | No | Android, iOS WKWebView |
| Type | Required |
| ------ | -------- |
| string | No |

```jsx
<WebView
source={{ uri: 'https://facebook.github.io/react-native' }}
applicationNameForUserAgent={"DemoApp/1.1.0"}
applicationNameForUserAgent={'DemoApp/1.1.0'}
/>
// Resulting User-Agent will look like:
// Mozilla/5.0 (Linux; Android 8.1.0; Android SDK built for x86 Build/OSM1.180201.021; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36 DemoApp/1.1.0
Expand Down Expand Up @@ -722,9 +718,6 @@ Possible values for `dataDetectorTypes` are:
- `calendarEvent`
- `none`
- `all`

With the [new WebKit](Reference.md#usewebkit) implementation, we have three new values:

- `trackingNumber`
- `flightNumber`
- `lookupSuggestion`
Expand Down Expand Up @@ -798,21 +791,11 @@ Boolean that sets whether JavaScript running in the context of a file scheme URL

### `allowingReadAccessToURL`

A String value that indicates which URLs the WebView's file can then reference in scripts, AJAX requests, and CSS imports. This is only used in `RNCWKWebView` for WebViews that are loaded with a source.uri set to a `'file://'` URL. If not provided, the default is to only allow read access to the URL provided in source.uri itself.

| Type | Required | Platform |
| ------ | -------- | ------------- |
| string | No | iOS WKWebView |

---

### `useWebKit`

If true, use WKWebView instead of UIWebView.
A String value that indicates which URLs the WebView's file can then reference in scripts, AJAX requests, and CSS imports. This is only used in for WebViews that are loaded with a source.uri set to a `'file://'` URL. If not provided, the default is to only allow read access to the URL provided in source.uri itself.

| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |
| Type | Required | Platform |
| ------ | -------- | -------- |
| string | No | iOS |

---

Expand All @@ -838,7 +821,7 @@ If true, use WKWebView instead of UIWebView.

### `keyboardDisplayRequiresUserAction`

If false, web content can programmatically display the keyboard when using the WKWebView. The default value is `true`.
If false, web content can programmatically display the keyboard. The default value is `true`.

| Type | Required | Platform |
| ------- | -------- | -------- |
Expand All @@ -848,7 +831,7 @@ If false, web content can programmatically display the keyboard when using the W

### `hideKeyboardAccessoryView`

If true, this will hide the keyboard accessory view (< > and Done) when using the WKWebView.
If true, this will hide the keyboard accessory view (< > and Done).

| Type | Required | Platform |
| ------- | -------- | -------- |
Expand All @@ -858,7 +841,7 @@ If true, this will hide the keyboard accessory view (< > and Done) when using th

### `allowsBackForwardNavigationGestures`

If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
If true, this will be able horizontal swipe gestures. The default value is `false`.

| Type | Required | Platform |
| ------- | -------- | -------- |
Expand All @@ -870,9 +853,9 @@ If true, this will be able horizontal swipe gestures when using the WKWebView. T

Does not store any data within the lifetime of the WebView.

| Type | Required | Platform |
| ------- | -------- | ---------------------- |
| boolean | No | Android, iOS WKWebView |
| Type | Required |
| ------- | -------- |
| boolean | No |

---

Expand All @@ -898,7 +881,7 @@ Sets whether the WebView should disable saving form data. The default value is `

### `cacheEnabled`

Sets whether WebView & WKWebView should use browser caching.
Sets whether WebView should use browser caching.

| Type | Required | Default |
| ------- | -------- | ------- |
Expand Down Expand Up @@ -928,7 +911,7 @@ A Boolean value that determines whether pressing on a link displays a preview of

### `sharedCookiesEnabled`

Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the `RNCWKWebView`. The default value is `false`.
Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the WebView. The default value is `false`.

| Type | Required | Platform |
| ------- | -------- | -------- |
Expand Down
39 changes: 0 additions & 39 deletions ios/RNCUIWebView.h

This file was deleted.

Loading

0 comments on commit 8549be5

Please sign in to comment.