Skip to content

Commit a517aaa

Browse files
committed
Merge commit '118663287acec269203c3850891cf145dc12f06e' into shirakaba/updatable-user-scripts
* commit '118663287acec269203c3850891cf145dc12f06e': chore(release): 8.1.1 [skip ci] fix(Android): Don't show camera options for a file upload when they can not be used (react-native-webview#1210) chore(docs): Fix Getting Started Guide link in Breaking History (react-native-webview#1213) chore(docs): Update Android assets path (react-native-webview#1173) chore(docs): Update cookie links (react-native-webview#1149) chore(Android): Convert RNCWebViewPackage to Kotlin (react-native-webview#1194) chore(release): 8.1.0 [skip ci] feat(macOS): macOS Support (react-native-webview#1164) chore(release): 8.0.6 [skip ci] fix(Android): Revert "Redirected URLs now redirect correctly. (react-native-webview#991)" (react-native-webview#1177) chore(release): 8.0.5 [skip ci] fix(Android): Redirected URLs now redirect correctly. (react-native-webview#991) chore(example): Added three test examples: Alerts, Scrolling, and Background. chore(release): 8.0.4 [skip ci] fix(iOS): Meta method 'UIScrollViewContentInsetAdjustmentBehavior:' conflict warning chore(example): Added example app chore(iOS): Extract wkWebViewConfig setup to setUpWkWebViewConfig function chore(release): 8.0.3 [skip ci] fix(whitelisted origins): Prevent handling of un-whitelisted URLs chore(README): Lean Core badge # Conflicts: # ios/RNCWebView.m
2 parents 14de90b + 1186632 commit a517aaa

File tree

101 files changed

+8144
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+8144
-238
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
55
[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
66
[![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)
7-
<a href="https://www.npmjs.com/package/react-native-webview"><img src="https://img.shields.io/npm/v/react-native-webview.svg"></a>
7+
[![NPM Version](https://img.shields.io/npm/v/react-native-webview.svg?style=flat-square)](https://www.npmjs.com/package/react-native-webview)
8+
[![Lean Core Extracted](https://img.shields.io/badge/Lean%20Core-Extracted-brightgreen.svg?style=flat-square)][lean-core-issue]
89

910
**React Native WebView** is a modern, well-supported, and cross-platform WebView for React Native. It is intended to be a replacement for the built-in WebView (which will be [removed from core](https://github.com/react-native-community/discussions-and-proposals/pull/3)).
1011

@@ -19,6 +20,7 @@ _This project is maintained for free by these people using both their free time
1920

2021
- [x] iOS
2122
- [x] Android
23+
- [x] macOS
2224

2325
_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)._
2426

@@ -101,3 +103,5 @@ MIT
101103
This readme is available in:
102104

103105
- [Brazilian portuguese](docs/README.portuguese.md)
106+
107+
[lean-core-issue]: https://github.com/facebook/react-native/issues/23313

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
123123

124124
dependencies {
125125
//noinspection GradleDynamicVersion
126-
api 'com.facebook.react:react-native:+'
126+
implementation 'com.facebook.react:react-native:+'
127127
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
128128
}

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.io.File;
3333
import java.io.IOException;
3434
import java.util.ArrayList;
35+
import java.util.Arrays;
3536

3637
import static android.app.Activity.RESULT_OK;
3738

@@ -180,11 +181,13 @@ public boolean startPhotoPickerIntent(final ValueCallback<Uri[]> callback, final
180181
filePathCallback = callback;
181182

182183
ArrayList<Parcelable> extraIntents = new ArrayList<>();
183-
if (acceptsImages(acceptTypes)) {
184-
extraIntents.add(getPhotoIntent());
185-
}
186-
if (acceptsVideo(acceptTypes)) {
187-
extraIntents.add(getVideoIntent());
184+
if (! needsCameraPermission()) {
185+
if (acceptsImages(acceptTypes)) {
186+
extraIntents.add(getPhotoIntent());
187+
}
188+
if (acceptsVideo(acceptTypes)) {
189+
extraIntents.add(getVideoIntent());
190+
}
188191
}
189192

190193
Intent fileSelectionIntent = getFileChooserIntent(acceptTypes, allowMultiple);
@@ -233,6 +236,23 @@ public boolean grantFileDownloaderPermissions() {
233236
return result;
234237
}
235238

239+
protected boolean needsCameraPermission() {
240+
boolean needed = false;
241+
242+
PackageManager packageManager = getCurrentActivity().getPackageManager();
243+
try {
244+
String[] requestedPermissions = packageManager.getPackageInfo(getReactApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS).requestedPermissions;
245+
if (Arrays.asList(requestedPermissions).contains(Manifest.permission.CAMERA)
246+
&& ContextCompat.checkSelfPermission(getCurrentActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
247+
needed = true;
248+
}
249+
} catch (PackageManager.NameNotFoundException e) {
250+
needed = true;
251+
}
252+
253+
return needed;
254+
}
255+
236256
private Intent getPhotoIntent() {
237257
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
238258
outputFileUri = getOutputUri(MediaStore.ACTION_IMAGE_CAPTURE);

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.java

-27
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.reactnativecommunity.webview
2+
3+
import com.facebook.react.ReactPackage
4+
import com.facebook.react.bridge.ReactApplicationContext
5+
6+
7+
class RNCWebViewPackage: ReactPackage {
8+
override fun createNativeModules(reactContext: ReactApplicationContext) = listOf(
9+
RNCWebViewModule(reactContext)
10+
)
11+
12+
override fun createViewManagers(reactContext: ReactApplicationContext) = listOf(
13+
RNCWebViewManager()
14+
)
15+
}

babel.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ module.exports = function(api) {
66
presets: ['module:metro-react-native-babel-preset'],
77
},
88
},
9+
presets: ['module:metro-react-native-babel-preset'],
910
};
1011
};

docs/Contributing.md

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,44 @@ Secondly, we'd like the contribution experience to be as good as possible. While
88

99
After you fork the repo, clone it to your machine, and make your changes, you'll want to test them in an app.
1010

11+
There are two methods of testing:
12+
1) Testing within a clone of react-native-webview
13+
2) Testing in a new `react-native init` project
14+
15+
### Testing within react-native-webview
16+
17+
#### For all platforms:
18+
```
19+
$ yarn install
20+
```
21+
22+
#### For Android:
23+
```
24+
$ yarn start:android
25+
```
26+
27+
The Android example app will built, the Metro Bundler will launch, and the example app will be installed and started in the Android emulator.
28+
29+
#### For iOS:
30+
```
31+
$ cd example/ios
32+
$ pod install
33+
$ cd ../..
34+
$ yarn start:ios
35+
```
36+
37+
The iOS example app will be built, the Metro bundler will launch, and the example app will be install and started in the Simulator.
38+
39+
#### for macOS:
40+
```
41+
$ open example/macos/example.xcodeproj
42+
$ yarn start:macos
43+
```
44+
45+
The Metro Bundler will now be running in the Terminal for react-native-macos. In XCode select the `example-macos` target and Run.
46+
47+
### Testing in a new `react-native init` project
48+
1149
In a new `react-native init` project, do this:
1250

1351
```

docs/Getting-Started.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Here's how to get started quickly with the React Native WebView.
44

5-
#### 1. Add react-native-webview to your dependencies
5+
## 1. Add react-native-webview to your dependencies
66

77
```
88
$ yarn add react-native-webview
@@ -14,7 +14,7 @@ $ yarn add react-native-webview
1414
$ npm install --save react-native-webview
1515
```
1616

17-
#### 2. Link native dependencies
17+
## 2. Link native dependencies
1818

1919
From react-native 0.60 autolinking will take care of the link step but don't forget to run `pod install`
2020

@@ -24,13 +24,20 @@ React Native modules that include native Objective-C, Swift, Java, or Kotlin cod
2424
$ react-native link react-native-webview
2525
```
2626

27-
iOS:
27+
_NOTE: If you ever need to uninstall React Native WebView, run `react-native unlink react-native-webview` to unlink it._
28+
29+
### iOS:
2830

2931
If using cocoapods in the `ios/` directory run
3032
```
3133
$ pod install
3234
```
3335

36+
For iOS, while you can manually link the old way using [react-native own tutorial](https://facebook.github.io/react-native/docs/linking-libraries-ios), we find it easier to use cocoapods.
37+
If you wish to use cocoapods and haven't set it up yet, please instead refer to [that article](https://engineering.brigad.co/demystifying-react-native-modules-linking-ae6c017a6b4a).
38+
39+
### Android:
40+
3441
Android - react-native-webview version <6:
3542
This module does not require any extra step after running the link command 🎉
3643

@@ -44,12 +51,13 @@ android.enableJetifier=true
4451

4552
For Android manual installation, please refer to [this article](https://engineering.brigad.co/demystifying-react-native-modules-linking-964399ec731b) where you can find detailed step on how to link any react-native project.
4653

47-
For iOS, while you can manually link the old way using [react-native own tutorial](https://facebook.github.io/react-native/docs/linking-libraries-ios), we find it easier to use cocoapods.
48-
If you wish to use cocoapods and haven't set it up yet, please instead refer to [that article](https://engineering.brigad.co/demystifying-react-native-modules-linking-ae6c017a6b4a).
54+
### macOS:
4955

50-
_NOTE: If you ever need to uninstall React Native WebView, run `react-native unlink react-native-webview` to unlink it._
56+
Cocoapod and autolinking is not yet support for react-native macOS but is coming soon. In the meantime you must manually link.
57+
58+
The method is nearly identical to the [manual linking method for iOS](https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking) except that you will include the `node_modules/react-native-webview/macos/RNCWebView.xcodeproj` project in your main project and link the `RNCWebView-macOS.a` library.
5159

52-
#### 3. Import the webview into your component
60+
## 3. Import the webview into your component
5361

5462
```js
5563
import React, { Component } from 'react';

docs/Guide.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class MyWeb extends Component {
7474
}
7575
```
7676

77-
However on Android, you need to place the HTML file inside your android project's asset directory. For example, if `local-site.html` is your HTML file and you'd like to load it into the webview, you should move the file to your project's android asset directory which is `your-project/android/src/main/assets/`. Then you can load the html file as shown in the following code block
77+
However on Android, you need to place the HTML file inside your android project's asset directory. For example, if `local-site.html` is your HTML file and you'd like to load it into the webview, you should move the file to your project's android asset directory which is `your-project/android/app/src/main/assets/`. Then you can load the html file as shown in the following code block
7878

7979
```js
8080
import React, { Component } from 'react';
@@ -191,6 +191,12 @@ Add permission in AndroidManifest.xml:
191191
</manifest>
192192
```
193193

194+
###### Camera option availability in uploading for Android
195+
196+
If the file input indicates that images or video is desired with [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept), then the WebView will attempt to provide options to the user to use their camera to take a picture or video.
197+
198+
Normally, apps that do not have permission to use the camera can prompt the user to use an external app so that the requesting app has no need for permission. However, Android has made a special exception for this around the camera to reduce confusion for users. If an app *can* request the camera permission because it has been declared, and the user has not granted the permission, it may not fire an intent that would use the camera (`MediaStore.ACTION_IMAGE_CAPTURE` or `MediaStore.ACTION_VIDEO_CAPTURE`). In this scenario, it is up to the developer to request camera permission before a file upload directly using the camera is necessary.
199+
194200
##### Check for File Upload support, with `static isFileUploadSupported()`
195201

196202
File Upload using `<input type="file" />` is not supported for Android 4.4 KitKat (see [details](https://github.com/delight-im/Android-AdvancedWebView/issues/4#issuecomment-70372146)):
@@ -301,7 +307,7 @@ _Under the hood_
301307

302308
#### The `injectedJavaScriptBeforeContentLoaded` prop
303309

304-
This is a script that runs **before** the web page loads for the first time. It only runs once, even if the page is reloaded or navigated away. This is useful if you want to inject anything into the window, localstorage, or document prior to the web code executing.
310+
This is a script that runs **before** the web page loads for the first time. It only runs once, even if the page is reloaded or navigated away. This is useful if you want to inject anything into the window, localstorage, or document prior to the web code executing.
305311

306312
```jsx
307313
import React, { Component } from 'react';
@@ -329,7 +335,7 @@ export default class App extends Component {
329335
}
330336
```
331337

332-
This runs the JavaScript in the `runFirst` string before the page is loaded. In this case, the value of `window.isNativeApp` will be set to true before the web code executes.
338+
This runs the JavaScript in the `runFirst` string before the page is loaded. In this case, the value of `window.isNativeApp` will be set to true before the web code executes.
333339

334340
#### The `injectJavaScript` method
335341

@@ -475,7 +481,7 @@ const CustomHeaderWebView = props => {
475481

476482
#### Managing Cookies
477483

478-
You can set cookies on the React Native side using the [react-native-cookies](https://github.com/joeferraro/react-native-cookies) package.
484+
You can set cookies on the React Native side using the [@react-native-community/cookies](https://github.com/react-native-community/cookies) package.
479485

480486
When you do, you'll likely want to enable the [sharedCookiesEnabled](Reference#sharedCookiesEnabled) prop as well.
481487

docs/README.portuguese.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Versão atual: ![version](https://img.shields.io/npm/v/react-native-webview.svg)
3636

3737
- [7.0.1](https://github.com/react-native-community/react-native-webview/releases/tag/v7.0.1) - UIWebView removido
3838

39-
- [6.0.**2**](https://github.com/react-native-community/react-native-webview/releases/tag/v6.0.2) - Update para AndroidX. Tenha certeza de habilitar no `android/gradle.properties` do seu projeto. Veja o [Getting Started Guide](docs/Getting-Started.md).
39+
- [6.0.**2**](https://github.com/react-native-community/react-native-webview/releases/tag/v6.0.2) - Update para AndroidX. Tenha certeza de habilitar no `android/gradle.properties` do seu projeto. Veja o [Getting Started Guide](https://github.com/react-native-community/react-native-webview/blob/master/docs/Getting-Started.md).
4040

4141
- [5.0.**1**](https://github.com/react-native-community/react-native-webview/releases/tag/v5.0.0) - Refatorou a antiga implementação postMessage para comunicação da visualização da webview para nativa.
4242
- [4.0.0](https://github.com/react-native-community/react-native-webview/releases/tag/v4.0.0) - Cache adicionada(habilitada por padrão).

docs/Reference.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ Note that this method will not be invoked on hash URL changes (e.g. from `https:
500500

501501
Function that is invoked when the `WebView` content process is terminated.
502502

503-
| Type | Required | Platform |
504-
| -------- | -------- | ------------- |
505-
| function | No | iOS WKWebView |
503+
| Type | Required | Platform |
504+
| -------- | -------- | ----------------------- |
505+
| function | No | iOS and macOS WKWebView |
506506

507507
Example:
508508

@@ -889,9 +889,9 @@ Possible values for `dataDetectorTypes` are:
889889

890890
Boolean value that determines whether scrolling is enabled in the `WebView`. The default value is `true`. Setting this to `false` will prevent the webview from moving the document body when the keyboard appears over an input.
891891

892-
| Type | Required | Platform |
893-
| ---- | -------- | -------- |
894-
| bool | No | iOS |
892+
| Type | Required | Platform |
893+
| ---- | -------- | ------------- |
894+
| bool | No | iOS and macOS |
895895

896896
---
897897

@@ -960,9 +960,9 @@ Boolean that sets whether JavaScript running in the context of a file scheme URL
960960

961961
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.
962962

963-
| Type | Required | Platform |
964-
| ------ | -------- | -------- |
965-
| string | No | iOS |
963+
| Type | Required | Platform |
964+
| ------ | -------- | ------------- |
965+
| string | No | iOS and macOS |
966966

967967
---
968968

@@ -1010,9 +1010,9 @@ If true, this will hide the keyboard accessory view (< > and Done).
10101010

10111011
If true, this will be able horizontal swipe gestures. The default value is `false`.
10121012

1013-
| Type | Required | Platform |
1014-
| ------- | -------- | -------- |
1015-
| boolean | No | iOS |
1013+
| Type | Required | Platform |
1014+
| ------- | -------- | ----------------- |
1015+
| boolean | No | iOS and macOS |
10161016

10171017
---
10181018

@@ -1087,19 +1087,19 @@ If the value of this property is true, the scroll view stops on multiples of the
10871087

10881088
A Boolean value that determines whether pressing on a link displays a preview of the destination for the link. In iOS this property 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.
10891089

1090-
| Type | Required | Platform |
1091-
| ------- | -------- | -------- |
1092-
| boolean | No | iOS |
1090+
| Type | Required | Platform |
1091+
| ------- | -------- | ----------------- |
1092+
| boolean | No | iOS and macOS |
10931093

10941094
---
10951095

10961096
### `sharedCookiesEnabled`
10971097

10981098
Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the WebView. The default value is `false`. For more on cookies, read the [Guide](Guide.md#Managing-Cookies)
10991099

1100-
| Type | Required | Platform |
1101-
| ------- | -------- | -------- |
1102-
| boolean | No | iOS |
1100+
| Type | Required | Platform |
1101+
| ------- | -------- | ----------------- |
1102+
| boolean | No | iOS and macOS |
11031103

11041104
---
11051105

example/.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

0 commit comments

Comments
 (0)