Browse Source

Fixed tsc

Tom Underhill 4 years ago
parent
commit
7c34b9541f
2 changed files with 174 additions and 21 deletions
  1. 0
    17
      src/WebView.macos.tsx
  2. 174
    4
      src/WebViewTypes.ts

+ 0
- 17
src/WebView.macos.tsx View File

@@ -24,7 +24,6 @@ import {
24 24
   WebViewProgressEvent,
25 25
   WebViewTerminatedEvent,
26 26
   MacOSWebViewProps,
27
-  DecelerationRateConstant,
28 27
   NativeWebViewMacOS,
29 28
   ViewManager,
30 29
   State,
@@ -36,17 +35,6 @@ import styles from './WebView.styles';
36 35
 const UIManager = NotTypedUIManager as RNCWebViewUIManagerMacOS;
37 36
 
38 37
 const { resolveAssetSource } = Image;
39
-const processDecelerationRate = (
40
-  decelerationRate: DecelerationRateConstant | number | undefined,
41
-) => {
42
-  let newDecelerationRate = decelerationRate;
43
-  if (newDecelerationRate === 'normal') {
44
-    newDecelerationRate = 0.998;
45
-  } else if (newDecelerationRate === 'fast') {
46
-    newDecelerationRate = 0.99;
47
-  }
48
-  return newDecelerationRate;
49
-};
50 38
 
51 39
 const RNCWebViewManager = NativeModules.RNCWebViewManager as ViewManager;
52 40
 
@@ -267,7 +255,6 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
267 255
     this.showRedboxOnPropChanges(prevProps, 'allowsInlineMediaPlayback');
268 256
     this.showRedboxOnPropChanges(prevProps, 'incognito');
269 257
     this.showRedboxOnPropChanges(prevProps, 'mediaPlaybackRequiresUserAction');
270
-    this.showRedboxOnPropChanges(prevProps, 'dataDetectorTypes');
271 258
   }
272 259
 
273 260
   showRedboxOnPropChanges(
@@ -283,7 +270,6 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
283 270
 
284 271
   render() {
285 272
     const {
286
-      decelerationRate: decelerationRateProp,
287 273
       nativeConfig = {},
288 274
       onMessage,
289 275
       onShouldStartLoadWithRequest: onShouldStartLoadWithRequestProp,
@@ -323,8 +309,6 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
323 309
       onShouldStartLoadWithRequestProp,
324 310
     );
325 311
 
326
-    const decelerationRate = processDecelerationRate(decelerationRateProp);
327
-
328 312
     const NativeWebView
329 313
       = (nativeConfig.component as typeof NativeWebViewMacOS | undefined)
330 314
       || RNCWebView;
@@ -333,7 +317,6 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
333 317
       <NativeWebView
334 318
         key="webViewKey"
335 319
         {...otherProps}
336
-        decelerationRate={decelerationRate}
337 320
         messagingEnabled={typeof onMessage === 'function'}
338 321
         onLoadingError={this.onLoadingError}
339 322
         onLoadingFinish={this.onLoadingFinish}

+ 174
- 4
src/WebViewTypes.ts View File

@@ -28,7 +28,7 @@ interface RNCWebViewUIManager<Commands extends string> extends UIManagerStatic {
28 28
 
29 29
 export type RNCWebViewUIManagerAndroid = RNCWebViewUIManager<WebViewCommands | AndroidWebViewCommands>
30 30
 export type RNCWebViewUIManagerIOS = RNCWebViewUIManager<WebViewCommands>
31
-
31
+export type RNCWebViewUIManagerMacOS = RNCWebViewUIManager<WebViewCommands>
32 32
 
33 33
 
34 34
 type WebViewState = 'IDLE' | 'LOADING' | 'ERROR';
@@ -57,6 +57,14 @@ declare const NativeWebViewIOSBase: Constructor<NativeMethodsMixin> &
57 57
   typeof NativeWebViewIOSComponent;
58 58
 export class NativeWebViewIOS extends NativeWebViewIOSBase {}
59 59
 
60
+// eslint-disable-next-line react/prefer-stateless-function
61
+declare class NativeWebViewMacOSComponent extends Component<
62
+  MacOSNativeWebViewProps
63
+> {}
64
+declare const NativeWebViewMacOSBase: Constructor<NativeMethodsMixin> &
65
+  typeof NativeWebViewMacOSComponent;
66
+export class NativeWebViewMacOS extends NativeWebViewMacOSBase {}
67
+
60 68
 // eslint-disable-next-line react/prefer-stateless-function
61 69
 declare class NativeWebViewAndroidComponent extends Component<
62 70
   AndroidNativeWebViewProps
@@ -104,7 +112,7 @@ export interface WebViewMessage extends WebViewNativeEvent {
104 112
 
105 113
 export interface WebViewError extends WebViewNativeEvent {
106 114
   /**
107
-   * `domain` is only used on iOS
115
+   * `domain` is only used on iOS and macOS
108 116
    */
109 117
   domain?: string;
110 118
   code: number;
@@ -195,7 +203,7 @@ export interface WebViewNativeConfig {
195 203
   /**
196 204
    * The native component used to render the WebView.
197 205
    */
198
-  component?: typeof NativeWebViewIOS | typeof NativeWebViewAndroid;
206
+  component?: typeof NativeWebViewIOS | typeof NativeWebViewMacOS | typeof NativeWebViewAndroid;
199 207
   /**
200 208
    * Set props directly on the native component WebView. Enables custom props which the
201 209
    * original WebView doesn't pass through.
@@ -203,7 +211,7 @@ export interface WebViewNativeConfig {
203 211
   props?: Object;
204 212
   /**
205 213
    * Set the ViewManager to use for communication with the native side.
206
-   * @platform ios
214
+   * @platform ios, macos
207 215
    */
208 216
   viewManager?: ViewManager;
209 217
 }
@@ -281,6 +289,27 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
281 289
   onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
282 290
 }
283 291
 
292
+export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
293
+  allowingReadAccessToURL?: string;
294
+  allowsBackForwardNavigationGestures?: boolean;
295
+  allowsInlineMediaPlayback?: boolean;
296
+  allowsLinkPreview?: boolean;
297
+  automaticallyAdjustContentInsets?: boolean;
298
+  bounces?: boolean;
299
+  contentInset?: ContentInsetProp;
300
+  contentInsetAdjustmentBehavior?:
301
+    | 'automatic'
302
+    | 'scrollableAxes'
303
+    | 'never'
304
+    | 'always';
305
+  directionalLockEnabled?: boolean;
306
+  hideKeyboardAccessoryView?: boolean;
307
+  pagingEnabled?: boolean;
308
+  scrollEnabled?: boolean;
309
+  useSharedProcessPool?: boolean;
310
+  onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
311
+}
312
+
284 313
 export interface IOSWebViewProps extends WebViewSharedProps {
285 314
   /**
286 315
    * Does not store any data within the lifetime of the WebView.
@@ -460,6 +489,147 @@ export interface IOSWebViewProps extends WebViewSharedProps {
460 489
   onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
461 490
 }
462 491
 
492
+export interface MacOSWebViewProps extends WebViewSharedProps {
493
+  /**
494
+   * Does not store any data within the lifetime of the WebView.
495
+   */
496
+  incognito?: boolean;
497
+
498
+  /**
499
+   * Boolean value that determines whether the web view bounces
500
+   * when it reaches the edge of the content. The default value is `true`.
501
+   * @platform macos
502
+   */
503
+  bounces?: boolean;
504
+
505
+  /**
506
+   * Boolean value that determines whether scrolling is enabled in the
507
+   * `WebView`. The default value is `true`.
508
+   * @platform macos
509
+   */
510
+  scrollEnabled?: boolean;
511
+
512
+  /**
513
+   * If the value of this property is true, the scroll view stops on multiples
514
+   * of the scroll view’s bounds when the user scrolls.
515
+   * The default value is false.
516
+   * @platform macos
517
+   */
518
+  pagingEnabled?: boolean;
519
+
520
+  /**
521
+   * Controls whether to adjust the content inset for web views that are
522
+   * placed behind a navigation bar, tab bar, or toolbar. The default value
523
+   * is `true`.
524
+   * @platform macos
525
+   */
526
+  automaticallyAdjustContentInsets?: boolean;
527
+
528
+  /**
529
+   * This property specifies how the safe area insets are used to modify the
530
+   * content area of the scroll view. The default value of this property is
531
+   * "never". Available on iOS 11 and later.
532
+   */
533
+  contentInsetAdjustmentBehavior?:
534
+    | 'automatic'
535
+    | 'scrollableAxes'
536
+    | 'never'
537
+    | 'always';
538
+
539
+  /**
540
+   * The amount by which the web view content is inset from the edges of
541
+   * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
542
+   * @platform macos
543
+   */
544
+  contentInset?: ContentInsetProp;
545
+
546
+  /**
547
+   * Boolean that determines whether HTML5 videos play inline or use the
548
+   * native full-screen controller. The default value is `false`.
549
+   *
550
+   * **NOTE** : In order for video to play inline, not only does this
551
+   * property need to be set to `true`, but the video element in the HTML
552
+   * document must also include the `webkit-playsinline` attribute.
553
+   * @platform macos
554
+   */
555
+  allowsInlineMediaPlayback?: boolean;
556
+  /**
557
+   * Hide the accessory view when the keyboard is open. Default is false to be
558
+   * backward compatible.
559
+   */
560
+  hideKeyboardAccessoryView?: boolean;
561
+  /**
562
+   * A Boolean value indicating whether horizontal swipe gestures will trigger
563
+   * back-forward list navigations.
564
+   */
565
+  allowsBackForwardNavigationGestures?: boolean;
566
+  /**
567
+   * A Boolean value indicating whether WebKit WebView should be created using a shared
568
+   * process pool, enabling WebViews to share cookies and localStorage between each other.
569
+   * Default is true but can be set to false for backwards compatibility.
570
+   * @platform macos
571
+   */
572
+  useSharedProcessPool?: boolean;
573
+
574
+  /**
575
+   * The custom user agent string.
576
+   */
577
+  userAgent?: string;
578
+
579
+  /**
580
+   * A Boolean value that determines whether pressing on a link
581
+   * displays a preview of the destination for the link.
582
+   *
583
+   * This property is available on devices that support Force Touch trackpad.
584
+   * @platform macos
585
+   */
586
+  allowsLinkPreview?: boolean;
587
+
588
+  /**
589
+   * Set true if shared cookies from HTTPCookieStorage should used for every load request.
590
+   * The default value is `false`.
591
+   * @platform macos
592
+   */
593
+  sharedCookiesEnabled?: boolean;
594
+
595
+  /**
596
+   * A Boolean value that determines whether scrolling is disabled in a particular direction.
597
+   * The default value is `true`.
598
+   * @platform macos
599
+   */
600
+  directionalLockEnabled?: boolean;
601
+
602
+  /**
603
+   * A Boolean value indicating whether web content can programmatically display the keyboard.
604
+   *
605
+   * When this property is set to true, the user must explicitly tap the elements in the
606
+   * web view to display the keyboard (or other relevant input view) for that element.
607
+   * When set to false, a focus event on an element causes the input view to be displayed
608
+   * and associated with that element automatically.
609
+   *
610
+   * The default value is `true`.
611
+   * @platform macos
612
+   */
613
+  keyboardDisplayRequiresUserAction?: boolean;
614
+
615
+  /**
616
+   * A String value that indicates which URLs the WebView's file can then
617
+   * reference in scripts, AJAX requests, and CSS imports. This is only used
618
+   * for WebViews that are loaded with a source.uri set to a `'file://'` URL.
619
+   *
620
+   * If not provided, the default is to only allow read access to the URL
621
+   * provided in source.uri itself.
622
+   * @platform macos
623
+   */
624
+  allowingReadAccessToURL?: string;
625
+
626
+  /**
627
+   * Function that is invoked when the WebKit WebView content process gets terminated.
628
+   * @platform macos
629
+   */
630
+  onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
631
+}
632
+
463 633
 export interface AndroidWebViewProps extends WebViewSharedProps {
464 634
   onNavigationStateChange?: (event: WebViewNavigation) => void;
465 635
   onContentSizeChange?: (event: WebViewEvent) => void;