/
WebViewTypes.ts
1191 lines (1030 loc) · 37.2 KB
/
WebViewTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable react/no-multi-comp, max-classes-per-file */
import { ReactElement, Component } from 'react';
import {
NativeSyntheticEvent,
ViewProps,
StyleProp,
ViewStyle,
NativeMethodsMixin,
Constructor,
UIManagerStatic,
NativeScrollEvent,
} from 'react-native';
type WebViewCommands = 'goForward' | 'goBack' | 'reload' | 'stopLoading' | 'postMessage' | 'injectJavaScript' | 'loadUrl' | 'requestFocus';
type AndroidWebViewCommands = 'clearHistory' | 'clearCache' | 'clearFormData';
interface RNCWebViewUIManager<Commands extends string> extends UIManagerStatic {
getViewManagerConfig: (
name: string,
) => {
Commands: {[key in Commands]: number};
};
}
export type RNCWebViewUIManagerAndroid = RNCWebViewUIManager<WebViewCommands | AndroidWebViewCommands>
export type RNCWebViewUIManagerIOS = RNCWebViewUIManager<WebViewCommands>
export type RNCWebViewUIManagerMacOS = RNCWebViewUIManager<WebViewCommands>
export type RNCWebViewUIManagerWindows = RNCWebViewUIManager<WebViewCommands>
type WebViewState = 'IDLE' | 'LOADING' | 'ERROR';
interface BaseState {
viewState: WebViewState;
}
interface NormalState extends BaseState {
viewState: 'IDLE' | 'LOADING';
lastErrorEvent: WebViewError | null;
}
interface ErrorState extends BaseState {
viewState: 'ERROR';
lastErrorEvent: WebViewError;
}
export type State = NormalState | ErrorState;
// eslint-disable-next-line react/prefer-stateless-function
declare class NativeWebViewIOSComponent extends Component<
IOSNativeWebViewProps
> {}
declare const NativeWebViewIOSBase: Constructor<NativeMethodsMixin> &
typeof NativeWebViewIOSComponent;
export class NativeWebViewIOS extends NativeWebViewIOSBase {}
// eslint-disable-next-line react/prefer-stateless-function
declare class NativeWebViewMacOSComponent extends Component<
MacOSNativeWebViewProps
> {}
declare const NativeWebViewMacOSBase: Constructor<NativeMethodsMixin> &
typeof NativeWebViewMacOSComponent;
export class NativeWebViewMacOS extends NativeWebViewMacOSBase {}
// eslint-disable-next-line react/prefer-stateless-function
declare class NativeWebViewAndroidComponent extends Component<
AndroidNativeWebViewProps
> {}
declare const NativeWebViewAndroidBase: Constructor<NativeMethodsMixin> &
typeof NativeWebViewAndroidComponent;
export class NativeWebViewAndroid extends NativeWebViewAndroidBase {}
// eslint-disable-next-line react/prefer-stateless-function
declare class NativeWebViewWindowsComponent extends Component<
WindowsNativeWebViewProps
> {}
declare const NativeWebViewWindowsBase: Constructor<NativeMethodsMixin> &
typeof NativeWebViewWindowsComponent;
export class NativeWebViewWindows extends NativeWebViewWindowsBase {}
export interface ContentInsetProp {
top?: number;
left?: number;
bottom?: number;
right?: number;
}
export interface WebViewNativeEvent {
url: string;
loading: boolean;
title: string;
canGoBack: boolean;
canGoForward: boolean;
lockIdentifier: number;
}
export interface WebViewNativeProgressEvent extends WebViewNativeEvent {
progress: number;
}
export interface WebViewNavigation extends WebViewNativeEvent {
navigationType:
| 'click'
| 'formsubmit'
| 'backforward'
| 'reload'
| 'formresubmit'
| 'other';
mainDocumentURL?: string;
}
export interface ShouldStartLoadRequest extends WebViewNavigation {
isTopFrame: boolean;
}
export interface FileDownload {
downloadUrl: string;
}
export type DecelerationRateConstant = 'normal' | 'fast';
export interface WebViewMessage extends WebViewNativeEvent {
data: string;
}
export interface WebViewError extends WebViewNativeEvent {
/**
* `domain` is only used on iOS and macOS
*/
domain?: string;
code: number;
description: string;
}
export interface WebViewHttpError extends WebViewNativeEvent {
description: string;
statusCode: number;
}
export interface WebViewRenderProcessGoneDetail {
didCrash: boolean;
}
export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
export type WebViewProgressEvent = NativeSyntheticEvent<
WebViewNativeProgressEvent
>;
export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
export type ShouldStartLoadRequestEvent = NativeSyntheticEvent<ShouldStartLoadRequest>;
export type FileDownloadEvent = NativeSyntheticEvent<FileDownload>;
export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
export type WebViewErrorEvent = NativeSyntheticEvent<WebViewError>;
export type WebViewTerminatedEvent = NativeSyntheticEvent<WebViewNativeEvent>;
export type WebViewHttpErrorEvent = NativeSyntheticEvent<WebViewHttpError>;
export type WebViewRenderProcessGoneEvent = NativeSyntheticEvent<WebViewRenderProcessGoneDetail>;
export type WebViewScrollEvent = NativeSyntheticEvent<NativeScrollEvent>;
export type DataDetectorTypes =
| 'phoneNumber'
| 'link'
| 'address'
| 'calendarEvent'
| 'trackingNumber'
| 'flightNumber'
| 'lookupSuggestion'
| 'none'
| 'all';
export type OverScrollModeType = 'always' | 'content' | 'never';
export type CacheMode = 'LOAD_DEFAULT' | 'LOAD_CACHE_ONLY' | 'LOAD_CACHE_ELSE_NETWORK' | 'LOAD_NO_CACHE';
export type AndroidLayerType = 'none' | 'software' | 'hardware';
export interface WebViewSourceUri {
/**
* The URI to load in the `WebView`. Can be a local or remote file.
*/
uri: string;
/**
* The HTTP Method to use. Defaults to GET if not specified.
* NOTE: On Android, only GET and POST are supported.
*/
method?: string;
/**
* Additional HTTP headers to send with the request.
* NOTE: On Android, this can only be used with GET requests.
*/
headers?: Object;
/**
* The HTTP body to send with the request. This must be a valid
* UTF-8 string, and will be sent exactly as specified, with no
* additional encoding (e.g. URL-escaping or base64) applied.
* NOTE: On Android, this can only be used with POST requests.
*/
body?: string;
}
export interface WebViewSourceHtml {
/**
* A static HTML page to display in the WebView.
*/
html: string;
/**
* The base URL to be used for any relative links in the HTML.
*/
baseUrl?: string;
}
export type WebViewSource = WebViewSourceUri | WebViewSourceHtml;
export interface ViewManager {
startLoadWithResult: Function;
}
export interface WebViewNativeConfig {
/**
* The native component used to render the WebView.
*/
component?: typeof NativeWebViewIOS | typeof NativeWebViewMacOS | typeof NativeWebViewAndroid;
/**
* Set props directly on the native component WebView. Enables custom props which the
* original WebView doesn't pass through.
*/
props?: Object;
/**
* Set the ViewManager to use for communication with the native side.
* @platform ios, macos
*/
viewManager?: ViewManager;
}
export type OnShouldStartLoadWithRequest = (
event: ShouldStartLoadRequest,
) => boolean;
export interface BasicAuthCredential {
/**
* A username used for basic authentication.
*/
username: string;
/**
* A password used for basic authentication.
*/
password: string;
}
export interface CommonNativeWebViewProps extends ViewProps {
cacheEnabled?: boolean;
incognito?: boolean;
injectedJavaScript?: string;
injectedJavaScriptBeforeContentLoaded?: string;
injectedJavaScriptForMainFrameOnly?: boolean;
injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
javaScriptCanOpenWindowsAutomatically?: boolean;
mediaPlaybackRequiresUserAction?: boolean;
messagingEnabled: boolean;
onScroll?: (event: WebViewScrollEvent) => void;
onLoadingError: (event: WebViewErrorEvent) => void;
onLoadingFinish: (event: WebViewNavigationEvent) => void;
onLoadingProgress: (event: WebViewProgressEvent) => void;
onLoadingStart: (event: WebViewNavigationEvent) => void;
onHttpError: (event: WebViewHttpErrorEvent) => void;
onMessage: (event: WebViewMessageEvent) => void;
onShouldStartLoadWithRequest: (event: ShouldStartLoadRequestEvent) => void;
showsHorizontalScrollIndicator?: boolean;
showsVerticalScrollIndicator?: boolean;
// TODO: find a better way to type this.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
source: any;
userAgent?: string;
/**
* Append to the existing user-agent. Overridden if `userAgent` is set.
*/
applicationNameForUserAgent?: string;
basicAuthCredential?: BasicAuthCredential;
}
export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
cacheMode?: CacheMode;
allowFileAccess?: boolean;
scalesPageToFit?: boolean;
allowFileAccessFromFileURLs?: boolean;
allowUniversalAccessFromFileURLs?: boolean;
androidHardwareAccelerationDisabled?: boolean;
androidLayerType?: AndroidLayerType;
domStorageEnabled?: boolean;
geolocationEnabled?: boolean;
javaScriptEnabled?: boolean;
mixedContentMode?: 'never' | 'always' | 'compatibility';
onContentSizeChange?: (event: WebViewEvent) => void;
onRenderProcessGone?: (event: WebViewRenderProcessGoneEvent) => void;
overScrollMode?: OverScrollModeType;
saveFormDataDisabled?: boolean;
setSupportMultipleWindows?: boolean;
textZoom?: number;
thirdPartyCookiesEnabled?: boolean;
messagingModuleName?: string;
setBuiltInZoomControls?: boolean,
setDisplayZoomControls?: boolean,
nestedScrollEnabled?: boolean;
readonly urlPrefixesForDefaultIntent?: string[];
forceDarkOn?: boolean;
}
export declare type ContentInsetAdjustmentBehavior = 'automatic' | 'scrollableAxes' | 'never' | 'always';
export declare type ContentMode = 'recommended' | 'mobile' | 'desktop';
export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
allowingReadAccessToURL?: string;
allowsBackForwardNavigationGestures?: boolean;
allowsInlineMediaPlayback?: boolean;
allowsLinkPreview?: boolean;
allowFileAccessFromFileURLs?: boolean;
allowUniversalAccessFromFileURLs?: boolean;
automaticallyAdjustContentInsets?: boolean;
autoManageStatusBarEnabled?: boolean;
bounces?: boolean;
contentInset?: ContentInsetProp;
contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
contentMode?: ContentMode;
readonly dataDetectorTypes?: DataDetectorTypes | DataDetectorTypes[];
decelerationRate?: number;
directionalLockEnabled?: boolean;
hideKeyboardAccessoryView?: boolean;
pagingEnabled?: boolean;
scrollEnabled?: boolean;
useSharedProcessPool?: boolean;
onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
injectedJavaScriptForMainFrameOnly?: boolean;
injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
onFileDownload?: (event: FileDownloadEvent) => void;
limitsNavigationsToAppBoundDomains?: boolean;
}
export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
allowingReadAccessToURL?: string;
allowFileAccessFromFileURLs?: boolean;
allowUniversalAccessFromFileURLs?: boolean;
allowsBackForwardNavigationGestures?: boolean;
allowsInlineMediaPlayback?: boolean;
allowsLinkPreview?: boolean;
automaticallyAdjustContentInsets?: boolean;
bounces?: boolean;
contentInset?: ContentInsetProp;
contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
directionalLockEnabled?: boolean;
hideKeyboardAccessoryView?: boolean;
pagingEnabled?: boolean;
scrollEnabled?: boolean;
useSharedProcessPool?: boolean;
onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
}
export interface WindowsNativeWebViewProps extends CommonNativeWebViewProps {
testID?: string
}
export interface IOSWebViewProps extends WebViewSharedProps {
/**
* Does not store any data within the lifetime of the WebView.
*/
incognito?: boolean;
/**
* Boolean value that determines whether the web view bounces
* when it reaches the edge of the content. The default value is `true`.
* @platform ios
*/
bounces?: boolean;
/**
* A floating-point number that determines how quickly the scroll view
* decelerates after the user lifts their finger. You may also use the
* string shortcuts `"normal"` and `"fast"` which match the underlying iOS
* settings for `UIScrollViewDecelerationRateNormal` and
* `UIScrollViewDecelerationRateFast` respectively:
*
* - normal: 0.998
* - fast: 0.99 (the default for iOS web view)
* @platform ios
*/
decelerationRate?: DecelerationRateConstant | number;
/**
* Boolean value that determines whether scrolling is enabled in the
* `WebView`. The default value is `true`.
* @platform ios
*/
scrollEnabled?: boolean;
/**
* If the value of this property is true, the scroll view stops on multiples
* of the scroll view’s bounds when the user scrolls.
* The default value is false.
* @platform ios
*/
pagingEnabled?: boolean;
/**
* Controls whether to adjust the content inset for web views that are
* placed behind a navigation bar, tab bar, or toolbar. The default value
* is `true`.
* @platform ios
*/
automaticallyAdjustContentInsets?: boolean;
/**
* Controls whether to adjust the scroll indicator inset for web views that are
* placed behind a navigation bar, tab bar, or toolbar. The default value
* is `false`. (iOS 13+)
* @platform ios
*/
automaticallyAdjustsScrollIndicatorInsets?: boolean;
/**
* This property specifies how the safe area insets are used to modify the
* content area of the scroll view. The default value of this property is
* "never". Available on iOS 11 and later.
*/
contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
/**
* The amount by which the web view content is inset from the edges of
* the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
* @platform ios
*/
contentInset?: ContentInsetProp;
/**
* Defaults to `recommended`, which loads mobile content on iPhone
* and iPad Mini but desktop content on other iPads.
*
* Possible values are:
* - `'recommended'`
* - `'mobile'`
* - `'desktop'`
* @platform ios
*/
contentMode?: ContentMode;
/**
* Determines the types of data converted to clickable URLs in the web view's content.
* By default only phone numbers are detected.
*
* You can provide one type or an array of many types.
*
* Possible values for `dataDetectorTypes` are:
*
* - `'phoneNumber'`
* - `'link'`
* - `'address'`
* - `'calendarEvent'`
* - `'none'`
* - `'all'`
*
* With the new WebKit implementation, we have three new values:
* - `'trackingNumber'`,
* - `'flightNumber'`,
* - `'lookupSuggestion'`,
*
* @platform ios
*/
readonly dataDetectorTypes?: DataDetectorTypes | DataDetectorTypes[];
/**
* Boolean that determines whether HTML5 videos play inline or use the
* native full-screen controller. The default value is `false`.
*
* **NOTE** : In order for video to play inline, not only does this
* property need to be set to `true`, but the video element in the HTML
* document must also include the `webkit-playsinline` attribute.
* @platform ios
*/
allowsInlineMediaPlayback?: boolean;
/**
* Hide the accessory view when the keyboard is open. Default is false to be
* backward compatible.
*/
hideKeyboardAccessoryView?: boolean;
/**
* A Boolean value indicating whether horizontal swipe gestures will trigger
* back-forward list navigations.
*/
allowsBackForwardNavigationGestures?: boolean;
/**
* A Boolean value indicating whether WebKit WebView should be created using a shared
* process pool, enabling WebViews to share cookies and localStorage between each other.
* Default is true but can be set to false for backwards compatibility.
* @platform ios
*/
useSharedProcessPool?: boolean;
/**
* The custom user agent string.
*/
userAgent?: string;
/**
* A Boolean value that determines whether pressing on a link
* displays a preview of the destination for the link.
*
* This property is available on devices that support 3D Touch.
* In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
* @platform ios
*/
allowsLinkPreview?: boolean;
/**
* Set true if shared cookies from HTTPCookieStorage should used for every load request.
* The default value is `false`.
* @platform ios
*/
sharedCookiesEnabled?: boolean;
/**
* When set to true the hardware silent switch is ignored.
* The default value is `false`.
* @platform ios
*/
ignoreSilentHardwareSwitch?: boolean;
/**
* Set true if StatusBar should be light when user watch video fullscreen.
* The default value is `true`.
* @platform ios
*/
autoManageStatusBarEnabled?: boolean;
/**
* A Boolean value that determines whether scrolling is disabled in a particular direction.
* The default value is `true`.
* @platform ios
*/
directionalLockEnabled?: boolean;
/**
* A Boolean value indicating whether web content can programmatically display the keyboard.
*
* When this property is set to true, the user must explicitly tap the elements in the
* web view to display the keyboard (or other relevant input view) for that element.
* When set to false, a focus event on an element causes the input view to be displayed
* and associated with that element automatically.
*
* The default value is `true`.
* @platform ios
*/
keyboardDisplayRequiresUserAction?: boolean;
/**
* A String value that indicates which URLs the WebView's file can then
* reference in scripts, AJAX requests, and CSS imports. This is only used
* for WebViews that are loaded with a source.uri set to a `'file://'` URL.
*
* If not provided, the default is to only allow read access to the URL
* provided in source.uri itself.
* @platform ios
*/
allowingReadAccessToURL?: string;
/**
* Boolean that sets whether JavaScript running in the context of a file
* scheme URL should be allowed to access content from other file scheme URLs.
* Including accessing content from other file scheme URLs
* @platform ios
*/
allowFileAccessFromFileURLs?: boolean;
/**
* Boolean that sets whether JavaScript running in the context of a file
* scheme URL should be allowed to access content from any origin.
* Including accessing content from other file scheme URLs
* @platform ios
*/
allowUniversalAccessFromFileURLs?: boolean;
/**
* Function that is invoked when the WebKit WebView content process gets terminated.
* @platform ios
*/
onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
/**
* If `true` (default), loads the `injectedJavaScript` only into the main frame.
* If `false`, loads it into all frames (e.g. iframes).
* @platform ios
*/
injectedJavaScriptForMainFrameOnly?: boolean;
/**
* If `true` (default), loads the `injectedJavaScriptBeforeContentLoaded` only into the main frame.
* If `false`, loads it into all frames (e.g. iframes).
* @platform ios
*/
injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
/**
* Boolean value that determines whether a pull to refresh gesture is
* available in the `WebView`. The default value is `false`.
* If `true`, sets `bounces` automatically to `true`
* @platform ios
*
*/
pullToRefreshEnabled?: boolean;
/**
* Function that is invoked when the client needs to download a file.
*
* iOS 13+ only: If the webview navigates to a URL that results in an HTTP
* response with a Content-Disposition header 'attachment...', then
* this will be called.
*
* iOS 8+: If the MIME type indicates that the content is not renderable by the
* webview, that will also cause this to be called. On iOS versions before 13,
* this is the only condition that will cause this function to be called.
*
* The application will need to provide its own code to actually download
* the file.
*
* If not provided, the default is to let the webview try to render the file.
*/
onFileDownload?: (event: FileDownloadEvent) => void;
/**
* A Boolean value which, when set to `true`, indicates to WebKit that a WKWebView
* will only navigate to app-bound domains. Once set, any attempt to navigate away
* from an app-bound domain will fail with the error “App-bound domain failure.”
*
* Applications can specify up to 10 “app-bound” domains using a new
* Info.plist key `WKAppBoundDomains`.
* @platform ios
*/
limitsNavigationsToAppBoundDomains?: boolean;
/**
* A Boolean value which, when set to `true`, WebView will be rendered with Apple Pay support.
* Once set, websites will be able to invoke apple pay from React Native Webview.
* This comes with a cost features like `injectJavaScript`, html5 History,`sharedCookiesEnabled`,
* `injectedJavaScript`, `injectedJavaScriptBeforeContentLoaded` will not work
* {@link https://developer.apple.com/documentation/safari-release-notes/safari-13-release-notes#Payment-Request-API ApplePay Doc}
* if you require to send message to App , webpage has to explicitly call webkit message handler
* and receive it on `onMessage` handler on react native side
* @example
* window.webkit.messageHandlers.ReactNativeWebView.postMessage("hello apple pay")
* @platform ios
* The default value is false.
*/
enableApplePay?: boolean;
}
export interface MacOSWebViewProps extends WebViewSharedProps {
/**
* Does not store any data within the lifetime of the WebView.
*/
incognito?: boolean;
/**
* Boolean value that determines whether the web view bounces
* when it reaches the edge of the content. The default value is `true`.
* @platform macos
*/
bounces?: boolean;
/**
* Boolean value that determines whether scrolling is enabled in the
* `WebView`. The default value is `true`.
* @platform macos
*/
scrollEnabled?: boolean;
/**
* If the value of this property is true, the scroll view stops on multiples
* of the scroll view’s bounds when the user scrolls.
* The default value is false.
* @platform macos
*/
pagingEnabled?: boolean;
/**
* Controls whether to adjust the content inset for web views that are
* placed behind a navigation bar, tab bar, or toolbar. The default value
* is `true`.
* @platform macos
*/
automaticallyAdjustContentInsets?: boolean;
/**
* This property specifies how the safe area insets are used to modify the
* content area of the scroll view. The default value of this property is
* "never". Available on iOS 11 and later.
*/
contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
/**
* The amount by which the web view content is inset from the edges of
* the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
* @platform macos
*/
contentInset?: ContentInsetProp;
/**
* Boolean that determines whether HTML5 videos play inline or use the
* native full-screen controller. The default value is `false`.
*
* **NOTE** : In order for video to play inline, not only does this
* property need to be set to `true`, but the video element in the HTML
* document must also include the `webkit-playsinline` attribute.
* @platform macos
*/
allowsInlineMediaPlayback?: boolean;
/**
* Hide the accessory view when the keyboard is open. Default is false to be
* backward compatible.
*/
hideKeyboardAccessoryView?: boolean;
/**
* A Boolean value indicating whether horizontal swipe gestures will trigger
* back-forward list navigations.
*/
allowsBackForwardNavigationGestures?: boolean;
/**
* A Boolean value indicating whether WebKit WebView should be created using a shared
* process pool, enabling WebViews to share cookies and localStorage between each other.
* Default is true but can be set to false for backwards compatibility.
* @platform macos
*/
useSharedProcessPool?: boolean;
/**
* The custom user agent string.
*/
userAgent?: string;
/**
* A Boolean value that determines whether pressing on a link
* displays a preview of the destination for the link.
*
* This property is available on devices that support Force Touch trackpad.
* @platform macos
*/
allowsLinkPreview?: boolean;
/**
* Set true if shared cookies from HTTPCookieStorage should used for every load request.
* The default value is `false`.
* @platform macos
*/
sharedCookiesEnabled?: boolean;
/**
* A Boolean value that determines whether scrolling is disabled in a particular direction.
* The default value is `true`.
* @platform macos
*/
directionalLockEnabled?: boolean;
/**
* A Boolean value indicating whether web content can programmatically display the keyboard.
*
* When this property is set to true, the user must explicitly tap the elements in the
* web view to display the keyboard (or other relevant input view) for that element.
* When set to false, a focus event on an element causes the input view to be displayed
* and associated with that element automatically.
*
* The default value is `true`.
* @platform macos
*/
keyboardDisplayRequiresUserAction?: boolean;
/**
* A String value that indicates which URLs the WebView's file can then
* reference in scripts, AJAX requests, and CSS imports. This is only used
* for WebViews that are loaded with a source.uri set to a `'file://'` URL.
*
* If not provided, the default is to only allow read access to the URL
* provided in source.uri itself.
* @platform macos
*/
allowingReadAccessToURL?: string;
/**
* Boolean that sets whether JavaScript running in the context of a file
* scheme URL should be allowed to access content from other file scheme URLs.
* Including accessing content from other file scheme URLs
* @platform macos
*/
allowFileAccessFromFileURLs?: boolean;
/**
* Boolean that sets whether JavaScript running in the context of a file
* scheme URL should be allowed to access content from any origin.
* Including accessing content from other file scheme URLs
* @platform macos
*/
allowUniversalAccessFromFileURLs?: boolean;
/**
* Function that is invoked when the WebKit WebView content process gets terminated.
* @platform macos
*/
onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
}
export interface AndroidWebViewProps extends WebViewSharedProps {
onNavigationStateChange?: (event: WebViewNavigation) => void;
onContentSizeChange?: (event: WebViewEvent) => void;
/**
* Function that is invoked when the `WebView` process crashes or is killed by the OS.
* Works only on Android (minimum API level 26).
*/
onRenderProcessGone?: (event: WebViewRenderProcessGoneEvent) => void;
/**
* https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
* Set the cacheMode. Possible values are:
*
* - `'LOAD_DEFAULT'` (default)
* - `'LOAD_CACHE_ELSE_NETWORK'`
* - `'LOAD_NO_CACHE'`
* - `'LOAD_CACHE_ONLY'`
*
* @platform android
*/
cacheMode?: CacheMode;
/**
* https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
* Sets the overScrollMode. Possible values are:
*
* - `'always'` (default)
* - `'content'`
* - `'never'`
*
* @platform android
*/
overScrollMode?: OverScrollModeType;
/**
* Boolean that controls whether the web content is scaled to fit
* the view and enables the user to change the scale. The default value
* is `true`.
*/
scalesPageToFit?: boolean;
/**
* Sets whether Geolocation is enabled. The default is false.
* @platform android
*/
geolocationEnabled?: boolean;
/**
* Boolean that sets whether JavaScript running in the context of a file
* scheme URL should be allowed to access content from other file scheme URLs.
* Including accessing content from other file scheme URLs
* @platform android
*/
allowFileAccessFromFileURLs?: boolean;
/**
* Boolean that sets whether JavaScript running in the context of a file
* scheme URL should be allowed to access content from any origin.
* Including accessing content from other file scheme URLs
* @platform android
*/
allowUniversalAccessFromFileURLs?: boolean;
/**
* Sets whether the webview allow access to file system.
* @platform android
*/
allowFileAccess?: boolean;
/**
* Used on Android only, controls whether form autocomplete data should be saved
* @platform android
*/
saveFormDataDisabled?: boolean;
/**
* Boolean value to set whether the WebView supports multiple windows. Used on Android only
* The default value is `true`.
* @platform android
*/
setSupportMultipleWindows?: boolean;
/**
* Used on Android only, controls whether the given list of URL prefixes should
* make {@link com.facebook.react.views.webview.ReactWebViewClient} to launch a
* default activity intent for those URL instead of loading it within the webview.
* Use this to list URLs that WebView cannot handle, e.g. a PDF url.
* @platform android
*/
readonly urlPrefixesForDefaultIntent?: string[];
/**
* Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
* as Hardware Acceleration is a feature only for Android. The default value is `false`.
* @platform android
*/
androidHardwareAccelerationDisabled?: boolean;
/**
* https://developer.android.com/reference/android/webkit/WebView#setLayerType(int,%20android.graphics.Paint)
* Sets the layerType. Possible values are:
*
* - `'none'` (default)
* - `'software'`
* - `'hardware'`
*
* @platform android
*/
androidLayerType?: AndroidLayerType;
/**
* Boolean value to enable third party cookies in the `WebView`. Used on
* Android Lollipop and above only as third party cookies are enabled by
* default on Android Kitkat and below and on iOS. The default value is `true`.
* @platform android
*/
thirdPartyCookiesEnabled?: boolean;
/**
* Boolean value to control whether DOM Storage is enabled. Used only in
* Android.
* @platform android
*/
domStorageEnabled?: boolean;
/**
* Sets the user-agent for the `WebView`.
* @platform android
*/
userAgent?: string;
/**
* Sets number that controls text zoom of the page in percent.
* @platform android
*/
textZoom?: number;
/**
* Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
*
* Possible values for `mixedContentMode` are:
*
* - `'never'` (default) - WebView will not allow a secure origin to load content from an insecure origin.
* - `'always'` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
* - `'compatibility'` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
* @platform android
*/
mixedContentMode?: 'never' | 'always' | 'compatibility';
/**
* Sets ability to open fullscreen videos on Android devices.
*/
allowsFullscreenVideo?: boolean;
/**
* Configuring Dark Theme
*
* *NOTE* : The force dark setting is not persistent. You must call the static method every time your app process is started.
*
* *NOTE* : The change from day<->night mode is a configuration change so by default the activity will be restarted
* and pickup the new values to apply the theme.
* Take care when overriding this default behavior to ensure this method is still called when changes are made.
*
* @platform android
*/
forceDarkOn?: boolean;
/**
* Boolean value to control whether pinch zoom is enabled. Used only in Android.
* Default to true
*
* @platform android
*/
setBuiltInZoomControls?: boolean;
/**