Quellcode durchsuchen

fix WebView types

Thibault Malbranche vor 6 Jahren
Ursprung
Commit
6c00b47607
3 geänderte Dateien mit 22 neuen und 24 gelöschten Zeilen
  1. 3
    1
      src/WebView.android.tsx
  2. 6
    10
      src/WebView.ios.tsx
  3. 13
    13
      types/index.d.ts

+ 3
- 1
src/WebView.android.tsx Datei anzeigen

@@ -50,7 +50,9 @@ enum WebViewState {
50 50
   ERROR = 'ERROR',
51 51
 }
52 52
 
53
-const isWebViewUriSource = (source: any): source is WebViewSourceUri =>
53
+const isWebViewUriSource = (
54
+  source: WebViewSource,
55
+): source is WebViewSourceUri =>
54 56
   typeof source !== 'number' && !('html' in source);
55 57
 
56 58
 const defaultRenderLoading = (): React.ReactNode => (

+ 6
- 10
src/WebView.ios.tsx Datei anzeigen

@@ -123,6 +123,9 @@ const defaultRenderError = (
123 123
   </View>
124 124
 );
125 125
 
126
+const RNCUIWebView = requireNativeComponent('RNCUIWebView');
127
+const RNCWKWebView = requireNativeComponent('RNCWKWebView');
128
+
126 129
 /**
127 130
  * `WebView` renders web content in a native view.
128 131
  *
@@ -475,13 +478,9 @@ export default class WebView extends React.Component<
475 478
 
476 479
     const messagingEnabled = typeof this.props.onMessage === 'function';
477 480
 
478
-    let NativeWebView = nativeConfig.component;
479
-
480
-    if (this.props.useWebKit) {
481
-      NativeWebView = NativeWebView || RNCWKWebView;
482
-    } else {
483
-      NativeWebView = NativeWebView || RNCUIWebView;
484
-    }
481
+    const NativeWebView
482
+      = nativeConfig.component
483
+      || (this.props.useWebKit ? RNCWKWebView : RNCUIWebView);
485 484
 
486 485
     const webView = (
487 486
       <NativeWebView
@@ -529,6 +528,3 @@ export default class WebView extends React.Component<
529 528
     );
530 529
   }
531 530
 }
532
-
533
-const RNCUIWebView = requireNativeComponent('RNCUIWebView');
534
-const RNCWKWebView = requireNativeComponent('RNCWKWebView');

+ 13
- 13
types/index.d.ts Datei anzeigen

@@ -476,7 +476,12 @@ declare module "src/WebView.ios" {
476 476
         state: State;
477 477
         webViewRef: React.RefObject<React.ComponentClass<{}, any>>;
478 478
         UNSAFE_componentWillMount(): void;
479
-        _getCommands(): {
479
+        componentDidUpdate(prevProps: WebViewSharedProps): void;
480
+        /**
481
+         * Go forward one page in the web view's history.
482
+         */
483
+        goForward: () => void;
484
+        getCommands(): {
480 485
             goForward: () => void;
481 486
             goBack: () => void;
482 487
             reload: () => void;
@@ -484,10 +489,6 @@ declare module "src/WebView.ios" {
484 489
             postMessage: () => void;
485 490
             injectJavaScript: () => void;
486 491
         };
487
-        /**
488
-         * Go forward one page in the web view's history.
489
-         */
490
-        goForward: () => void;
491 492
         /**
492 493
          * Go back one page in the web view's history.
493 494
          */
@@ -522,18 +523,17 @@ declare module "src/WebView.ios" {
522 523
          * We return an event with a bunch of fields including:
523 524
          *  url, title, loading, canGoBack, canGoForward
524 525
          */
525
-        _updateNavigationState: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
526
+        updateNavigationState: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
526 527
         /**
527 528
          * Returns the native `WebView` node.
528 529
          */
529 530
         getWebViewHandle: () => number | null;
530
-        _onLoadingStart: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
531
-        _onLoadingError: (event: NativeSyntheticEvent<WebViewError>) => void;
532
-        _onLoadingFinish: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
533
-        _onMessage: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewMessage>) => void;
534
-        _onLoadingProgress: (event: NativeSyntheticEvent<WebViewProgressEvent>) => void;
535
-        componentDidUpdate(prevProps: WebViewSharedProps): void;
536
-        _showRedboxOnPropChanges(prevProps: WebViewSharedProps, propName: 'allowsInlineMediaPlayback' | 'mediaPlaybackRequiresUserAction' | 'dataDetectorTypes'): void;
531
+        onLoadingStart: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
532
+        onLoadingError: (event: NativeSyntheticEvent<WebViewError>) => void;
533
+        onLoadingFinish: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
534
+        onMessage: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewMessage>) => void;
535
+        onLoadingProgress: (event: NativeSyntheticEvent<WebViewProgressEvent>) => void;
536
+        showRedboxOnPropChanges(prevProps: WebViewSharedProps, propName: 'allowsInlineMediaPlayback' | 'mediaPlaybackRequiresUserAction' | 'dataDetectorTypes'): void;
537 537
         render(): React.ReactNode;
538 538
     }
539 539
 }