Browse Source

fix WebView types

Thibault Malbranche 6 years ago
parent
commit
6c00b47607
3 changed files with 22 additions and 24 deletions
  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 View File

50
   ERROR = 'ERROR',
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
   typeof source !== 'number' && !('html' in source);
56
   typeof source !== 'number' && !('html' in source);
55
 
57
 
56
 const defaultRenderLoading = (): React.ReactNode => (
58
 const defaultRenderLoading = (): React.ReactNode => (

+ 6
- 10
src/WebView.ios.tsx View File

123
   </View>
123
   </View>
124
 );
124
 );
125
 
125
 
126
+const RNCUIWebView = requireNativeComponent('RNCUIWebView');
127
+const RNCWKWebView = requireNativeComponent('RNCWKWebView');
128
+
126
 /**
129
 /**
127
  * `WebView` renders web content in a native view.
130
  * `WebView` renders web content in a native view.
128
  *
131
  *
475
 
478
 
476
     const messagingEnabled = typeof this.props.onMessage === 'function';
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
     const webView = (
485
     const webView = (
487
       <NativeWebView
486
       <NativeWebView
529
     );
528
     );
530
   }
529
   }
531
 }
530
 }
532
-
533
-const RNCUIWebView = requireNativeComponent('RNCUIWebView');
534
-const RNCWKWebView = requireNativeComponent('RNCWKWebView');

+ 13
- 13
types/index.d.ts View File

476
         state: State;
476
         state: State;
477
         webViewRef: React.RefObject<React.ComponentClass<{}, any>>;
477
         webViewRef: React.RefObject<React.ComponentClass<{}, any>>;
478
         UNSAFE_componentWillMount(): void;
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
             goForward: () => void;
485
             goForward: () => void;
481
             goBack: () => void;
486
             goBack: () => void;
482
             reload: () => void;
487
             reload: () => void;
484
             postMessage: () => void;
489
             postMessage: () => void;
485
             injectJavaScript: () => void;
490
             injectJavaScript: () => void;
486
         };
491
         };
487
-        /**
488
-         * Go forward one page in the web view's history.
489
-         */
490
-        goForward: () => void;
491
         /**
492
         /**
492
          * Go back one page in the web view's history.
493
          * Go back one page in the web view's history.
493
          */
494
          */
522
          * We return an event with a bunch of fields including:
523
          * We return an event with a bunch of fields including:
523
          *  url, title, loading, canGoBack, canGoForward
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
          * Returns the native `WebView` node.
528
          * Returns the native `WebView` node.
528
          */
529
          */
529
         getWebViewHandle: () => number | null;
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
         render(): React.ReactNode;
537
         render(): React.ReactNode;
538
     }
538
     }
539
 }
539
 }