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

1
+lib/

+ 4
- 3
index.d.ts View File

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
 export { WebView };
7
 export { WebView };
7
 export default WebView;
8
 export default WebView;

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

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

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

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

+ 8
- 9
src/WebViewTypes.ts View File

8
 
8
 
9
 /* eslint-disable react/no-multi-comp */
9
 /* eslint-disable react/no-multi-comp */
10
 
10
 
11
-import { ReactNode, ReactElement, Component } from 'react';
11
+import { ReactElement, Component } from 'react';
12
 import {
12
 import {
13
   NativeSyntheticEvent,
13
   NativeSyntheticEvent,
14
   ViewStyle,
14
   ViewStyle,
512
   /**
512
   /**
513
    * Function that returns a view to show if there's an error.
513
    * Function that returns a view to show if there's an error.
514
    */
514
    */
515
-  renderError: (
515
+  renderError?: (
516
     errorDomain: string | undefined,
516
     errorDomain: string | undefined,
517
     errorCode: number,
517
     errorCode: number,
518
     errorDesc: string,
518
     errorDesc: string,
521
   /**
521
   /**
522
    * Function that returns a loading indicator.
522
    * Function that returns a loading indicator.
523
    */
523
    */
524
-  renderLoading: () => ReactElement;
524
+  renderLoading?: () => ReactElement;
525
 
525
 
526
   /**
526
   /**
527
    * Function that is invoked when the `WebView` has finished loading.
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
    * Function that is invoked when the `WebView` load succeeds or fails.
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
    * Function that is invoked when the `WebView` starts loading.
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
    * Function that is invoked when the `WebView` load fails.
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
    * Function that is invoked when the `WebView` loading starts or ends.
547
    * Function that is invoked when the `WebView` loading starts or ends.
608
    * this whitelist, we will open the URL in Safari.
608
    * this whitelist, we will open the URL in Safari.
609
    * The default whitelisted origins are "http://*" and "https://*".
609
    * The default whitelisted origins are "http://*" and "https://*".
610
    */
610
    */
611
-  originWhitelist: ReadonlyArray<string>;
611
+  originWhitelist?: ReadonlyArray<string>;
612
 
612
 
613
   /**
613
   /**
614
    * Function that allows custom handling of any web view requests. Return
614
    * Function that allows custom handling of any web view requests. Return
629
   cacheEnabled?: boolean;
629
   cacheEnabled?: boolean;
630
 
630
 
631
   style?: StyleProp<ViewStyle>;
631
   style?: StyleProp<ViewStyle>;
632
-  children: ReactNode;
633
 }
632
 }