No Description

WebViewTypes.ts 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /* eslint-disable react/no-multi-comp, max-classes-per-file */
  2. import { ReactElement, Component } from 'react';
  3. import {
  4. NativeSyntheticEvent,
  5. ViewProps,
  6. StyleProp,
  7. ViewStyle,
  8. NativeMethodsMixin,
  9. Constructor,
  10. UIManagerStatic,
  11. NativeScrollEvent,
  12. } from 'react-native';
  13. type WebViewCommands = 'goForward' | 'goBack' | 'reload' | 'stopLoading' | 'postMessage' | 'injectJavaScript' | 'loadUrl' | 'requestFocus';
  14. type AndroidWebViewCommands = 'clearHistory' | 'clearCache' | 'clearFormData';
  15. interface RNCWebViewUIManager<Commands extends string> extends UIManagerStatic {
  16. getViewManagerConfig: (
  17. name: string,
  18. ) => {
  19. Commands: {[key in Commands]: number};
  20. };
  21. }
  22. export type RNCWebViewUIManagerAndroid = RNCWebViewUIManager<WebViewCommands | AndroidWebViewCommands>
  23. export type RNCWebViewUIManagerIOS = RNCWebViewUIManager<WebViewCommands>
  24. type WebViewState = 'IDLE' | 'LOADING' | 'ERROR';
  25. interface BaseState {
  26. viewState: WebViewState;
  27. }
  28. interface NormalState extends BaseState {
  29. viewState: 'IDLE' | 'LOADING';
  30. lastErrorEvent: WebViewError | null;
  31. }
  32. interface ErrorState extends BaseState {
  33. viewState: 'ERROR';
  34. lastErrorEvent: WebViewError;
  35. }
  36. export type State = NormalState | ErrorState;
  37. // eslint-disable-next-line react/prefer-stateless-function
  38. declare class NativeWebViewIOSComponent extends Component<
  39. IOSNativeWebViewProps
  40. > {}
  41. declare const NativeWebViewIOSBase: Constructor<NativeMethodsMixin> &
  42. typeof NativeWebViewIOSComponent;
  43. export class NativeWebViewIOS extends NativeWebViewIOSBase {}
  44. // eslint-disable-next-line react/prefer-stateless-function
  45. declare class NativeWebViewAndroidComponent extends Component<
  46. AndroidNativeWebViewProps
  47. > {}
  48. declare const NativeWebViewAndroidBase: Constructor<NativeMethodsMixin> &
  49. typeof NativeWebViewAndroidComponent;
  50. export class NativeWebViewAndroid extends NativeWebViewAndroidBase {}
  51. export interface ContentInsetProp {
  52. top?: number;
  53. left?: number;
  54. bottom?: number;
  55. right?: number;
  56. }
  57. export interface WebViewNativeEvent {
  58. url: string;
  59. loading: boolean;
  60. title: string;
  61. canGoBack: boolean;
  62. canGoForward: boolean;
  63. lockIdentifier: number;
  64. }
  65. export interface WebViewNativeProgressEvent extends WebViewNativeEvent {
  66. progress: number;
  67. }
  68. export interface WebViewNavigation extends WebViewNativeEvent {
  69. navigationType:
  70. | 'click'
  71. | 'formsubmit'
  72. | 'backforward'
  73. | 'reload'
  74. | 'formresubmit'
  75. | 'other';
  76. mainDocumentURL?: string;
  77. }
  78. export type DecelerationRateConstant = 'normal' | 'fast';
  79. export interface WebViewMessage extends WebViewNativeEvent {
  80. data: string;
  81. }
  82. export interface WebViewError extends WebViewNativeEvent {
  83. /**
  84. * `domain` is only used on iOS
  85. */
  86. domain?: string;
  87. code: number;
  88. description: string;
  89. }
  90. export interface WebViewHttpError extends WebViewNativeEvent {
  91. description: string;
  92. statusCode: number;
  93. }
  94. export type WebViewEvent = NativeSyntheticEvent<WebViewNativeEvent>;
  95. export type WebViewProgressEvent = NativeSyntheticEvent<
  96. WebViewNativeProgressEvent
  97. >;
  98. export type WebViewNavigationEvent = NativeSyntheticEvent<WebViewNavigation>;
  99. export type WebViewMessageEvent = NativeSyntheticEvent<WebViewMessage>;
  100. export type WebViewErrorEvent = NativeSyntheticEvent<WebViewError>;
  101. export type WebViewTerminatedEvent = NativeSyntheticEvent<WebViewNativeEvent>;
  102. export type WebViewHttpErrorEvent = NativeSyntheticEvent<WebViewHttpError>;
  103. export type DataDetectorTypes =
  104. | 'phoneNumber'
  105. | 'link'
  106. | 'address'
  107. | 'calendarEvent'
  108. | 'trackingNumber'
  109. | 'flightNumber'
  110. | 'lookupSuggestion'
  111. | 'none'
  112. | 'all';
  113. export type OverScrollModeType = 'always' | 'content' | 'never';
  114. export type CacheMode = 'LOAD_DEFAULT' | 'LOAD_CACHE_ONLY' | 'LOAD_CACHE_ELSE_NETWORK' | 'LOAD_NO_CACHE';
  115. export interface WebViewSourceUri {
  116. /**
  117. * The URI to load in the `WebView`. Can be a local or remote file.
  118. */
  119. uri: string;
  120. /**
  121. * The HTTP Method to use. Defaults to GET if not specified.
  122. * NOTE: On Android, only GET and POST are supported.
  123. */
  124. method?: string;
  125. /**
  126. * Additional HTTP headers to send with the request.
  127. * NOTE: On Android, this can only be used with GET requests.
  128. */
  129. headers?: Object;
  130. /**
  131. * The HTTP body to send with the request. This must be a valid
  132. * UTF-8 string, and will be sent exactly as specified, with no
  133. * additional encoding (e.g. URL-escaping or base64) applied.
  134. * NOTE: On Android, this can only be used with POST requests.
  135. */
  136. body?: string;
  137. }
  138. export interface WebViewSourceHtml {
  139. /**
  140. * A static HTML page to display in the WebView.
  141. */
  142. html: string;
  143. /**
  144. * The base URL to be used for any relative links in the HTML.
  145. */
  146. baseUrl?: string;
  147. }
  148. export type WebViewSource = WebViewSourceUri | WebViewSourceHtml;
  149. export interface ViewManager {
  150. startLoadWithResult: Function;
  151. }
  152. export interface WebViewNativeConfig {
  153. /**
  154. * The native component used to render the WebView.
  155. */
  156. component?: typeof NativeWebViewIOS | typeof NativeWebViewAndroid;
  157. /**
  158. * Set props directly on the native component WebView. Enables custom props which the
  159. * original WebView doesn't pass through.
  160. */
  161. props?: Object;
  162. /**
  163. * Set the ViewManager to use for communication with the native side.
  164. * @platform ios
  165. */
  166. viewManager?: ViewManager;
  167. }
  168. export type OnShouldStartLoadWithRequest = (
  169. event: WebViewNavigation,
  170. ) => boolean;
  171. export interface CommonNativeWebViewProps extends ViewProps {
  172. cacheEnabled?: boolean;
  173. incognito?: boolean;
  174. injectedJavaScript?: string;
  175. injectedJavaScriptBeforeContentLoaded?: string;
  176. mediaPlaybackRequiresUserAction?: boolean;
  177. messagingEnabled: boolean;
  178. onScroll?: (event: NativeScrollEvent) => void;
  179. onLoadingError: (event: WebViewErrorEvent) => void;
  180. onLoadingFinish: (event: WebViewNavigationEvent) => void;
  181. onLoadingProgress: (event: WebViewProgressEvent) => void;
  182. onLoadingStart: (event: WebViewNavigationEvent) => void;
  183. onHttpError: (event: WebViewHttpErrorEvent) => void;
  184. onMessage: (event: WebViewMessageEvent) => void;
  185. onShouldStartLoadWithRequest: (event: WebViewNavigationEvent) => void;
  186. showsHorizontalScrollIndicator?: boolean;
  187. showsVerticalScrollIndicator?: boolean;
  188. // TODO: find a better way to type this.
  189. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  190. source: any;
  191. userAgent?: string;
  192. /**
  193. * Append to the existing user-agent. Overriden if `userAgent` is set.
  194. */
  195. applicationNameForUserAgent?: string;
  196. }
  197. export interface AndroidNativeWebViewProps extends CommonNativeWebViewProps {
  198. cacheMode?: CacheMode;
  199. allowFileAccess?: boolean;
  200. scalesPageToFit?: boolean;
  201. allowFileAccessFromFileURLs?: boolean;
  202. allowUniversalAccessFromFileURLs?: boolean;
  203. androidHardwareAccelerationDisabled?: boolean;
  204. domStorageEnabled?: boolean;
  205. geolocationEnabled?: boolean;
  206. javaScriptEnabled?: boolean;
  207. mixedContentMode?: 'never' | 'always' | 'compatibility';
  208. onContentSizeChange?: (event: WebViewEvent) => void;
  209. overScrollMode?: OverScrollModeType;
  210. saveFormDataDisabled?: boolean;
  211. textZoom?: number;
  212. thirdPartyCookiesEnabled?: boolean;
  213. urlPrefixesForDefaultIntent?: readonly string[];
  214. }
  215. export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
  216. allowingReadAccessToURL?: string;
  217. allowsBackForwardNavigationGestures?: boolean;
  218. allowsInlineMediaPlayback?: boolean;
  219. allowsLinkPreview?: boolean;
  220. automaticallyAdjustContentInsets?: boolean;
  221. bounces?: boolean;
  222. contentInset?: ContentInsetProp;
  223. contentInsetAdjustmentBehavior?:
  224. | 'automatic'
  225. | 'scrollableAxes'
  226. | 'never'
  227. | 'always';
  228. dataDetectorTypes?: DataDetectorTypes | readonly DataDetectorTypes[];
  229. decelerationRate?: number;
  230. directionalLockEnabled?: boolean;
  231. hideKeyboardAccessoryView?: boolean;
  232. pagingEnabled?: boolean;
  233. scrollEnabled?: boolean;
  234. useSharedProcessPool?: boolean;
  235. onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
  236. }
  237. export interface IOSWebViewProps extends WebViewSharedProps {
  238. /**
  239. * Does not store any data within the lifetime of the WebView.
  240. */
  241. incognito?: boolean;
  242. /**
  243. * Boolean value that determines whether the web view bounces
  244. * when it reaches the edge of the content. The default value is `true`.
  245. * @platform ios
  246. */
  247. bounces?: boolean;
  248. /**
  249. * A floating-point number that determines how quickly the scroll view
  250. * decelerates after the user lifts their finger. You may also use the
  251. * string shortcuts `"normal"` and `"fast"` which match the underlying iOS
  252. * settings for `UIScrollViewDecelerationRateNormal` and
  253. * `UIScrollViewDecelerationRateFast` respectively:
  254. *
  255. * - normal: 0.998
  256. * - fast: 0.99 (the default for iOS web view)
  257. * @platform ios
  258. */
  259. decelerationRate?: DecelerationRateConstant | number;
  260. /**
  261. * Boolean value that determines whether scrolling is enabled in the
  262. * `WebView`. The default value is `true`.
  263. * @platform ios
  264. */
  265. scrollEnabled?: boolean;
  266. /**
  267. * If the value of this property is true, the scroll view stops on multiples
  268. * of the scroll view’s bounds when the user scrolls.
  269. * The default value is false.
  270. * @platform ios
  271. */
  272. pagingEnabled?: boolean;
  273. /**
  274. * Controls whether to adjust the content inset for web views that are
  275. * placed behind a navigation bar, tab bar, or toolbar. The default value
  276. * is `true`.
  277. * @platform ios
  278. */
  279. automaticallyAdjustContentInsets?: boolean;
  280. /**
  281. * This property specifies how the safe area insets are used to modify the
  282. * content area of the scroll view. The default value of this property is
  283. * "never". Available on iOS 11 and later.
  284. */
  285. contentInsetAdjustmentBehavior?:
  286. | 'automatic'
  287. | 'scrollableAxes'
  288. | 'never'
  289. | 'always';
  290. /**
  291. * The amount by which the web view content is inset from the edges of
  292. * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
  293. * @platform ios
  294. */
  295. contentInset?: ContentInsetProp;
  296. /**
  297. * Determines the types of data converted to clickable URLs in the web view's content.
  298. * By default only phone numbers are detected.
  299. *
  300. * You can provide one type or an array of many types.
  301. *
  302. * Possible values for `dataDetectorTypes` are:
  303. *
  304. * - `'phoneNumber'`
  305. * - `'link'`
  306. * - `'address'`
  307. * - `'calendarEvent'`
  308. * - `'none'`
  309. * - `'all'`
  310. *
  311. * With the new WebKit implementation, we have three new values:
  312. * - `'trackingNumber'`,
  313. * - `'flightNumber'`,
  314. * - `'lookupSuggestion'`,
  315. *
  316. * @platform ios
  317. */
  318. dataDetectorTypes?: DataDetectorTypes | readonly DataDetectorTypes[];
  319. /**
  320. * Boolean that determines whether HTML5 videos play inline or use the
  321. * native full-screen controller. The default value is `false`.
  322. *
  323. * **NOTE** : In order for video to play inline, not only does this
  324. * property need to be set to `true`, but the video element in the HTML
  325. * document must also include the `webkit-playsinline` attribute.
  326. * @platform ios
  327. */
  328. allowsInlineMediaPlayback?: boolean;
  329. /**
  330. * Hide the accessory view when the keyboard is open. Default is false to be
  331. * backward compatible.
  332. */
  333. hideKeyboardAccessoryView?: boolean;
  334. /**
  335. * A Boolean value indicating whether horizontal swipe gestures will trigger
  336. * back-forward list navigations.
  337. */
  338. allowsBackForwardNavigationGestures?: boolean;
  339. /**
  340. * A Boolean value indicating whether WebKit WebView should be created using a shared
  341. * process pool, enabling WebViews to share cookies and localStorage between each other.
  342. * Default is true but can be set to false for backwards compatibility.
  343. * @platform ios
  344. */
  345. useSharedProcessPool?: boolean;
  346. /**
  347. * The custom user agent string.
  348. */
  349. userAgent?: string;
  350. /**
  351. * A Boolean value that determines whether pressing on a link
  352. * displays a preview of the destination for the link.
  353. *
  354. * This property is available on devices that support 3D Touch.
  355. * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
  356. * @platform ios
  357. */
  358. allowsLinkPreview?: boolean;
  359. /**
  360. * Set true if shared cookies from HTTPCookieStorage should used for every load request.
  361. * The default value is `false`.
  362. * @platform ios
  363. */
  364. sharedCookiesEnabled?: boolean;
  365. /**
  366. * A Boolean value that determines whether scrolling is disabled in a particular direction.
  367. * The default value is `true`.
  368. * @platform ios
  369. */
  370. directionalLockEnabled?: boolean;
  371. /**
  372. * A Boolean value indicating whether web content can programmatically display the keyboard.
  373. *
  374. * When this property is set to true, the user must explicitly tap the elements in the
  375. * web view to display the keyboard (or other relevant input view) for that element.
  376. * When set to false, a focus event on an element causes the input view to be displayed
  377. * and associated with that element automatically.
  378. *
  379. * The default value is `true`.
  380. * @platform ios
  381. */
  382. keyboardDisplayRequiresUserAction?: boolean;
  383. /**
  384. * A String value that indicates which URLs the WebView's file can then
  385. * reference in scripts, AJAX requests, and CSS imports. This is only used
  386. * for WebViews that are loaded with a source.uri set to a `'file://'` URL.
  387. *
  388. * If not provided, the default is to only allow read access to the URL
  389. * provided in source.uri itself.
  390. * @platform ios
  391. */
  392. allowingReadAccessToURL?: string;
  393. /**
  394. * Function that is invoked when the WebKit WebView content process gets terminated.
  395. * @platform ios
  396. */
  397. onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
  398. }
  399. export interface AndroidWebViewProps extends WebViewSharedProps {
  400. onNavigationStateChange?: (event: WebViewNavigation) => void;
  401. onContentSizeChange?: (event: WebViewEvent) => void;
  402. /**
  403. * https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
  404. * Set the cacheMode. Possible values are:
  405. *
  406. * - `'LOAD_DEFAULT'` (default)
  407. * - `'LOAD_CACHE_ELSE_NETWORK'`
  408. * - `'LOAD_NO_CACHE'`
  409. * - `'LOAD_CACHE_ONLY'`
  410. *
  411. * @platform android
  412. */
  413. cacheMode?: CacheMode;
  414. /**
  415. * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
  416. * Sets the overScrollMode. Possible values are:
  417. *
  418. * - `'always'` (default)
  419. * - `'content'`
  420. * - `'never'`
  421. *
  422. * @platform android
  423. */
  424. overScrollMode?: OverScrollModeType;
  425. /**
  426. * Boolean that controls whether the web content is scaled to fit
  427. * the view and enables the user to change the scale. The default value
  428. * is `true`.
  429. */
  430. scalesPageToFit?: boolean;
  431. /**
  432. * Sets whether Geolocation is enabled. The default is false.
  433. * @platform android
  434. */
  435. geolocationEnabled?: boolean;
  436. /**
  437. * Boolean that sets whether JavaScript running in the context of a file
  438. * scheme URL should be allowed to access content from other file scheme URLs.
  439. * Including accessing content from other file scheme URLs
  440. * @platform android
  441. */
  442. allowFileAccessFromFileURLs?: boolean;
  443. /**
  444. * Boolean that sets whether JavaScript running in the context of a file
  445. * scheme URL should be allowed to access content from any origin.
  446. * Including accessing content from other file scheme URLs
  447. * @platform android
  448. */
  449. allowUniversalAccessFromFileURLs?: boolean;
  450. /**
  451. * Sets whether the webview allow access to file system.
  452. * @platform android
  453. */
  454. allowFileAccess?: boolean;
  455. /**
  456. * Used on Android only, controls whether form autocomplete data should be saved
  457. * @platform android
  458. */
  459. saveFormDataDisabled?: boolean;
  460. /**
  461. * Used on Android only, controls whether the given list of URL prefixes should
  462. * make {@link com.facebook.react.views.webview.ReactWebViewClient} to launch a
  463. * default activity intent for those URL instead of loading it within the webview.
  464. * Use this to list URLs that WebView cannot handle, e.g. a PDF url.
  465. * @platform android
  466. */
  467. urlPrefixesForDefaultIntent?: readonly string[];
  468. /**
  469. * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
  470. * as Hardware Acceleration is a feature only for Android. The default value is `false`.
  471. * @platform android
  472. */
  473. androidHardwareAccelerationDisabled?: boolean;
  474. /**
  475. * Boolean value to enable third party cookies in the `WebView`. Used on
  476. * Android Lollipop and above only as third party cookies are enabled by
  477. * default on Android Kitkat and below and on iOS. The default value is `true`.
  478. * @platform android
  479. */
  480. thirdPartyCookiesEnabled?: boolean;
  481. /**
  482. * Boolean value to control whether DOM Storage is enabled. Used only in
  483. * Android.
  484. * @platform android
  485. */
  486. domStorageEnabled?: boolean;
  487. /**
  488. * Sets the user-agent for the `WebView`.
  489. * @platform android
  490. */
  491. userAgent?: string;
  492. /**
  493. * Sets number that controls text zoom of the page in percent.
  494. * @platform android
  495. */
  496. textZoom?: number;
  497. /**
  498. * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
  499. *
  500. * Possible values for `mixedContentMode` are:
  501. *
  502. * - `'never'` (default) - WebView will not allow a secure origin to load content from an insecure origin.
  503. * - `'always'` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
  504. * - `'compatibility'` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
  505. * @platform android
  506. */
  507. mixedContentMode?: 'never' | 'always' | 'compatibility';
  508. /**
  509. * Sets ability to open fullscreen videos on Android devices.
  510. */
  511. allowsFullscreenVideo?: boolean;
  512. }
  513. export interface WebViewSharedProps extends ViewProps {
  514. /**
  515. * Loads static html or a uri (with optional headers) in the WebView.
  516. */
  517. source?: WebViewSource;
  518. /**
  519. * Boolean value to enable JavaScript in the `WebView`. Used on Android only
  520. * as JavaScript is enabled by default on iOS. The default value is `true`.
  521. * @platform android
  522. */
  523. javaScriptEnabled?: boolean;
  524. /**
  525. * Stylesheet object to set the style of the container view.
  526. */
  527. containerStyle?: StyleProp<ViewStyle>;
  528. /**
  529. * Function that returns a view to show if there's an error.
  530. */
  531. renderError?: (
  532. errorDomain: string | undefined,
  533. errorCode: number,
  534. errorDesc: string,
  535. ) => ReactElement; // view to show if there's an error
  536. /**
  537. * Function that returns a loading indicator.
  538. */
  539. renderLoading?: () => ReactElement;
  540. /**
  541. * Function that is invoked when the `WebView` scrolls.
  542. */
  543. onScroll?: (event: NativeScrollEvent) => void;
  544. /**
  545. * Function that is invoked when the `WebView` has finished loading.
  546. */
  547. onLoad?: (event: WebViewNavigationEvent) => void;
  548. /**
  549. * Function that is invoked when the `WebView` load succeeds or fails.
  550. */
  551. onLoadEnd?: (event: WebViewNavigationEvent | WebViewErrorEvent) => void;
  552. /**
  553. * Function that is invoked when the `WebView` starts loading.
  554. */
  555. onLoadStart?: (event: WebViewNavigationEvent) => void;
  556. /**
  557. * Function that is invoked when the `WebView` load fails.
  558. */
  559. onError?: (event: WebViewErrorEvent) => void;
  560. /**
  561. * Function that is invoked when the `WebView` receives an error status code.
  562. * Works on iOS and Android (minimum API level 23).
  563. */
  564. onHttpError?: (event: WebViewHttpErrorEvent) => void;
  565. /**
  566. * Function that is invoked when the `WebView` loading starts or ends.
  567. */
  568. onNavigationStateChange?: (event: WebViewNavigation) => void;
  569. /**
  570. * Function that is invoked when the webview calls `window.ReactNativeWebView.postMessage`.
  571. * Setting this property will inject this global into your webview.
  572. *
  573. * `window.ReactNativeWebView.postMessage` accepts one argument, `data`, which will be
  574. * available on the event object, `event.nativeEvent.data`. `data` must be a string.
  575. */
  576. onMessage?: (event: WebViewMessageEvent) => void;
  577. /**
  578. * Function that is invoked when the `WebView` is loading.
  579. */
  580. onLoadProgress?: (event: WebViewProgressEvent) => void;
  581. /**
  582. * Boolean value that forces the `WebView` to show the loading view
  583. * on the first load.
  584. */
  585. startInLoadingState?: boolean;
  586. /**
  587. * Set this to provide JavaScript that will be injected into the web page
  588. * when the view loads.
  589. */
  590. injectedJavaScript?: string;
  591. /**
  592. * Set this to provide JavaScript that will be injected into the web page
  593. * once the webview is initialized but before the view loads any content.
  594. */
  595. injectedJavaScriptBeforeContentLoaded?: string;
  596. /**
  597. * Boolean value that determines whether a horizontal scroll indicator is
  598. * shown in the `WebView`. The default value is `true`.
  599. */
  600. showsHorizontalScrollIndicator?: boolean;
  601. /**
  602. * Boolean value that determines whether a vertical scroll indicator is
  603. * shown in the `WebView`. The default value is `true`.
  604. */
  605. showsVerticalScrollIndicator?: boolean;
  606. /**
  607. * Boolean that determines whether HTML5 audio and video requires the user
  608. * to tap them before they start playing. The default value is `true`.
  609. */
  610. mediaPlaybackRequiresUserAction?: boolean;
  611. /**
  612. * List of origin strings to allow being navigated to. The strings allow
  613. * wildcards and get matched against *just* the origin (not the full URL).
  614. * If the user taps to navigate to a new page but the new page is not in
  615. * this whitelist, we will open the URL in Safari.
  616. * The default whitelisted origins are "http://*" and "https://*".
  617. */
  618. originWhitelist?: readonly string[];
  619. /**
  620. * Function that allows custom handling of any web view requests. Return
  621. * `true` from the function to continue loading the request and `false`
  622. * to stop loading. The `navigationType` is always `other` on android.
  623. */
  624. onShouldStartLoadWithRequest?: OnShouldStartLoadWithRequest;
  625. /**
  626. * Override the native component used to render the WebView. Enables a custom native
  627. * WebView which uses the same JavaScript as the original WebView.
  628. */
  629. nativeConfig?: WebViewNativeConfig;
  630. /**
  631. * Should caching be enabled. Default is true.
  632. */
  633. cacheEnabled?: boolean;
  634. }