Browse Source

Merge branch 'master' into patch-1

Jamon Holmgren 4 years ago
parent
commit
0098ac7779
No account linked to committer's email address

+ 2
- 2
.github/workflows/detox.yml View File

13
       - name: Setup - Install Yarn
13
       - name: Setup - Install Yarn
14
         run: YARN_GPG=NO curl -o- -L https://yarnpkg.com/install.sh | bash
14
         run: YARN_GPG=NO curl -o- -L https://yarnpkg.com/install.sh | bash
15
       - name: Setup - Install NPM Dependencies
15
       - name: Setup - Install NPM Dependencies
16
-        run: yarn
16
+        run: yarn --frozen-lockfile
17
       - name: Setup - Install CocoaPods CLI
17
       - name: Setup - Install CocoaPods CLI
18
-        run: sudo gem install cocoapods
18
+        run: sudo gem install cocoapods -v 1.8.4
19
       - name: Run tests
19
       - name: Run tests
20
         run: yarn ci
20
         run: yarn ci

+ 6
- 0
README.md View File

93
 ## License
93
 ## License
94
 
94
 
95
 MIT
95
 MIT
96
+
97
+## Traduções
98
+
99
+This readme is available in:
100
+
101
+- [Brazilian portuguese](docs/README.portuguese.md)

+ 1
- 1
android/gradle.properties View File

1
-ReactNativeWebView_kotlinVersion=1.3.11
1
+ReactNativeWebView_kotlinVersion=1.3.50
2
 ReactNativeWebView_compileSdkVersion=28
2
 ReactNativeWebView_compileSdkVersion=28
3
 ReactNativeWebView_buildToolsVersion=28.0.3
3
 ReactNativeWebView_buildToolsVersion=28.0.3
4
 ReactNativeWebView_targetSdkVersion=28
4
 ReactNativeWebView_targetSdkVersion=28

+ 45
- 20
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

115
   public static final int COMMAND_INJECT_JAVASCRIPT = 6;
115
   public static final int COMMAND_INJECT_JAVASCRIPT = 6;
116
   public static final int COMMAND_LOAD_URL = 7;
116
   public static final int COMMAND_LOAD_URL = 7;
117
   public static final int COMMAND_FOCUS = 8;
117
   public static final int COMMAND_FOCUS = 8;
118
+
119
+  // android commands
120
+  public static final int COMMAND_CLEAR_FORM_DATA = 1000;
121
+  public static final int COMMAND_CLEAR_CACHE = 1001;
122
+  public static final int COMMAND_CLEAR_HISTORY = 1002;
123
+
118
   protected static final String REACT_CLASS = "RNCWebView";
124
   protected static final String REACT_CLASS = "RNCWebView";
119
   protected static final String HTML_ENCODING = "UTF-8";
125
   protected static final String HTML_ENCODING = "UTF-8";
120
   protected static final String HTML_MIME_TYPE = "text/html";
126
   protected static final String HTML_MIME_TYPE = "text/html";
266
         break;
272
         break;
267
       case "LOAD_CACHE_ELSE_NETWORK":
273
       case "LOAD_CACHE_ELSE_NETWORK":
268
         cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK;
274
         cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK;
269
-        break;  
275
+        break;
270
       case "LOAD_NO_CACHE":
276
       case "LOAD_NO_CACHE":
271
         cacheMode = WebSettings.LOAD_NO_CACHE;
277
         cacheMode = WebSettings.LOAD_NO_CACHE;
272
         break;
278
         break;
280
 
286
 
281
   @ReactProp(name = "androidHardwareAccelerationDisabled")
287
   @ReactProp(name = "androidHardwareAccelerationDisabled")
282
   public void setHardwareAccelerationDisabled(WebView view, boolean disabled) {
288
   public void setHardwareAccelerationDisabled(WebView view, boolean disabled) {
283
-    ReactContext reactContext = (ReactContext) view.getContext();
284
-    final boolean isHardwareAccelerated = (reactContext.getCurrentActivity().getWindow()
285
-        .getAttributes().flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0;
286
-    if (disabled || !isHardwareAccelerated) {
289
+    if (disabled) {
287
       view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
290
       view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
288
-    } else {
289
-      view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
290
     }
291
     }
291
   }
292
   }
292
 
293
 
550
   @Override
551
   @Override
551
   public @Nullable
552
   public @Nullable
552
   Map<String, Integer> getCommandsMap() {
553
   Map<String, Integer> getCommandsMap() {
553
-    Map map = MapBuilder.of(
554
-      "goBack", COMMAND_GO_BACK,
555
-      "goForward", COMMAND_GO_FORWARD,
556
-      "reload", COMMAND_RELOAD,
557
-      "stopLoading", COMMAND_STOP_LOADING,
558
-      "postMessage", COMMAND_POST_MESSAGE,
559
-      "injectJavaScript", COMMAND_INJECT_JAVASCRIPT,
560
-      "loadUrl", COMMAND_LOAD_URL
561
-    );
562
-    map.put("requestFocus", COMMAND_FOCUS);
563
-    return map;
554
+    return MapBuilder.<String, Integer>builder()
555
+      .put("goBack", COMMAND_GO_BACK)
556
+      .put("goForward", COMMAND_GO_FORWARD)
557
+      .put("reload", COMMAND_RELOAD)
558
+      .put("stopLoading", COMMAND_STOP_LOADING)
559
+      .put("postMessage", COMMAND_POST_MESSAGE)
560
+      .put("injectJavaScript", COMMAND_INJECT_JAVASCRIPT)
561
+      .put("loadUrl", COMMAND_LOAD_URL)
562
+      .put("requestFocus", COMMAND_FOCUS)
563
+      .put("clearFormData", COMMAND_CLEAR_FORM_DATA)
564
+      .put("clearCache", COMMAND_CLEAR_CACHE)
565
+      .put("clearHistory", COMMAND_CLEAR_HISTORY)
566
+      .build();
564
   }
567
   }
565
 
568
 
566
   @Override
569
   @Override
611
       case COMMAND_FOCUS:
614
       case COMMAND_FOCUS:
612
         root.requestFocus();
615
         root.requestFocus();
613
         break;
616
         break;
617
+      case COMMAND_CLEAR_FORM_DATA:
618
+        root.clearFormData();
619
+        break;
620
+      case COMMAND_CLEAR_CACHE:
621
+        boolean includeDiskFiles = args != null && args.getBoolean(0);
622
+        root.clearCache(includeDiskFiles);
623
+        break;
624
+      case COMMAND_CLEAR_HISTORY:
625
+        root.clearHistory();
626
+        break;
614
     }
627
     }
615
   }
628
   }
616
 
629
 
629
     if (mAllowsFullscreenVideo) {
642
     if (mAllowsFullscreenVideo) {
630
       int initialRequestedOrientation = reactContext.getCurrentActivity().getRequestedOrientation();
643
       int initialRequestedOrientation = reactContext.getCurrentActivity().getRequestedOrientation();
631
       mWebChromeClient = new RNCWebChromeClient(reactContext, webView) {
644
       mWebChromeClient = new RNCWebChromeClient(reactContext, webView) {
645
+        @Override
646
+        public Bitmap getDefaultVideoPoster() {
647
+          return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
648
+        }
649
+        
632
         @Override
650
         @Override
633
         public void onShowCustomView(View view, CustomViewCallback callback) {
651
         public void onShowCustomView(View view, CustomViewCallback callback) {
634
           if (mVideoView != null) {
652
           if (mVideoView != null) {
681
       if (mWebChromeClient != null) {
699
       if (mWebChromeClient != null) {
682
         mWebChromeClient.onHideCustomView();
700
         mWebChromeClient.onHideCustomView();
683
       }
701
       }
684
-      mWebChromeClient = new RNCWebChromeClient(reactContext, webView);
702
+      mWebChromeClient = new RNCWebChromeClient(reactContext, webView) {
703
+        @Override
704
+        public Bitmap getDefaultVideoPoster() {
705
+          return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
706
+        }
707
+      };
685
       webView.setWebChromeClient(mWebChromeClient);
708
       webView.setWebChromeClient(mWebChromeClient);
686
     }
709
     }
687
   }
710
   }
1007
     @Override
1030
     @Override
1008
     public void setWebViewClient(WebViewClient client) {
1031
     public void setWebViewClient(WebViewClient client) {
1009
       super.setWebViewClient(client);
1032
       super.setWebViewClient(client);
1010
-      mRNCWebViewClient = (RNCWebViewClient) client;
1033
+      if (client instanceof RNCWebViewClient) {
1034
+        mRNCWebViewClient = (RNCWebViewClient) client;
1035
+      }
1011
     }
1036
     }
1012
 
1037
 
1013
     public @Nullable
1038
     public @Nullable

+ 0
- 2
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java View File

242
 
242
 
243
   private Intent getVideoIntent() {
243
   private Intent getVideoIntent() {
244
     Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
244
     Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
245
-    // @todo from experience, for Videos we get the data onActivityResult
246
-    // so there's no need to store the Uri
247
     outputFileUri = getOutputUri(MediaStore.ACTION_VIDEO_CAPTURE);
245
     outputFileUri = getOutputUri(MediaStore.ACTION_VIDEO_CAPTURE);
248
     intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
246
     intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
249
     return intent;
247
     return intent;

+ 126
- 1
docs/Guide.md View File

8
 
8
 
9
 - [Basic Inline HTML](Guide.md#basic-inline-html)
9
 - [Basic Inline HTML](Guide.md#basic-inline-html)
10
 - [Basic URL Source](Guide.md#basic-url-source)
10
 - [Basic URL Source](Guide.md#basic-url-source)
11
+- [Loading local HTML files](Guide.md#loading-local-html-files)
11
 - [Controlling navigation state changes](Guide.md#controlling-navigation-state-changes)
12
 - [Controlling navigation state changes](Guide.md#controlling-navigation-state-changes)
12
 - [Add support for File Upload](Guide.md#add-support-for-file-upload)
13
 - [Add support for File Upload](Guide.md#add-support-for-file-upload)
13
 - [Multiple files upload](Guide.md#multiple-files-upload)
14
 - [Multiple files upload](Guide.md#multiple-files-upload)
14
 - [Add support for File Download](Guide.md#add-support-for-file-download)
15
 - [Add support for File Download](Guide.md#add-support-for-file-download)
15
 - [Communicating between JS and Native](Guide.md#communicating-between-js-and-native)
16
 - [Communicating between JS and Native](Guide.md#communicating-between-js-and-native)
17
+- [Working with custom headers, sessions, and cookies](Guide.md#working-with-custom-headers-sessions-and-cookies)
16
 
18
 
17
 ### Basic inline HTML
19
 ### Basic inline HTML
18
 
20
 
53
 }
55
 }
54
 ```
56
 ```
55
 
57
 
58
+### Loading local HTML files
59
+
60
+Sometimes you would have bundled an HTML file along with the app and would like to load the HTML asset into your WebView. To do this on iOS, you can just import the html file like any other asset as shown below.
61
+
62
+```js
63
+import React, { Component } from 'react';
64
+import { WebView } from 'react-native-webview';
65
+
66
+const myHtmlFile = require("./my-asset-folder/local-site.html");
67
+
68
+class MyWeb extends Component {
69
+  render() {
70
+    return (
71
+      <WebView source={myHtmlFile} />
72
+    );
73
+  }
74
+}
75
+```
76
+
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
78
+
79
+```js
80
+import React, { Component } from 'react';
81
+import { WebView } from 'react-native-webview';
82
+
83
+class MyWeb extends Component {
84
+  render() {
85
+    return (
86
+      <WebView source={{ uri: "file:///android_asset/local-site.html" }} />
87
+    );
88
+  }
89
+}
90
+```
91
+
56
 ### Controlling navigation state changes
92
 ### Controlling navigation state changes
57
 
93
 
58
 Sometimes you want to intercept a user tapping on a link in your webview and do something different than navigating there in the webview. Here's some example code on how you might do that using the `onNavigationStateChange` function.
94
 Sometimes you want to intercept a user tapping on a link in your webview and do something different than navigating there in the webview. Here's some example code on how you might do that using the `onNavigationStateChange` function.
346
 
382
 
347
 #### The `window.ReactNativeWebView.postMessage` method and `onMessage` prop
383
 #### The `window.ReactNativeWebView.postMessage` method and `onMessage` prop
348
 
384
 
349
-Being able to send JavaScript to the web page is great, but what about when the web page wants to communicate back to your React Native code? This where `window.ReactNativeWebView.postMessage` and the `onMessage` prop come in.
385
+Being able to send JavaScript to the web page is great, but what about when the web page wants to communicate back to your React Native code? This is where `window.ReactNativeWebView.postMessage` and the `onMessage` prop come in.
350
 
386
 
351
 You _must_ set `onMessage` or the `window.ReactNativeWebView.postMessage` method will not be injected into the web page.
387
 You _must_ set `onMessage` or the `window.ReactNativeWebView.postMessage` method will not be injected into the web page.
352
 
388
 
389
 This code will result in this alert:
425
 This code will result in this alert:
390
 
426
 
391
 <img alt="Alert showing communication from web page to React Native" width="200" src="https://user-images.githubusercontent.com/1479215/53671269-7e822300-3c32-11e9-9937-7ddc34ba8af3.png" />
427
 <img alt="Alert showing communication from web page to React Native" width="200" src="https://user-images.githubusercontent.com/1479215/53671269-7e822300-3c32-11e9-9937-7ddc34ba8af3.png" />
428
+
429
+### Working with custom headers, sessions, and cookies
430
+
431
+#### Setting Custom Headers
432
+
433
+In React Native WebView, you can set a custom header like this:
434
+
435
+```jsx
436
+<WebView
437
+  source={{
438
+    uri: 'http://example.com',
439
+    headers: {
440
+      'my-custom-header-key': 'my-custom-header-value',
441
+    },
442
+  }}
443
+/>
444
+```
445
+
446
+This will set the header on the first load, but not on subsequent page navigations.
447
+
448
+In order to work around this, you can track the current URL, intercept new page loads, and navigate to them yourself ([original credit for this technique to Chirag Shah from Big Binary](https://blog.bigbinary.com/2016/07/26/passing-request-headers-on-each-webview-request-in-react-native.html)):
449
+
450
+```jsx
451
+const CustomHeaderWebView = props => {
452
+  const { uri, onLoadStart, ...restProps } = props;
453
+  const [currentURI, setURI] = useState(props.source.uri);
454
+  const newSource = { ...props.source, uri: currentURI };
455
+
456
+  return (
457
+    <WebView
458
+      {...restProps}
459
+      source={newSource}
460
+      onShouldStartLoadWithRequest={request => {
461
+        // If we're loading the current URI, allow it to load
462
+        if (request.url === currentURI) return true;
463
+        // We're loading a new URL -- change state first
464
+        setURI(request.url);
465
+        return false;
466
+      }}
467
+    />
468
+  );
469
+};
470
+
471
+<CustomHeaderWebView
472
+  source={{
473
+    uri: 'http://example.com',
474
+    headers: {
475
+      'my-custom-header-key': 'my-custom-header-value',
476
+    },
477
+  }}
478
+/>;
479
+```
480
+
481
+#### Managing Cookies
482
+
483
+You can set cookies on the React Native side using the [react-native-cookies](https://github.com/joeferraro/react-native-cookies) package.
484
+
485
+When you do, you'll likely want to enable the [sharedCookiesEnabled](Reference#sharedCookiesEnabled) prop as well.
486
+
487
+```jsx
488
+const App = () => {
489
+  return (
490
+    <WebView
491
+      source={{ uri: 'http://example.com' }}
492
+      sharedCookiesEnabled={true}
493
+    />
494
+  );
495
+};
496
+```
497
+
498
+If you'd like to send custom cookies in the WebView itself, you can do so in a custom header, like this:
499
+
500
+```jsx
501
+const App = () => {
502
+  return (
503
+    <WebView
504
+      source={{
505
+        uri: 'http://example.com',
506
+        headers: {
507
+          Cookie: 'cookie1=asdf; cookie2=dfasdfdas',
508
+        },
509
+      }}
510
+      sharedCookiesEnabled={true}
511
+    />
512
+  );
513
+};
514
+```
515
+
516
+Note that these cookies will only be sent on the first request unless you use the technique above for [setting custom headers on each page load](#Setting-Custom-Headers).

+ 102
- 0
docs/README.portuguese.md
File diff suppressed because it is too large
View File


+ 49
- 11
docs/Reference.md View File

70
 - [`reload`](Reference.md#reload)
70
 - [`reload`](Reference.md#reload)
71
 - [`stopLoading`](Reference.md#stoploading)
71
 - [`stopLoading`](Reference.md#stoploading)
72
 - [`injectJavaScript`](Reference.md#injectjavascriptstr)
72
 - [`injectJavaScript`](Reference.md#injectjavascriptstr)
73
-
73
+- [`clearFormData`](Reference.md#clearFormData)
74
+- [`clearCache`](Reference.md#clearCache)
75
+- [`clearHistory`](Reference.md#clearHistory)
76
+- [`requestFocus`](Reference.md#requestFocus)
74
 ---
77
 ---
75
 
78
 
76
 # Reference
79
 # Reference
85
 
88
 
86
 **Load uri**
89
 **Load uri**
87
 
90
 
88
-- `uri` (string) - The URI to load in the `WebView`. Can be a local or remote file.
91
+- `uri` (string) - The URI to load in the `WebView`. Can be a local or remote file, and can be changed with React state or props to navigate to a new page.
89
 - `method` (string) - The HTTP Method to use. Defaults to GET if not specified. On Android, the only supported methods are GET and POST.
92
 - `method` (string) - The HTTP Method to use. Defaults to GET if not specified. On Android, the only supported methods are GET and POST.
90
-- `headers` (object) - Additional HTTP headers to send with the request. On Android, this can only be used with GET requests.
93
+- `headers` (object) - Additional HTTP headers to send with the request. On Android, this can only be used with GET requests. See the [Guide](Guide.md#setting-custom-headers) for more information on setting custom headers.
91
 - `body` (string) - The HTTP body to send with the request. This must be a valid UTF-8 string, and will be sent exactly as specified, with no additional encoding (e.g. URL-escaping or base64) applied. On Android, this can only be used with POST requests.
94
 - `body` (string) - The HTTP body to send with the request. This must be a valid UTF-8 string, and will be sent exactly as specified, with no additional encoding (e.g. URL-escaping or base64) applied. On Android, this can only be used with POST requests.
92
 
95
 
93
 **Static HTML**
96
 **Static HTML**
689
 
692
 
690
 ### `thirdPartyCookiesEnabled`
693
 ### `thirdPartyCookiesEnabled`
691
 
694
 
692
-Boolean value to enable third party cookies in the `WebView`. Used on Android Lollipop and above only as third party cookies are enabled by default on Android Kitkat and below and on iOS. The default value is `true`.
695
+Boolean value to enable third party cookies in the `WebView`. Used on Android Lollipop and above only as third party cookies are enabled by default on Android Kitkat and below and on iOS. The default value is `true`. For more on cookies, read the [Guide](Guide.md#Managing-Cookies)
693
 
696
 
694
 | Type | Required | Platform |
697
 | Type | Required | Platform |
695
 | ---- | -------- | -------- |
698
 | ---- | -------- | -------- |
879
 
882
 
880
 ### `allowFileAccessFromFileURLs`
883
 ### `allowFileAccessFromFileURLs`
881
 
884
 
882
- Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs. The default value is `false`.
885
+Boolean that sets whether JavaScript running in the context of a file scheme URL should be allowed to access content from other file scheme URLs. The default value is `false`.
883
 
886
 
884
 | Type | Required | Platform |
887
 | Type | Required | Platform |
885
 | ---- | -------- | -------- |
888
 | ---- | -------- | -------- |
1002
 Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed. When navigating back, content is not revalidated, instead the content is just retrieved from the cache. This property allows the client to override this behavior.
1005
 Overrides the way the cache is used. The way the cache is used is based on the navigation type. For a normal page load, the cache is checked and content is re-validated as needed. When navigating back, content is not revalidated, instead the content is just retrieved from the cache. This property allows the client to override this behavior.
1003
 
1006
 
1004
 Possible values are:
1007
 Possible values are:
1008
+
1005
 - `LOAD_DEFAULT` - Default cache usage mode. If the navigation type doesn't impose any specific behavior, use cached resources when they are available and not expired, otherwise load resources from the network.
1009
 - `LOAD_DEFAULT` - Default cache usage mode. If the navigation type doesn't impose any specific behavior, use cached resources when they are available and not expired, otherwise load resources from the network.
1006
 - `LOAD_CACHE_ELSE_NETWORK` - Use cached resources when they are available, even if they have expired. Otherwise load resources from the network.
1010
 - `LOAD_CACHE_ELSE_NETWORK` - Use cached resources when they are available, even if they have expired. Otherwise load resources from the network.
1007
 - `LOAD_NO_CACHE` - Don't use the cache, load from the network.
1011
 - `LOAD_NO_CACHE` - Don't use the cache, load from the network.
1008
-- `LOAD_CACHE_ONLY` - Don't use the network, load from the cache. 
1009
- 
1010
-| Type    | Required | Default      | Platform |
1011
-| ------- | -------- | -------------| -------- |
1012
-| string  | No       | LOAD_DEFAULT | Android  |
1012
+- `LOAD_CACHE_ONLY` - Don't use the network, load from the cache.
1013
+
1014
+| Type   | Required | Default      | Platform |
1015
+| ------ | -------- | ------------ | -------- |
1016
+| string | No       | LOAD_DEFAULT | Android  |
1013
 
1017
 
1014
 ---
1018
 ---
1015
 
1019
 
1035
 
1039
 
1036
 ### `sharedCookiesEnabled`
1040
 ### `sharedCookiesEnabled`
1037
 
1041
 
1038
-Set `true` if shared cookies from `[NSHTTPCookieStorage sharedHTTPCookieStorage]` should used for every load request in the WebView. The default value is `false`.
1042
+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)
1039
 
1043
 
1040
 | Type    | Required | Platform |
1044
 | Type    | Required | Platform |
1041
 | ------- | -------- | -------- |
1045
 | ------- | -------- | -------- |
1107
 
1111
 
1108
 To learn more, read the [Communicating between JS and Native](Guide.md#communicating-between-js-and-native) guide.
1112
 To learn more, read the [Communicating between JS and Native](Guide.md#communicating-between-js-and-native) guide.
1109
 
1113
 
1114
+### `requestFocus()`
1115
+
1116
+```javascript
1117
+requestFocus();
1118
+```
1119
+
1120
+Request the webView to ask for focus. (People working on TV apps might want having a look at this!)
1121
+
1122
+### `clearFormData()`
1123
+(android only)
1124
+
1125
+```javascript
1126
+clearFormData();
1127
+```
1128
+Removes the autocomplete popup from the currently focused form field, if present. [developer.android.com reference](https://developer.android.com/reference/android/webkit/WebView.html#clearFormData())
1129
+
1130
+
1131
+### `clearCache(bool)`
1132
+(android only)
1133
+```javascript
1134
+clearCache(true);
1135
+```
1136
+
1137
+Clears the resource cache. Note that the cache is per-application, so this will clear the cache for all WebViews used. [developer.android.com reference](https://developer.android.com/reference/android/webkit/WebView.html#clearCache(boolean))
1138
+
1139
+
1140
+### `clearHistory()`
1141
+(android only)
1142
+```javascript
1143
+clearHistory();
1144
+```
1145
+
1146
+Tells this WebView to clear its internal back/forward list. [developer.android.com reference](https://developer.android.com/reference/android/webkit/WebView.html#clearHistory())
1147
+
1110
 ## Other Docs
1148
 ## Other Docs
1111
 
1149
 
1112
 Also check out our [Getting Started Guide](Getting-Started.md) and [In-Depth Guide](Guide.md).
1150
 Also check out our [Getting Started Guide](Getting-Started.md) and [In-Depth Guide](Guide.md).

+ 1
- 1
package.json View File

8
     "Thibault Malbranche <malbranche.thibault@gmail.com>"
8
     "Thibault Malbranche <malbranche.thibault@gmail.com>"
9
   ],
9
   ],
10
   "license": "MIT",
10
   "license": "MIT",
11
-  "version": "7.4.2",
11
+  "version": "7.5.2",
12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
12
   "homepage": "https://github.com/react-native-community/react-native-webview#readme",
13
   "scripts": {
13
   "scripts": {
14
     "ci": "CI=true && yarn lint && yarn test",
14
     "ci": "CI=true && yarn lint && yarn test",

+ 27
- 3
src/WebView.android.tsx View File

27
   AndroidWebViewProps,
27
   AndroidWebViewProps,
28
   NativeWebViewAndroid,
28
   NativeWebViewAndroid,
29
   State,
29
   State,
30
-  RNCWebViewUIManager,
30
+  RNCWebViewUIManagerAndroid,
31
 } from './WebViewTypes';
31
 } from './WebViewTypes';
32
 
32
 
33
 import styles from './WebView.styles';
33
 import styles from './WebView.styles';
34
 
34
 
35
-const UIManager = NotTypedUIManager as RNCWebViewUIManager;
35
+const UIManager = NotTypedUIManager as RNCWebViewUIManagerAndroid;
36
 
36
 
37
 const RNCWebView = requireNativeComponent(
37
 const RNCWebView = requireNativeComponent(
38
   'RNCWebView',
38
   'RNCWebView',
123
     );
123
     );
124
   };
124
   };
125
 
125
 
126
+  clearFormData = () => {
127
+    UIManager.dispatchViewManagerCommand(
128
+       this.getWebViewHandle(),
129
+       this.getCommands().clearFormData,
130
+        undefined,
131
+    );
132
+  }
133
+
134
+  clearCache = (includeDiskFiles: boolean) => {
135
+    UIManager.dispatchViewManagerCommand(
136
+       this.getWebViewHandle(),
137
+       this.getCommands().clearCache,
138
+       [includeDiskFiles],
139
+    );
140
+  };
141
+
142
+  clearHistory = () => {
143
+    UIManager.dispatchViewManagerCommand(
144
+       this.getWebViewHandle(),
145
+       this.getCommands().clearHistory,
146
+        undefined,
147
+    );
148
+  };
149
+
126
   /**
150
   /**
127
    * Injects a javascript string into the referenced WebView. Deliberately does not
151
    * Injects a javascript string into the referenced WebView. Deliberately does not
128
    * return a response because using eval() to return a response breaks this method
152
    * return a response because using eval() to return a response breaks this method
278
     const webViewStyles = [styles.container, styles.webView, style];
302
     const webViewStyles = [styles.container, styles.webView, style];
279
     const webViewContainerStyle = [styles.container, containerStyle];
303
     const webViewContainerStyle = [styles.container, containerStyle];
280
 
304
 
281
-    if (source && 'method' in source) {
305
+    if (typeof source !== "number" && source && 'method' in source) {
282
       if (source.method === 'POST' && source.headers) {
306
       if (source.method === 'POST' && source.headers) {
283
         console.warn(
307
         console.warn(
284
           'WebView: `source.headers` is not supported when using POST.',
308
           'WebView: `source.headers` is not supported when using POST.',

+ 2
- 2
src/WebView.ios.tsx View File

28
   NativeWebViewIOS,
28
   NativeWebViewIOS,
29
   ViewManager,
29
   ViewManager,
30
   State,
30
   State,
31
-  RNCWebViewUIManager,
31
+  RNCWebViewUIManagerIOS,
32
 } from './WebViewTypes';
32
 } from './WebViewTypes';
33
 
33
 
34
 import styles from './WebView.styles';
34
 import styles from './WebView.styles';
35
 
35
 
36
-const UIManager = NotTypedUIManager as RNCWebViewUIManager;
36
+const UIManager = NotTypedUIManager as RNCWebViewUIManagerIOS;
37
 
37
 
38
 const { resolveAssetSource } = Image;
38
 const { resolveAssetSource } = Image;
39
 const processDecelerationRate = (
39
 const processDecelerationRate = (

+ 17
- 8
src/WebViewTypes.ts View File

14
 
14
 
15
 type WebViewCommands = 'goForward' | 'goBack' | 'reload' | 'stopLoading' | 'postMessage' | 'injectJavaScript' | 'loadUrl' | 'requestFocus';
15
 type WebViewCommands = 'goForward' | 'goBack' | 'reload' | 'stopLoading' | 'postMessage' | 'injectJavaScript' | 'loadUrl' | 'requestFocus';
16
 
16
 
17
-export interface RNCWebViewUIManager extends UIManagerStatic {
17
+type AndroidWebViewCommands = 'clearHistory' | 'clearCache' | 'clearFormData';
18
+
19
+
20
+
21
+interface RNCWebViewUIManager<Commands extends string> extends UIManagerStatic {
18
   getViewManagerConfig: (
22
   getViewManagerConfig: (
19
-    name: string,
23
+      name: string,
20
   ) => {
24
   ) => {
21
-    Commands: { [key in WebViewCommands]: number };
25
+    Commands: {[key in Commands]: number};
22
   };
26
   };
23
 }
27
 }
24
 
28
 
29
+export type RNCWebViewUIManagerAndroid = RNCWebViewUIManager<WebViewCommands | AndroidWebViewCommands>
30
+export type RNCWebViewUIManagerIOS = RNCWebViewUIManager<WebViewCommands>
31
+
32
+
33
+
25
 type WebViewState = 'IDLE' | 'LOADING' | 'ERROR';
34
 type WebViewState = 'IDLE' | 'LOADING' | 'ERROR';
26
 
35
 
27
 interface BaseState {
36
 interface BaseState {
457
   /**
466
   /**
458
    * https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
467
    * https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
459
    * Set the cacheMode. Possible values are:
468
    * Set the cacheMode. Possible values are:
460
-   * 
469
+   *
461
    * - `'LOAD_DEFAULT'` (default)
470
    * - `'LOAD_DEFAULT'` (default)
462
    * - `'LOAD_CACHE_ELSE_NETWORK'`
471
    * - `'LOAD_CACHE_ELSE_NETWORK'`
463
    * - `'LOAD_NO_CACHE'`
472
    * - `'LOAD_NO_CACHE'`
492
    */
501
    */
493
   geolocationEnabled?: boolean;
502
   geolocationEnabled?: boolean;
494
 
503
 
495
-  
504
+
496
   /**
505
   /**
497
-   * Boolean that sets whether JavaScript running in the context of a file 
498
-   * scheme URL should be allowed to access content from other file scheme URLs. 
506
+   * Boolean that sets whether JavaScript running in the context of a file
507
+   * scheme URL should be allowed to access content from other file scheme URLs.
499
    * Including accessing content from other file scheme URLs
508
    * Including accessing content from other file scheme URLs
500
    * @platform android
509
    * @platform android
501
    */
510
    */
502
   allowFileAccessFromFileURLs?: boolean;
511
   allowFileAccessFromFileURLs?: boolean;
503
-  
512
+
504
   /**
513
   /**
505
    * Boolean that sets whether JavaScript running in the context of a file
514
    * Boolean that sets whether JavaScript running in the context of a file
506
    * scheme URL should be allowed to access content from any origin.
515
    * scheme URL should be allowed to access content from any origin.