Browse Source

🦉 WIP: Update to WKWebView - WebView.android.js

Jamon Holmgren 6 years ago
parent
commit
de777b9533
1 changed files with 28 additions and 13 deletions
  1. 28
    13
      js/WebView.android.js

+ 28
- 13
js/WebView.android.js View File

1
+/**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ */
9
+
1
 'use strict';
10
 'use strict';
2
 
11
 
3
 import React from 'react';
12
 import React from 'react';
54
     onMessage: PropTypes.func,
63
     onMessage: PropTypes.func,
55
     onContentSizeChange: PropTypes.func,
64
     onContentSizeChange: PropTypes.func,
56
     startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
65
     startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
57
-    style: ViewPropTypes.style,
66
+    style: DeprecatedViewPropTypes.style,
58
 
67
 
59
     html: deprecatedPropType(
68
     html: deprecatedPropType(
60
       PropTypes.string,
69
       PropTypes.string,
106
       PropTypes.number,
115
       PropTypes.number,
107
     ]),
116
     ]),
108
 
117
 
118
+    /**
119
+     * If true, use WKWebView instead of UIWebView.
120
+     * @platform ios
121
+     */
122
+    useWebKit: PropTypes.bool,
123
+
109
     /**
124
     /**
110
      * Used on Android only, JS is enabled by default for WebView on iOS
125
      * Used on Android only, JS is enabled by default for WebView on iOS
111
      * @platform android
126
      * @platform android
265
         );
280
         );
266
     } else if (this.state.viewState !== WebViewState.IDLE) {
281
     } else if (this.state.viewState !== WebViewState.IDLE) {
267
       console.error(
282
       console.error(
268
-        'RNCWebView invalid state encountered: ' + this.state.loading,
283
+        'RCTWebView invalid state encountered: ' + this.state.loading,
269
       );
284
       );
270
     }
285
     }
271
 
286
 
299
       WebViewShared.originWhitelistToRegex,
314
       WebViewShared.originWhitelistToRegex,
300
     );
315
     );
301
 
316
 
302
-    let NativeWebView = nativeConfig.component || RNCWebView;
317
+    let NativeWebView = nativeConfig.component || RCTWebView;
303
 
318
 
304
     const webView = (
319
     const webView = (
305
       <NativeWebView
320
       <NativeWebView
306
-        ref={RNC_WEBVIEW_REF}
321
+        ref={RCT_WEBVIEW_REF}
307
         key="webViewKey"
322
         key="webViewKey"
308
         style={webViewStyles}
323
         style={webViewStyles}
309
         source={resolveAssetSource(source)}
324
         source={resolveAssetSource(source)}
350
   goForward = () => {
365
   goForward = () => {
351
     UIManager.dispatchViewManagerCommand(
366
     UIManager.dispatchViewManagerCommand(
352
       this.getWebViewHandle(),
367
       this.getWebViewHandle(),
353
-      UIManager.RNCWebView.Commands.goForward,
368
+      UIManager.RCTWebView.Commands.goForward,
354
       null,
369
       null,
355
     );
370
     );
356
   };
371
   };
358
   goBack = () => {
373
   goBack = () => {
359
     UIManager.dispatchViewManagerCommand(
374
     UIManager.dispatchViewManagerCommand(
360
       this.getWebViewHandle(),
375
       this.getWebViewHandle(),
361
-      UIManager.RNCWebView.Commands.goBack,
376
+      UIManager.RCTWebView.Commands.goBack,
362
       null,
377
       null,
363
     );
378
     );
364
   };
379
   };
369
     });
384
     });
370
     UIManager.dispatchViewManagerCommand(
385
     UIManager.dispatchViewManagerCommand(
371
       this.getWebViewHandle(),
386
       this.getWebViewHandle(),
372
-      UIManager.RNCWebView.Commands.reload,
387
+      UIManager.RCTWebView.Commands.reload,
373
       null,
388
       null,
374
     );
389
     );
375
   };
390
   };
377
   stopLoading = () => {
392
   stopLoading = () => {
378
     UIManager.dispatchViewManagerCommand(
393
     UIManager.dispatchViewManagerCommand(
379
       this.getWebViewHandle(),
394
       this.getWebViewHandle(),
380
-      UIManager.RNCWebView.Commands.stopLoading,
395
+      UIManager.RCTWebView.Commands.stopLoading,
381
       null,
396
       null,
382
     );
397
     );
383
   };
398
   };
385
   postMessage = data => {
400
   postMessage = data => {
386
     UIManager.dispatchViewManagerCommand(
401
     UIManager.dispatchViewManagerCommand(
387
       this.getWebViewHandle(),
402
       this.getWebViewHandle(),
388
-      UIManager.RNCWebView.Commands.postMessage,
403
+      UIManager.RCTWebView.Commands.postMessage,
389
       [String(data)],
404
       [String(data)],
390
     );
405
     );
391
   };
406
   };
399
   injectJavaScript = data => {
414
   injectJavaScript = data => {
400
     UIManager.dispatchViewManagerCommand(
415
     UIManager.dispatchViewManagerCommand(
401
       this.getWebViewHandle(),
416
       this.getWebViewHandle(),
402
-      UIManager.RNCWebView.Commands.injectJavaScript,
417
+      UIManager.RCTWebView.Commands.injectJavaScript,
403
       [data],
418
       [data],
404
     );
419
     );
405
   };
420
   };
415
   };
430
   };
416
 
431
 
417
   getWebViewHandle = () => {
432
   getWebViewHandle = () => {
418
-    return ReactNative.findNodeHandle(this.refs[RNC_WEBVIEW_REF]);
433
+    return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
419
   };
434
   };
420
 
435
 
421
   onLoadingStart = event => {
436
   onLoadingStart = event => {
447
     this.updateNavigationState(event);
462
     this.updateNavigationState(event);
448
   };
463
   };
449
 
464
 
450
-  onMessage = (event) => {
465
+  onMessage = (event: Event) => {
451
     const { onMessage } = this.props;
466
     const { onMessage } = this.props;
452
     onMessage && onMessage(event);
467
     onMessage && onMessage(event);
453
   };
468
   };
454
 }
469
 }
455
 
470
 
456
-const RNCWebView = requireNativeComponent('RNCWebView');
471
+const RCTWebView = requireNativeComponent('RCTWebView');
457
 
472
 
458
 const styles = StyleSheet.create({
473
 const styles = StyleSheet.create({
459
   container: {
474
   container: {