Browse Source

fixed types

Thibault Malbranche 5 years ago
parent
commit
e4360cf298
5 changed files with 19 additions and 16 deletions
  1. 1
    0
      .eslintignore
  2. 4
    3
      index.d.ts
  3. 3
    2
      src/WebView.android.tsx
  4. 3
    2
      src/WebView.ios.tsx
  5. 8
    9
      src/WebViewTypes.ts

+ 1
- 0
.eslintignore View File

@@ -0,0 +1 @@
1
+lib/

+ 4
- 3
index.d.ts View File

@@ -1,7 +1,8 @@
1
-import WebViewIOS from './lib/WebView.ios';
2
-import WebViewAndroid from './lib/WebView.android';
1
+import { ComponentType } from 'react';
2
+// eslint-disable-next-line
3
+import { IOSWebViewProps, AndroidWebViewProps } from './lib/WebViewTypes';
3 4
 
4
-declare const WebView: WebViewIOS | WebViewAndroid;
5
+declare const WebView: ComponentType<IOSWebViewProps & AndroidWebViewProps>;
5 6
 
6 7
 export { WebView };
7 8
 export default WebView;

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

@@ -273,7 +273,8 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
273 273
 
274 274
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
275 275
       this.onShouldStartLoadWithRequestCallback,
276
-      originWhitelist,
276
+      // casting cause it's in the default props
277
+      originWhitelist as ReadonlyArray<string>,
277 278
       onShouldStartLoadWithRequestProp,
278 279
     );
279 280
 
@@ -305,4 +306,4 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
305 306
   }
306 307
 }
307 308
 
308
-module.exports = WebView;
309
+export default WebView;

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

@@ -382,7 +382,8 @@ class WebView extends React.Component<IOSWebViewProps, State> {
382 382
 
383 383
     const onShouldStartLoadWithRequest = createOnShouldStartLoadWithRequest(
384 384
       this.onShouldStartLoadWithRequestCallback,
385
-      originWhitelist,
385
+      // casting cause it's in the default props
386
+      originWhitelist as ReadonlyArray<string>,
386 387
       onShouldStartLoadWithRequestProp,
387 388
     );
388 389
 
@@ -426,4 +427,4 @@ class WebView extends React.Component<IOSWebViewProps, State> {
426 427
   }
427 428
 }
428 429
 
429
-module.exports = WebView;
430
+export default WebView;

+ 8
- 9
src/WebViewTypes.ts View File

@@ -8,7 +8,7 @@
8 8
 
9 9
 /* eslint-disable react/no-multi-comp */
10 10
 
11
-import { ReactNode, ReactElement, Component } from 'react';
11
+import { ReactElement, Component } from 'react';
12 12
 import {
13 13
   NativeSyntheticEvent,
14 14
   ViewStyle,
@@ -512,7 +512,7 @@ export interface WebViewSharedProps extends ViewProps {
512 512
   /**
513 513
    * Function that returns a view to show if there's an error.
514 514
    */
515
-  renderError: (
515
+  renderError?: (
516 516
     errorDomain: string | undefined,
517 517
     errorCode: number,
518 518
     errorDesc: string,
@@ -521,27 +521,27 @@ export interface WebViewSharedProps extends ViewProps {
521 521
   /**
522 522
    * Function that returns a loading indicator.
523 523
    */
524
-  renderLoading: () => ReactElement;
524
+  renderLoading?: () => ReactElement;
525 525
 
526 526
   /**
527 527
    * Function that is invoked when the `WebView` has finished loading.
528 528
    */
529
-  onLoad: (event: WebViewNavigationEvent) => void;
529
+  onLoad?: (event: WebViewNavigationEvent) => void;
530 530
 
531 531
   /**
532 532
    * Function that is invoked when the `WebView` load succeeds or fails.
533 533
    */
534
-  onLoadEnd: (event: WebViewNavigationEvent | WebViewErrorEvent) => void;
534
+  onLoadEnd?: (event: WebViewNavigationEvent | WebViewErrorEvent) => void;
535 535
 
536 536
   /**
537 537
    * Function that is invoked when the `WebView` starts loading.
538 538
    */
539
-  onLoadStart: (event: WebViewNavigationEvent) => void;
539
+  onLoadStart?: (event: WebViewNavigationEvent) => void;
540 540
 
541 541
   /**
542 542
    * Function that is invoked when the `WebView` load fails.
543 543
    */
544
-  onError: (event: WebViewErrorEvent) => void;
544
+  onError?: (event: WebViewErrorEvent) => void;
545 545
 
546 546
   /**
547 547
    * Function that is invoked when the `WebView` loading starts or ends.
@@ -608,7 +608,7 @@ export interface WebViewSharedProps extends ViewProps {
608 608
    * this whitelist, we will open the URL in Safari.
609 609
    * The default whitelisted origins are "http://*" and "https://*".
610 610
    */
611
-  originWhitelist: ReadonlyArray<string>;
611
+  originWhitelist?: ReadonlyArray<string>;
612 612
 
613 613
   /**
614 614
    * Function that allows custom handling of any web view requests. Return
@@ -629,5 +629,4 @@ export interface WebViewSharedProps extends ViewProps {
629 629
   cacheEnabled?: boolean;
630 630
 
631 631
   style?: StyleProp<ViewStyle>;
632
-  children: ReactNode;
633 632
 }