Browse Source

Merge branch 'master' into patch-1

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

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

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

+ 6
- 0
README.md View File

@@ -93,3 +93,9 @@ This project follows the [all-contributors](https://github.com/all-contributors/
93 93
 ## License
94 94
 
95 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,4 +1,4 @@
1
-ReactNativeWebView_kotlinVersion=1.3.11
1
+ReactNativeWebView_kotlinVersion=1.3.50
2 2
 ReactNativeWebView_compileSdkVersion=28
3 3
 ReactNativeWebView_buildToolsVersion=28.0.3
4 4
 ReactNativeWebView_targetSdkVersion=28

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

@@ -115,6 +115,12 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
115 115
   public static final int COMMAND_INJECT_JAVASCRIPT = 6;
116 116
   public static final int COMMAND_LOAD_URL = 7;
117 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 124
   protected static final String REACT_CLASS = "RNCWebView";
119 125
   protected static final String HTML_ENCODING = "UTF-8";
120 126
   protected static final String HTML_MIME_TYPE = "text/html";
@@ -266,7 +272,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
266 272
         break;
267 273
       case "LOAD_CACHE_ELSE_NETWORK":
268 274
         cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK;
269
-        break;  
275
+        break;
270 276
       case "LOAD_NO_CACHE":
271 277
         cacheMode = WebSettings.LOAD_NO_CACHE;
272 278
         break;
@@ -280,13 +286,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
280 286
 
281 287
   @ReactProp(name = "androidHardwareAccelerationDisabled")
282 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 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,17 +551,19 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
550 551
   @Override
551 552
   public @Nullable
552 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 569
   @Override
@@ -611,6 +614,16 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
611 614
       case COMMAND_FOCUS:
612 615
         root.requestFocus();
613 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,6 +642,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
629 642
     if (mAllowsFullscreenVideo) {
630 643
       int initialRequestedOrientation = reactContext.getCurrentActivity().getRequestedOrientation();
631 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 650
         @Override
633 651
         public void onShowCustomView(View view, CustomViewCallback callback) {
634 652
           if (mVideoView != null) {
@@ -681,7 +699,12 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
681 699
       if (mWebChromeClient != null) {
682 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 708
       webView.setWebChromeClient(mWebChromeClient);
686 709
     }
687 710
   }
@@ -1007,7 +1030,9 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
1007 1030
     @Override
1008 1031
     public void setWebViewClient(WebViewClient client) {
1009 1032
       super.setWebViewClient(client);
1010
-      mRNCWebViewClient = (RNCWebViewClient) client;
1033
+      if (client instanceof RNCWebViewClient) {
1034
+        mRNCWebViewClient = (RNCWebViewClient) client;
1035
+      }
1011 1036
     }
1012 1037
 
1013 1038
     public @Nullable

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

@@ -242,8 +242,6 @@ public class RNCWebViewModule extends ReactContextBaseJavaModule implements Acti
242 242
 
243 243
   private Intent getVideoIntent() {
244 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 245
     outputFileUri = getOutputUri(MediaStore.ACTION_VIDEO_CAPTURE);
248 246
     intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
249 247
     return intent;

+ 126
- 1
docs/Guide.md View File

@@ -8,11 +8,13 @@ _This guide is currently a work in progress._
8 8
 
9 9
 - [Basic Inline HTML](Guide.md#basic-inline-html)
10 10
 - [Basic URL Source](Guide.md#basic-url-source)
11
+- [Loading local HTML files](Guide.md#loading-local-html-files)
11 12
 - [Controlling navigation state changes](Guide.md#controlling-navigation-state-changes)
12 13
 - [Add support for File Upload](Guide.md#add-support-for-file-upload)
13 14
 - [Multiple files upload](Guide.md#multiple-files-upload)
14 15
 - [Add support for File Download](Guide.md#add-support-for-file-download)
15 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 19
 ### Basic inline HTML
18 20
 
@@ -53,6 +55,40 @@ class MyWeb extends Component {
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 92
 ### Controlling navigation state changes
57 93
 
58 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,7 +382,7 @@ _Under the hood_
346 382
 
347 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 387
 You _must_ set `onMessage` or the `window.ReactNativeWebView.postMessage` method will not be injected into the web page.
352 388
 
@@ -389,3 +425,92 @@ export default class App extends Component {
389 425
 This code will result in this alert:
390 426
 
391 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,7 +70,10 @@ This document lays out the current public properties and methods for the React N
70 70
 - [`reload`](Reference.md#reload)
71 71
 - [`stopLoading`](Reference.md#stoploading)
72 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 79
 # Reference
@@ -85,9 +88,9 @@ The object passed to `source` can have either of the following shapes:
85 88
 
86 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 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 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 96
 **Static HTML**
@@ -689,7 +692,7 @@ Possible values for `mixedContentMode` are:
689 692
 
690 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 697
 | Type | Required | Platform |
695 698
 | ---- | -------- | -------- |
@@ -879,7 +882,7 @@ Set whether Geolocation is enabled in the `WebView`. The default value is `false
879 882
 
880 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 887
 | Type | Required | Platform |
885 888
 | ---- | -------- | -------- |
@@ -1002,14 +1005,15 @@ Sets whether WebView should use browser caching.
1002 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 1007
 Possible values are:
1008
+
1005 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 1010
 - `LOAD_CACHE_ELSE_NETWORK` - Use cached resources when they are available, even if they have expired. Otherwise load resources from the network.
1007 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,7 +1039,7 @@ A Boolean value that determines whether pressing on a link displays a preview of
1035 1039
 
1036 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 1044
 | Type    | Required | Platform |
1041 1045
 | ------- | -------- | -------- |
@@ -1107,6 +1111,40 @@ Executes the JavaScript string.
1107 1111
 
1108 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 1148
 ## Other Docs
1111 1149
 
1112 1150
 Also check out our [Getting Started Guide](Getting-Started.md) and [In-Depth Guide](Guide.md).

+ 1
- 1
package.json View File

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

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

@@ -27,12 +27,12 @@ import {
27 27
   AndroidWebViewProps,
28 28
   NativeWebViewAndroid,
29 29
   State,
30
-  RNCWebViewUIManager,
30
+  RNCWebViewUIManagerAndroid,
31 31
 } from './WebViewTypes';
32 32
 
33 33
 import styles from './WebView.styles';
34 34
 
35
-const UIManager = NotTypedUIManager as RNCWebViewUIManager;
35
+const UIManager = NotTypedUIManager as RNCWebViewUIManagerAndroid;
36 36
 
37 37
 const RNCWebView = requireNativeComponent(
38 38
   'RNCWebView',
@@ -123,6 +123,30 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
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 151
    * Injects a javascript string into the referenced WebView. Deliberately does not
128 152
    * return a response because using eval() to return a response breaks this method
@@ -278,7 +302,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
278 302
     const webViewStyles = [styles.container, styles.webView, style];
279 303
     const webViewContainerStyle = [styles.container, containerStyle];
280 304
 
281
-    if (source && 'method' in source) {
305
+    if (typeof source !== "number" && source && 'method' in source) {
282 306
       if (source.method === 'POST' && source.headers) {
283 307
         console.warn(
284 308
           'WebView: `source.headers` is not supported when using POST.',

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

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

+ 17
- 8
src/WebViewTypes.ts View File

@@ -14,14 +14,23 @@ import {
14 14
 
15 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 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 34
 type WebViewState = 'IDLE' | 'LOADING' | 'ERROR';
26 35
 
27 36
 interface BaseState {
@@ -457,7 +466,7 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
457 466
   /**
458 467
    * https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
459 468
    * Set the cacheMode. Possible values are:
460
-   * 
469
+   *
461 470
    * - `'LOAD_DEFAULT'` (default)
462 471
    * - `'LOAD_CACHE_ELSE_NETWORK'`
463 472
    * - `'LOAD_NO_CACHE'`
@@ -492,15 +501,15 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
492 501
    */
493 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 508
    * Including accessing content from other file scheme URLs
500 509
    * @platform android
501 510
    */
502 511
   allowFileAccessFromFileURLs?: boolean;
503
-  
512
+
504 513
   /**
505 514
    * Boolean that sets whether JavaScript running in the context of a file
506 515
    * scheme URL should be allowed to access content from any origin.