react-native-webview.git

WebViewTypes.ts 27KB

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