Просмотр исходного кода

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

Jamon Holmgren 6 лет назад
Родитель
Сommit
de777b9533
1 измененных файлов: 28 добавлений и 13 удалений
  1. 28
    13
      js/WebView.android.js

+ 28
- 13
js/WebView.android.js Просмотреть файл

@@ -1,3 +1,12 @@
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 10
 'use strict';
2 11
 
3 12
 import React from 'react';
@@ -54,7 +63,7 @@ class WebView extends React.Component {
54 63
     onMessage: PropTypes.func,
55 64
     onContentSizeChange: PropTypes.func,
56 65
     startInLoadingState: PropTypes.bool, // force WebView to show loadingView on first load
57
-    style: ViewPropTypes.style,
66
+    style: DeprecatedViewPropTypes.style,
58 67
 
59 68
     html: deprecatedPropType(
60 69
       PropTypes.string,
@@ -106,6 +115,12 @@ class WebView extends React.Component {
106 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 125
      * Used on Android only, JS is enabled by default for WebView on iOS
111 126
      * @platform android
@@ -265,7 +280,7 @@ class WebView extends React.Component {
265 280
         );
266 281
     } else if (this.state.viewState !== WebViewState.IDLE) {
267 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,11 +314,11 @@ class WebView extends React.Component {
299 314
       WebViewShared.originWhitelistToRegex,
300 315
     );
301 316
 
302
-    let NativeWebView = nativeConfig.component || RNCWebView;
317
+    let NativeWebView = nativeConfig.component || RCTWebView;
303 318
 
304 319
     const webView = (
305 320
       <NativeWebView
306
-        ref={RNC_WEBVIEW_REF}
321
+        ref={RCT_WEBVIEW_REF}
307 322
         key="webViewKey"
308 323
         style={webViewStyles}
309 324
         source={resolveAssetSource(source)}
@@ -350,7 +365,7 @@ class WebView extends React.Component {
350 365
   goForward = () => {
351 366
     UIManager.dispatchViewManagerCommand(
352 367
       this.getWebViewHandle(),
353
-      UIManager.RNCWebView.Commands.goForward,
368
+      UIManager.RCTWebView.Commands.goForward,
354 369
       null,
355 370
     );
356 371
   };
@@ -358,7 +373,7 @@ class WebView extends React.Component {
358 373
   goBack = () => {
359 374
     UIManager.dispatchViewManagerCommand(
360 375
       this.getWebViewHandle(),
361
-      UIManager.RNCWebView.Commands.goBack,
376
+      UIManager.RCTWebView.Commands.goBack,
362 377
       null,
363 378
     );
364 379
   };
@@ -369,7 +384,7 @@ class WebView extends React.Component {
369 384
     });
370 385
     UIManager.dispatchViewManagerCommand(
371 386
       this.getWebViewHandle(),
372
-      UIManager.RNCWebView.Commands.reload,
387
+      UIManager.RCTWebView.Commands.reload,
373 388
       null,
374 389
     );
375 390
   };
@@ -377,7 +392,7 @@ class WebView extends React.Component {
377 392
   stopLoading = () => {
378 393
     UIManager.dispatchViewManagerCommand(
379 394
       this.getWebViewHandle(),
380
-      UIManager.RNCWebView.Commands.stopLoading,
395
+      UIManager.RCTWebView.Commands.stopLoading,
381 396
       null,
382 397
     );
383 398
   };
@@ -385,7 +400,7 @@ class WebView extends React.Component {
385 400
   postMessage = data => {
386 401
     UIManager.dispatchViewManagerCommand(
387 402
       this.getWebViewHandle(),
388
-      UIManager.RNCWebView.Commands.postMessage,
403
+      UIManager.RCTWebView.Commands.postMessage,
389 404
       [String(data)],
390 405
     );
391 406
   };
@@ -399,7 +414,7 @@ class WebView extends React.Component {
399 414
   injectJavaScript = data => {
400 415
     UIManager.dispatchViewManagerCommand(
401 416
       this.getWebViewHandle(),
402
-      UIManager.RNCWebView.Commands.injectJavaScript,
417
+      UIManager.RCTWebView.Commands.injectJavaScript,
403 418
       [data],
404 419
     );
405 420
   };
@@ -415,7 +430,7 @@ class WebView extends React.Component {
415 430
   };
416 431
 
417 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 436
   onLoadingStart = event => {
@@ -447,13 +462,13 @@ class WebView extends React.Component {
447 462
     this.updateNavigationState(event);
448 463
   };
449 464
 
450
-  onMessage = (event) => {
465
+  onMessage = (event: Event) => {
451 466
     const { onMessage } = this.props;
452 467
     onMessage && onMessage(event);
453 468
   };
454 469
 }
455 470
 
456
-const RNCWebView = requireNativeComponent('RNCWebView');
471
+const RCTWebView = requireNativeComponent('RCTWebView');
457 472
 
458 473
 const styles = StyleSheet.create({
459 474
   container: {