|
@@ -1,5 +1,546 @@
|
1
|
|
-import WebViewIOS from './src/WebView.ios';
|
2
|
|
-import WebViewAndroid from './src/WebView.android';
|
3
|
|
-declare const WebView: typeof WebViewAndroid | typeof WebViewIOS;
|
4
|
|
-export { WebView };
|
5
|
|
-export default WebView;
|
|
1
|
+/// <reference types="react" />
|
|
2
|
+declare module "src/WebViewShared" {
|
|
3
|
+ const WebViewShared: {
|
|
4
|
+ defaultOriginWhitelist: string[];
|
|
5
|
+ extractOrigin: (url: string) => string;
|
|
6
|
+ originWhitelistToRegex: (originWhitelist: string) => string;
|
|
7
|
+ };
|
|
8
|
+ export default WebViewShared;
|
|
9
|
+}
|
|
10
|
+declare module "src/types/WebViewTypes" {
|
|
11
|
+ import { ComponentType, ReactElement, ReactNode } from 'react';
|
|
12
|
+ import { Insets, NativeSyntheticEvent, StyleProp, ViewProps, ViewStyle } from 'react-native';
|
|
13
|
+ module 'react-native' {
|
|
14
|
+ interface UIManagerStatic {
|
|
15
|
+ dispatchViewManagerCommand(node: any, callback: any, x: any): void;
|
|
16
|
+ RNCUIWebView: any;
|
|
17
|
+ RNCWKWebView: any;
|
|
18
|
+ RNCWebView: any;
|
|
19
|
+ }
|
|
20
|
+ }
|
|
21
|
+ export interface WebViewNativeEvent {
|
|
22
|
+ readonly url: string;
|
|
23
|
+ readonly loading: boolean;
|
|
24
|
+ readonly title: string;
|
|
25
|
+ readonly canGoBack: boolean;
|
|
26
|
+ readonly canGoForward: boolean;
|
|
27
|
+ }
|
|
28
|
+ export interface WebViewIOSLoadRequestEvent extends WebViewNativeEvent {
|
|
29
|
+ target: number;
|
|
30
|
+ lockIdentifier: number;
|
|
31
|
+ navigationType: 'click' | 'formsubmit' | 'backforward' | 'reload' | 'formresubmit' | 'other';
|
|
32
|
+ }
|
|
33
|
+ export interface WebViewProgressEvent extends WebViewNativeEvent {
|
|
34
|
+ readonly progress: number;
|
|
35
|
+ }
|
|
36
|
+ export interface WebViewNavigation extends WebViewNativeEvent {
|
|
37
|
+ readonly navigationType: 'click' | 'formsubmit' | 'backforward' | 'reload' | 'formresubmit' | 'other';
|
|
38
|
+ }
|
|
39
|
+ export interface WebViewMessage extends WebViewNativeEvent {
|
|
40
|
+ readonly data: string;
|
|
41
|
+ }
|
|
42
|
+ export interface WebViewError extends WebViewNativeEvent {
|
|
43
|
+ readonly domain?: string;
|
|
44
|
+ readonly code: number;
|
|
45
|
+ readonly description: string;
|
|
46
|
+ }
|
|
47
|
+ export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
|
|
48
|
+ export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
|
|
49
|
+ export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
|
|
50
|
+ export type WebViewErrorEvent = NativeSyntheticEvent<WebViewError>;
|
|
51
|
+ export type DataDetectorTypes = 'phoneNumber' | 'link' | 'address' | 'calendarEvent' | 'trackingNumber' | 'flightNumber' | 'lookupSuggestion' | 'none' | 'all';
|
|
52
|
+ export type OverScrollModeType = 'always' | 'content' | 'never';
|
|
53
|
+ export interface WebViewSourceUri {
|
|
54
|
+ /**
|
|
55
|
+ * The URI to load in the `WebView`. Can be a local or remote file.
|
|
56
|
+ */
|
|
57
|
+ uri?: string;
|
|
58
|
+ /**
|
|
59
|
+ * The HTTP Method to use. Defaults to GET if not specified.
|
|
60
|
+ * NOTE: On Android, only GET and POST are supported.
|
|
61
|
+ */
|
|
62
|
+ method?: string;
|
|
63
|
+ /**
|
|
64
|
+ * Additional HTTP headers to send with the request.
|
|
65
|
+ * NOTE: On Android, this can only be used with GET requests.
|
|
66
|
+ */
|
|
67
|
+ headers?: {
|
|
68
|
+ [key: string]: string;
|
|
69
|
+ };
|
|
70
|
+ /**
|
|
71
|
+ * The HTTP body to send with the request. This must be a valid
|
|
72
|
+ * UTF-8 string, and will be sent exactly as specified, with no
|
|
73
|
+ * additional encoding (e.g. URL-escaping or base64) applied.
|
|
74
|
+ * NOTE: On Android, this can only be used with POST requests.
|
|
75
|
+ */
|
|
76
|
+ body?: string;
|
|
77
|
+ }
|
|
78
|
+ export interface WebViewSourceHtml {
|
|
79
|
+ /**
|
|
80
|
+ * A static HTML page to display in the WebView.
|
|
81
|
+ */
|
|
82
|
+ html?: string;
|
|
83
|
+ /**
|
|
84
|
+ * The base URL to be used for any relative links in the HTML.
|
|
85
|
+ */
|
|
86
|
+ baseUrl?: string;
|
|
87
|
+ }
|
|
88
|
+ export type WebViewSource = WebViewSourceUri | WebViewSourceHtml;
|
|
89
|
+ export interface WebViewNativeConfig {
|
|
90
|
+ component?: ComponentType<WebViewSharedProps>;
|
|
91
|
+ props?: any;
|
|
92
|
+ viewManager?: any;
|
|
93
|
+ }
|
|
94
|
+ export interface IOSWebViewProps {
|
|
95
|
+ /**
|
|
96
|
+ * If true, use WKWebView instead of UIWebView.
|
|
97
|
+ * @platform ios
|
|
98
|
+ */
|
|
99
|
+ useWebKit?: boolean;
|
|
100
|
+ /**
|
|
101
|
+ * Boolean value that determines whether the web view bounces
|
|
102
|
+ * when it reaches the edge of the content. The default value is `true`.
|
|
103
|
+ * @platform ios
|
|
104
|
+ */
|
|
105
|
+ bounces?: boolean;
|
|
106
|
+ /**
|
|
107
|
+ * A floating-point number that determines how quickly the scroll view
|
|
108
|
+ * decelerates after the user lifts their finger. You may also use the
|
|
109
|
+ * string shortcuts `"normal"` and `"fast"` which match the underlying iOS
|
|
110
|
+ * settings for `UIScrollViewDecelerationRateNormal` and
|
|
111
|
+ * `UIScrollViewDecelerationRateFast` respectively:
|
|
112
|
+ *
|
|
113
|
+ * - normal: 0.998
|
|
114
|
+ * - fast: 0.99 (the default for iOS web view)
|
|
115
|
+ * @platform ios
|
|
116
|
+ */
|
|
117
|
+ decelerationRate?: 'fast' | 'normal' | number;
|
|
118
|
+ /**
|
|
119
|
+ * Boolean value that determines whether scrolling is enabled in the
|
|
120
|
+ * `WebView`. The default value is `true`.
|
|
121
|
+ * @platform ios
|
|
122
|
+ */
|
|
123
|
+ scrollEnabled?: boolean;
|
|
124
|
+ /**
|
|
125
|
+ * If the value of this property is true, the scroll view stops on multiples
|
|
126
|
+ * of the scroll view’s bounds when the user scrolls.
|
|
127
|
+ * The default value is false.
|
|
128
|
+ * @platform ios
|
|
129
|
+ */
|
|
130
|
+ pagingEnabled?: boolean;
|
|
131
|
+ /**
|
|
132
|
+ * The amount by which the web view content is inset from the edges of
|
|
133
|
+ * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
|
|
134
|
+ * @platform ios
|
|
135
|
+ */
|
|
136
|
+ contentInset?: Insets;
|
|
137
|
+ /**
|
|
138
|
+ * Determines the types of data converted to clickable URLs in the web view's content.
|
|
139
|
+ * By default only phone numbers are detected.
|
|
140
|
+ *
|
|
141
|
+ * You can provide one type or an array of many types.
|
|
142
|
+ *
|
|
143
|
+ * Possible values for `dataDetectorTypes` are:
|
|
144
|
+ *
|
|
145
|
+ * - `'phoneNumber'`
|
|
146
|
+ * - `'link'`
|
|
147
|
+ * - `'address'`
|
|
148
|
+ * - `'calendarEvent'`
|
|
149
|
+ * - `'none'`
|
|
150
|
+ * - `'all'`
|
|
151
|
+ *
|
|
152
|
+ * With the new WebKit implementation, we have three new values:
|
|
153
|
+ * - `'trackingNumber'`,
|
|
154
|
+ * - `'flightNumber'`,
|
|
155
|
+ * - `'lookupSuggestion'`,
|
|
156
|
+ *
|
|
157
|
+ * @platform ios
|
|
158
|
+ */
|
|
159
|
+ dataDetectorTypes?: DataDetectorTypes | DataDetectorTypes[];
|
|
160
|
+ /**
|
|
161
|
+ * Function that allows custom handling of any web view requests. Return
|
|
162
|
+ * `true` from the function to continue loading the request and `false`
|
|
163
|
+ * to stop loading.
|
|
164
|
+ * @platform ios
|
|
165
|
+ */
|
|
166
|
+ onShouldStartLoadWithRequest?: (event: WebViewIOSLoadRequestEvent) => any;
|
|
167
|
+ /**
|
|
168
|
+ * Boolean that determines whether HTML5 videos play inline or use the
|
|
169
|
+ * native full-screen controller. The default value is `false`.
|
|
170
|
+ *
|
|
171
|
+ * **NOTE** : In order for video to play inline, not only does this
|
|
172
|
+ * property need to be set to `true`, but the video element in the HTML
|
|
173
|
+ * document must also include the `webkit-playsinline` attribute.
|
|
174
|
+ * @platform ios
|
|
175
|
+ */
|
|
176
|
+ allowsInlineMediaPlayback?: boolean;
|
|
177
|
+ /**
|
|
178
|
+ * Hide the accessory view when the keyboard is open. Default is false to be
|
|
179
|
+ * backward compatible.
|
|
180
|
+ */
|
|
181
|
+ hideKeyboardAccessoryView?: boolean;
|
|
182
|
+ /**
|
|
183
|
+ * If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
|
|
184
|
+ */
|
|
185
|
+ allowsBackForwardNavigationGestures?: boolean;
|
|
186
|
+ /**
|
|
187
|
+ * A Boolean value that determines whether pressing on a link
|
|
188
|
+ * displays a preview of the destination for the link.
|
|
189
|
+ *
|
|
190
|
+ * This property is available on devices that support 3D Touch.
|
|
191
|
+ * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
|
|
192
|
+ * @platform ios
|
|
193
|
+ */
|
|
194
|
+ allowsLinkPreview?: boolean;
|
|
195
|
+ }
|
|
196
|
+ export interface AndroidWebViewProps {
|
|
197
|
+ onNavigationStateChange?: (event: WebViewNavigation) => any;
|
|
198
|
+ onContentSizeChange?: (event: WebViewEvent) => any;
|
|
199
|
+ /**
|
|
200
|
+ * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
|
|
201
|
+ * Sets the overScrollMode. Possible values are:
|
|
202
|
+ *
|
|
203
|
+ * - `'always'` (default)
|
|
204
|
+ * - `'content'`
|
|
205
|
+ * - `'never'`
|
|
206
|
+ *
|
|
207
|
+ * @platform android
|
|
208
|
+ */
|
|
209
|
+ overScrollMode?: OverScrollModeType;
|
|
210
|
+ /**
|
|
211
|
+ * Sets whether Geolocation is enabled. The default is false.
|
|
212
|
+ * @platform android
|
|
213
|
+ */
|
|
214
|
+ geolocationEnabled?: boolean;
|
|
215
|
+ /**
|
|
216
|
+ * Boolean that sets whether JavaScript running in the context of a file
|
|
217
|
+ * scheme URL should be allowed to access content from any origin.
|
|
218
|
+ * Including accessing content from other file scheme URLs
|
|
219
|
+ * @platform android
|
|
220
|
+ */
|
|
221
|
+ allowUniversalAccessFromFileURLs?: boolean;
|
|
222
|
+ /**
|
|
223
|
+ * Sets whether the webview allow access to file system.
|
|
224
|
+ * @platform android
|
|
225
|
+ */
|
|
226
|
+ allowFileAccess?: boolean;
|
|
227
|
+ /**
|
|
228
|
+ * Used on Android only, controls whether form autocomplete data should be saved
|
|
229
|
+ * @platform android
|
|
230
|
+ */
|
|
231
|
+ saveFormDataDisabled?: boolean;
|
|
232
|
+ urlPrefixesForDefaultIntent?: string[];
|
|
233
|
+ /**
|
|
234
|
+ * Boolean value to enable JavaScript in the `WebView`. Used on Android only
|
|
235
|
+ * as JavaScript is enabled by default on iOS. The default value is `true`.
|
|
236
|
+ * @platform android
|
|
237
|
+ */
|
|
238
|
+ javaScriptEnabled?: boolean;
|
|
239
|
+ /**
|
|
240
|
+ * Boolean value to enable third party cookies in the `WebView`. Used on
|
|
241
|
+ * Android Lollipop and above only as third party cookies are enabled by
|
|
242
|
+ * default on Android Kitkat and below and on iOS. The default value is `true`.
|
|
243
|
+ * @platform android
|
|
244
|
+ */
|
|
245
|
+ thirdPartyCookiesEnabled?: boolean;
|
|
246
|
+ /**
|
|
247
|
+ * Boolean value to control whether DOM Storage is enabled. Used only in
|
|
248
|
+ * Android.
|
|
249
|
+ * @platform android
|
|
250
|
+ */
|
|
251
|
+ domStorageEnabled?: boolean;
|
|
252
|
+ /**
|
|
253
|
+ * Sets the user-agent for the `WebView`.
|
|
254
|
+ * @platform android
|
|
255
|
+ */
|
|
256
|
+ userAgent?: string;
|
|
257
|
+ /**
|
|
258
|
+ * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
|
|
259
|
+ *
|
|
260
|
+ * Possible values for `mixedContentMode` are:
|
|
261
|
+ *
|
|
262
|
+ * - `'never'` (default) - WebView will not allow a secure origin to load content from an insecure origin.
|
|
263
|
+ * - `'always'` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
|
|
264
|
+ * - `'compatibility'` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
|
|
265
|
+ * @platform android
|
|
266
|
+ */
|
|
267
|
+ mixedContentMode?: 'never' | 'always' | 'compatibility';
|
|
268
|
+ }
|
|
269
|
+ export interface WebViewSharedProps extends ViewProps, IOSWebViewProps, AndroidWebViewProps {
|
|
270
|
+ /**
|
|
271
|
+ * @Deprecated. Use `source` instead.
|
|
272
|
+ */
|
|
273
|
+ url?: string;
|
|
274
|
+ /**
|
|
275
|
+ * @Deprecated. Use `source` instead.
|
|
276
|
+ */
|
|
277
|
+ html?: string;
|
|
278
|
+ /**
|
|
279
|
+ * Loads static html or a uri (with optional headers) in the WebView.
|
|
280
|
+ */
|
|
281
|
+ source?: WebViewSource;
|
|
282
|
+ /**
|
|
283
|
+ * Function that returns a view to show if there's an error.
|
|
284
|
+ */
|
|
285
|
+ renderError?: (errorDomain: string | undefined, errorCode: number, errorDesc: string) => ReactElement<any>;
|
|
286
|
+ /**
|
|
287
|
+ * Function that returns a loading indicator.
|
|
288
|
+ */
|
|
289
|
+ renderLoading?: () => ReactElement<any>;
|
|
290
|
+ /**
|
|
291
|
+ * Function that is invoked when the `WebView` has finished loading.
|
|
292
|
+ */
|
|
293
|
+ onLoad?: (event: WebViewNavigationEvent) => any;
|
|
294
|
+ /**
|
|
295
|
+ * Function that is invoked when the `WebView` load succeeds or fails.
|
|
296
|
+ */
|
|
297
|
+ onLoadEnd?: (event: WebViewNavigationEvent | WebViewErrorEvent) => any;
|
|
298
|
+ /**
|
|
299
|
+ * Function that is invoked when the `WebView` starts loading.
|
|
300
|
+ */
|
|
301
|
+ onLoadStart?: (event: WebViewNavigationEvent) => any;
|
|
302
|
+ /**
|
|
303
|
+ * Function that is invoked when the `WebView` load fails.
|
|
304
|
+ */
|
|
305
|
+ onError?: (event: WebViewErrorEvent) => any;
|
|
306
|
+ /**
|
|
307
|
+ * Controls whether to adjust the content inset for web views that are
|
|
308
|
+ * placed behind a navigation bar, tab bar, or toolbar. The default value
|
|
309
|
+ * is `true`.
|
|
310
|
+ */
|
|
311
|
+ automaticallyAdjustContentInsets?: boolean;
|
|
312
|
+ /**
|
|
313
|
+ * Function that is invoked when the `WebView` loading starts or ends.
|
|
314
|
+ */
|
|
315
|
+ onNavigationStateChange?: (event: WebViewNavigation) => any;
|
|
316
|
+ /**
|
|
317
|
+ * A function that is invoked when the webview calls `window.postMessage`.
|
|
318
|
+ * Setting this property will inject a `postMessage` global into your
|
|
319
|
+ * webview, but will still call pre-existing values of `postMessage`.
|
|
320
|
+ *
|
|
321
|
+ * `window.postMessage` accepts one argument, `data`, which will be
|
|
322
|
+ * available on the event object, `event.nativeEvent.data`. `data`
|
|
323
|
+ * must be a string.
|
|
324
|
+ */
|
|
325
|
+ onMessage?: (event: WebViewMessageEvent) => any;
|
|
326
|
+ /**
|
|
327
|
+ * Function that is invoked when the `WebView` is loading.
|
|
328
|
+ */
|
|
329
|
+ onLoadProgress?: (event: NativeSyntheticEvent<WebViewProgressEvent>) => any;
|
|
330
|
+ /**
|
|
331
|
+ * Boolean value that forces the `WebView` to show the loading view
|
|
332
|
+ * on the first load.
|
|
333
|
+ */
|
|
334
|
+ startInLoadingState?: boolean;
|
|
335
|
+ /**
|
|
336
|
+ * Set this to provide JavaScript that will be injected into the web page
|
|
337
|
+ * when the view loads.
|
|
338
|
+ */
|
|
339
|
+ injectedJavaScript?: string;
|
|
340
|
+ /**
|
|
341
|
+ * Boolean that controls whether the web content is scaled to fit
|
|
342
|
+ * the view and enables the user to change the scale. The default value
|
|
343
|
+ * is `true`.
|
|
344
|
+ *
|
|
345
|
+ * On iOS, when `useWebKit=true`, this prop will not work.
|
|
346
|
+ */
|
|
347
|
+ scalesPageToFit?: boolean;
|
|
348
|
+ /**
|
|
349
|
+ * Boolean that determines whether HTML5 audio and video requires the user
|
|
350
|
+ * to tap them before they start playing. The default value is `true`.
|
|
351
|
+ */
|
|
352
|
+ mediaPlaybackRequiresUserAction?: boolean;
|
|
353
|
+ /**
|
|
354
|
+ * List of origin strings to allow being navigated to. The strings allow
|
|
355
|
+ * wildcards and get matched against *just* the origin (not the full URL).
|
|
356
|
+ * If the user taps to navigate to a new page but the new page is not in
|
|
357
|
+ * this whitelist, we will open the URL in Safari.
|
|
358
|
+ * The default whitelisted origins are "http://*" and "https://*".
|
|
359
|
+ */
|
|
360
|
+ originWhitelist?: string[];
|
|
361
|
+ /**
|
|
362
|
+ * Override the native component used to render the WebView. Enables a custom native
|
|
363
|
+ * WebView which uses the same JavaScript as the original WebView.
|
|
364
|
+ */
|
|
365
|
+ nativeConfig?: WebViewNativeConfig;
|
|
366
|
+ style?: StyleProp<ViewStyle>;
|
|
367
|
+ children?: ReactNode;
|
|
368
|
+ }
|
|
369
|
+}
|
|
370
|
+declare module "src/WebView.android" {
|
|
371
|
+ import React from 'react';
|
|
372
|
+ import { NativeSyntheticEvent } from 'react-native';
|
|
373
|
+ import { WebViewError, WebViewSharedProps, WebViewProgressEvent } from "src/types/WebViewTypes";
|
|
374
|
+ enum WebViewState {
|
|
375
|
+ IDLE = "IDLE",
|
|
376
|
+ LOADING = "LOADING",
|
|
377
|
+ ERROR = "ERROR"
|
|
378
|
+ }
|
|
379
|
+ type State = {
|
|
380
|
+ viewState: WebViewState;
|
|
381
|
+ lastErrorEvent: WebViewError | null;
|
|
382
|
+ };
|
|
383
|
+ /**
|
|
384
|
+ * Renders a native WebView.
|
|
385
|
+ */
|
|
386
|
+ export default class WebView extends React.Component<WebViewSharedProps, State> {
|
|
387
|
+ static defaultProps: {
|
|
388
|
+ overScrollMode: string;
|
|
389
|
+ javaScriptEnabled: boolean;
|
|
390
|
+ thirdPartyCookiesEnabled: boolean;
|
|
391
|
+ scalesPageToFit: boolean;
|
|
392
|
+ allowFileAccess: boolean;
|
|
393
|
+ saveFormDataDisabled: boolean;
|
|
394
|
+ originWhitelist: string[];
|
|
395
|
+ };
|
|
396
|
+ static isFileUploadSupported: () => Promise<boolean>;
|
|
397
|
+ state: State;
|
|
398
|
+ webViewRef: React.RefObject<React.ComponentClass<{}, any>>;
|
|
399
|
+ goForward: () => void;
|
|
400
|
+ goBack: () => void;
|
|
401
|
+ reload: () => void;
|
|
402
|
+ stopLoading: () => void;
|
|
403
|
+ postMessage: (data: string) => void;
|
|
404
|
+ /**
|
|
405
|
+ * Injects a javascript string into the referenced WebView. Deliberately does not
|
|
406
|
+ * return a response because using eval() to return a response breaks this method
|
|
407
|
+ * on pages with a Content Security Policy that disallows eval(). If you need that
|
|
408
|
+ * functionality, look into postMessage/onMessage.
|
|
409
|
+ */
|
|
410
|
+ injectJavaScript: (data: string) => void;
|
|
411
|
+ /**
|
|
412
|
+ * We return an event with a bunch of fields including:
|
|
413
|
+ * url, title, loading, canGoBack, canGoForward
|
|
414
|
+ */
|
|
415
|
+ updateNavigationState: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
|
|
416
|
+ getWebViewHandle: () => number | null;
|
|
417
|
+ onLoadingStart: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
|
|
418
|
+ onLoadingError: (event: NativeSyntheticEvent<WebViewError>) => void;
|
|
419
|
+ onLoadingFinish: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
|
|
420
|
+ onMessage: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewMessage>) => void;
|
|
421
|
+ onLoadingProgress: (event: NativeSyntheticEvent<WebViewProgressEvent>) => void;
|
|
422
|
+ render(): React.ReactNode;
|
|
423
|
+ }
|
|
424
|
+}
|
|
425
|
+declare module "src/WebView.ios" {
|
|
426
|
+ import React from 'react';
|
|
427
|
+ import { NativeSyntheticEvent } from 'react-native';
|
|
428
|
+ import { WebViewError, WebViewSharedProps, WebViewProgressEvent } from "src/types/WebViewTypes";
|
|
429
|
+ enum WebViewState {
|
|
430
|
+ IDLE = "IDLE",
|
|
431
|
+ LOADING = "LOADING",
|
|
432
|
+ ERROR = "ERROR"
|
|
433
|
+ }
|
|
434
|
+ enum NavigationType {
|
|
435
|
+ click = "click",
|
|
436
|
+ formsubmit = "formsubmit",
|
|
437
|
+ backforward = "backforward",
|
|
438
|
+ reload = "reload",
|
|
439
|
+ formresubmit = "formresubmit",
|
|
440
|
+ other = "other"
|
|
441
|
+ }
|
|
442
|
+ type State = {
|
|
443
|
+ viewState: WebViewState;
|
|
444
|
+ lastErrorEvent: WebViewError | null;
|
|
445
|
+ };
|
|
446
|
+ /**
|
|
447
|
+ * `WebView` renders web content in a native view.
|
|
448
|
+ *
|
|
449
|
+ *```
|
|
450
|
+ * import React, { Component } from 'react';
|
|
451
|
+ * import { WebView } from 'react-native';
|
|
452
|
+ *
|
|
453
|
+ * class MyWeb extends Component {
|
|
454
|
+ * render() {
|
|
455
|
+ * return (
|
|
456
|
+ * <WebView
|
|
457
|
+ * source={{uri: 'https://github.com/facebook/react-native'}}
|
|
458
|
+ * style={{marginTop: 20}}
|
|
459
|
+ * />
|
|
460
|
+ * );
|
|
461
|
+ * }
|
|
462
|
+ * }
|
|
463
|
+ *```
|
|
464
|
+ *
|
|
465
|
+ * You can use this component to navigate back and forth in the web view's
|
|
466
|
+ * history and configure various properties for the web content.
|
|
467
|
+ */
|
|
468
|
+ export default class WebView extends React.Component<WebViewSharedProps, State> {
|
|
469
|
+ static JSNavigationScheme: string;
|
|
470
|
+ static NavigationType: typeof NavigationType;
|
|
471
|
+ static defaultProps: {
|
|
472
|
+ useWebKit: boolean;
|
|
473
|
+ originWhitelist: string[];
|
|
474
|
+ };
|
|
475
|
+ static isFileUploadSupported: () => Promise<boolean>;
|
|
476
|
+ state: State;
|
|
477
|
+ webViewRef: React.RefObject<React.ComponentClass<{}, any>>;
|
|
478
|
+ UNSAFE_componentWillMount(): void;
|
|
479
|
+ _getCommands(): {
|
|
480
|
+ goForward: () => void;
|
|
481
|
+ goBack: () => void;
|
|
482
|
+ reload: () => void;
|
|
483
|
+ stopLoading: () => void;
|
|
484
|
+ postMessage: () => void;
|
|
485
|
+ injectJavaScript: () => void;
|
|
486
|
+ };
|
|
487
|
+ /**
|
|
488
|
+ * Go forward one page in the web view's history.
|
|
489
|
+ */
|
|
490
|
+ goForward: () => void;
|
|
491
|
+ /**
|
|
492
|
+ * Go back one page in the web view's history.
|
|
493
|
+ */
|
|
494
|
+ goBack: () => void;
|
|
495
|
+ /**
|
|
496
|
+ * Reloads the current page.
|
|
497
|
+ */
|
|
498
|
+ reload: () => void;
|
|
499
|
+ /**
|
|
500
|
+ * Stop loading the current page.
|
|
501
|
+ */
|
|
502
|
+ stopLoading: () => void;
|
|
503
|
+ /**
|
|
504
|
+ * Posts a message to the web view, which will emit a `message` event.
|
|
505
|
+ * Accepts one argument, `data`, which must be a string.
|
|
506
|
+ *
|
|
507
|
+ * In your webview, you'll need to something like the following.
|
|
508
|
+ *
|
|
509
|
+ * ```js
|
|
510
|
+ * document.addEventListener('message', e => { document.title = e.data; });
|
|
511
|
+ * ```
|
|
512
|
+ */
|
|
513
|
+ postMessage: (data: string) => void;
|
|
514
|
+ /**
|
|
515
|
+ * Injects a javascript string into the referenced WebView. Deliberately does not
|
|
516
|
+ * return a response because using eval() to return a response breaks this method
|
|
517
|
+ * on pages with a Content Security Policy that disallows eval(). If you need that
|
|
518
|
+ * functionality, look into postMessage/onMessage.
|
|
519
|
+ */
|
|
520
|
+ injectJavaScript: (data: string) => void;
|
|
521
|
+ /**
|
|
522
|
+ * We return an event with a bunch of fields including:
|
|
523
|
+ * url, title, loading, canGoBack, canGoForward
|
|
524
|
+ */
|
|
525
|
+ _updateNavigationState: (event: NativeSyntheticEvent<import("src/types/WebViewTypes").WebViewNavigation>) => void;
|
|
526
|
+ /**
|
|
527
|
+ * Returns the native `WebView` node.
|
|
528
|
+ */
|
|
529
|
+ 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;
|
|
537
|
+ render(): React.ReactNode;
|
|
538
|
+ }
|
|
539
|
+}
|
|
540
|
+declare module "index" {
|
|
541
|
+ import WebViewIOS from "src/WebView.ios";
|
|
542
|
+ import WebViewAndroid from "src/WebView.android";
|
|
543
|
+ const WebView: typeof WebViewAndroid | typeof WebViewIOS;
|
|
544
|
+ export { WebView };
|
|
545
|
+ export default WebView;
|
|
546
|
+}
|