react-native-webview.git

WebViewTypes.ts 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. injectedJavaScriptForMainFrameOnly?: boolean;
  247. injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
  248. }
  249. export interface MacOSNativeWebViewProps extends CommonNativeWebViewProps {
  250. allowingReadAccessToURL?: string;
  251. allowsBackForwardNavigationGestures?: boolean;
  252. allowsInlineMediaPlayback?: boolean;
  253. allowsLinkPreview?: boolean;
  254. automaticallyAdjustContentInsets?: boolean;
  255. bounces?: boolean;
  256. contentInset?: ContentInsetProp;
  257. contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
  258. directionalLockEnabled?: boolean;
  259. hideKeyboardAccessoryView?: boolean;
  260. pagingEnabled?: boolean;
  261. scrollEnabled?: boolean;
  262. useSharedProcessPool?: boolean;
  263. onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
  264. }
  265. export interface IOSWebViewProps extends WebViewSharedProps {
  266. /**
  267. * Does not store any data within the lifetime of the WebView.
  268. */
  269. incognito?: boolean;
  270. /**
  271. * Boolean value that determines whether the web view bounces
  272. * when it reaches the edge of the content. The default value is `true`.
  273. * @platform ios
  274. */
  275. bounces?: boolean;
  276. /**
  277. * A floating-point number that determines how quickly the scroll view
  278. * decelerates after the user lifts their finger. You may also use the
  279. * string shortcuts `"normal"` and `"fast"` which match the underlying iOS
  280. * settings for `UIScrollViewDecelerationRateNormal` and
  281. * `UIScrollViewDecelerationRateFast` respectively:
  282. *
  283. * - normal: 0.998
  284. * - fast: 0.99 (the default for iOS web view)
  285. * @platform ios
  286. */
  287. decelerationRate?: DecelerationRateConstant | number;
  288. /**
  289. * Boolean value that determines whether scrolling is enabled in the
  290. * `WebView`. The default value is `true`.
  291. * @platform ios
  292. */
  293. scrollEnabled?: boolean;
  294. /**
  295. * If the value of this property is true, the scroll view stops on multiples
  296. * of the scroll view’s bounds when the user scrolls.
  297. * The default value is false.
  298. * @platform ios
  299. */
  300. pagingEnabled?: boolean;
  301. /**
  302. * Controls whether to adjust the content inset for web views that are
  303. * placed behind a navigation bar, tab bar, or toolbar. The default value
  304. * is `true`.
  305. * @platform ios
  306. */
  307. automaticallyAdjustContentInsets?: boolean;
  308. /**
  309. * This property specifies how the safe area insets are used to modify the
  310. * content area of the scroll view. The default value of this property is
  311. * "never". Available on iOS 11 and later.
  312. */
  313. contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
  314. /**
  315. * The amount by which the web view content is inset from the edges of
  316. * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
  317. * @platform ios
  318. */
  319. contentInset?: ContentInsetProp;
  320. /**
  321. * Determines the types of data converted to clickable URLs in the web view's content.
  322. * By default only phone numbers are detected.
  323. *
  324. * You can provide one type or an array of many types.
  325. *
  326. * Possible values for `dataDetectorTypes` are:
  327. *
  328. * - `'phoneNumber'`
  329. * - `'link'`
  330. * - `'address'`
  331. * - `'calendarEvent'`
  332. * - `'none'`
  333. * - `'all'`
  334. *
  335. * With the new WebKit implementation, we have three new values:
  336. * - `'trackingNumber'`,
  337. * - `'flightNumber'`,
  338. * - `'lookupSuggestion'`,
  339. *
  340. * @platform ios
  341. */
  342. dataDetectorTypes?: DataDetectorTypes | readonly DataDetectorTypes[];
  343. /**
  344. * Boolean that determines whether HTML5 videos play inline or use the
  345. * native full-screen controller. The default value is `false`.
  346. *
  347. * **NOTE** : In order for video to play inline, not only does this
  348. * property need to be set to `true`, but the video element in the HTML
  349. * document must also include the `webkit-playsinline` attribute.
  350. * @platform ios
  351. */
  352. allowsInlineMediaPlayback?: boolean;
  353. /**
  354. * Hide the accessory view when the keyboard is open. Default is false to be
  355. * backward compatible.
  356. */
  357. hideKeyboardAccessoryView?: boolean;
  358. /**
  359. * A Boolean value indicating whether horizontal swipe gestures will trigger
  360. * back-forward list navigations.
  361. */
  362. allowsBackForwardNavigationGestures?: boolean;
  363. /**
  364. * A Boolean value indicating whether WebKit WebView should be created using a shared
  365. * process pool, enabling WebViews to share cookies and localStorage between each other.
  366. * Default is true but can be set to false for backwards compatibility.
  367. * @platform ios
  368. */
  369. useSharedProcessPool?: boolean;
  370. /**
  371. * The custom user agent string.
  372. */
  373. userAgent?: string;
  374. /**
  375. * A Boolean value that determines whether pressing on a link
  376. * displays a preview of the destination for the link.
  377. *
  378. * This property is available on devices that support 3D Touch.
  379. * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
  380. * @platform ios
  381. */
  382. allowsLinkPreview?: boolean;
  383. /**
  384. * Set true if shared cookies from HTTPCookieStorage should used for every load request.
  385. * The default value is `false`.
  386. * @platform ios
  387. */
  388. sharedCookiesEnabled?: boolean;
  389. /**
  390. * A Boolean value that determines whether scrolling is disabled in a particular direction.
  391. * The default value is `true`.
  392. * @platform ios
  393. */
  394. directionalLockEnabled?: boolean;
  395. /**
  396. * A Boolean value indicating whether web content can programmatically display the keyboard.
  397. *
  398. * When this property is set to true, the user must explicitly tap the elements in the
  399. * web view to display the keyboard (or other relevant input view) for that element.
  400. * When set to false, a focus event on an element causes the input view to be displayed
  401. * and associated with that element automatically.
  402. *
  403. * The default value is `true`.
  404. * @platform ios
  405. */
  406. keyboardDisplayRequiresUserAction?: boolean;
  407. /**
  408. * A String value that indicates which URLs the WebView's file can then
  409. * reference in scripts, AJAX requests, and CSS imports. This is only used
  410. * for WebViews that are loaded with a source.uri set to a `'file://'` URL.
  411. *
  412. * If not provided, the default is to only allow read access to the URL
  413. * provided in source.uri itself.
  414. * @platform ios
  415. */
  416. allowingReadAccessToURL?: string;
  417. /**
  418. * Function that is invoked when the WebKit WebView content process gets terminated.
  419. * @platform ios
  420. */
  421. onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
  422. /**
  423. * If `true` (default), loads the `injectedJavaScript` only into the main frame.
  424. * If `false`, loads it into all frames (e.g. iframes).
  425. * @platform ios
  426. */
  427. injectedJavaScriptForMainFrameOnly?: boolean;
  428. /**
  429. * If `true` (default), loads the `injectedJavaScriptBeforeContentLoaded` only into the main frame.
  430. * If `false`, loads it into all frames (e.g. iframes).
  431. * @platform ios
  432. */
  433. injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
  434. }
  435. export interface MacOSWebViewProps extends WebViewSharedProps {
  436. /**
  437. * Does not store any data within the lifetime of the WebView.
  438. */
  439. incognito?: boolean;
  440. /**
  441. * Boolean value that determines whether the web view bounces
  442. * when it reaches the edge of the content. The default value is `true`.
  443. * @platform macos
  444. */
  445. bounces?: boolean;
  446. /**
  447. * Boolean value that determines whether scrolling is enabled in the
  448. * `WebView`. The default value is `true`.
  449. * @platform macos
  450. */
  451. scrollEnabled?: boolean;
  452. /**
  453. * If the value of this property is true, the scroll view stops on multiples
  454. * of the scroll view’s bounds when the user scrolls.
  455. * The default value is false.
  456. * @platform macos
  457. */
  458. pagingEnabled?: boolean;
  459. /**
  460. * Controls whether to adjust the content inset for web views that are
  461. * placed behind a navigation bar, tab bar, or toolbar. The default value
  462. * is `true`.
  463. * @platform macos
  464. */
  465. automaticallyAdjustContentInsets?: boolean;
  466. /**
  467. * This property specifies how the safe area insets are used to modify the
  468. * content area of the scroll view. The default value of this property is
  469. * "never". Available on iOS 11 and later.
  470. */
  471. contentInsetAdjustmentBehavior?: ContentInsetAdjustmentBehavior;
  472. /**
  473. * The amount by which the web view content is inset from the edges of
  474. * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
  475. * @platform macos
  476. */
  477. contentInset?: ContentInsetProp;
  478. /**
  479. * Boolean that determines whether HTML5 videos play inline or use the
  480. * native full-screen controller. The default value is `false`.
  481. *
  482. * **NOTE** : In order for video to play inline, not only does this
  483. * property need to be set to `true`, but the video element in the HTML
  484. * document must also include the `webkit-playsinline` attribute.
  485. * @platform macos
  486. */
  487. allowsInlineMediaPlayback?: boolean;
  488. /**
  489. * Hide the accessory view when the keyboard is open. Default is false to be
  490. * backward compatible.
  491. */
  492. hideKeyboardAccessoryView?: boolean;
  493. /**
  494. * A Boolean value indicating whether horizontal swipe gestures will trigger
  495. * back-forward list navigations.
  496. */
  497. allowsBackForwardNavigationGestures?: boolean;
  498. /**
  499. * A Boolean value indicating whether WebKit WebView should be created using a shared
  500. * process pool, enabling WebViews to share cookies and localStorage between each other.
  501. * Default is true but can be set to false for backwards compatibility.
  502. * @platform macos
  503. */
  504. useSharedProcessPool?: boolean;
  505. /**
  506. * The custom user agent string.
  507. */
  508. userAgent?: string;
  509. /**
  510. * A Boolean value that determines whether pressing on a link
  511. * displays a preview of the destination for the link.
  512. *
  513. * This property is available on devices that support Force Touch trackpad.
  514. * @platform macos
  515. */
  516. allowsLinkPreview?: boolean;
  517. /**
  518. * Set true if shared cookies from HTTPCookieStorage should used for every load request.
  519. * The default value is `false`.
  520. * @platform macos
  521. */
  522. sharedCookiesEnabled?: boolean;
  523. /**
  524. * A Boolean value that determines whether scrolling is disabled in a particular direction.
  525. * The default value is `true`.
  526. * @platform macos
  527. */
  528. directionalLockEnabled?: boolean;
  529. /**
  530. * A Boolean value indicating whether web content can programmatically display the keyboard.
  531. *
  532. * When this property is set to true, the user must explicitly tap the elements in the
  533. * web view to display the keyboard (or other relevant input view) for that element.
  534. * When set to false, a focus event on an element causes the input view to be displayed
  535. * and associated with that element automatically.
  536. *
  537. * The default value is `true`.
  538. * @platform macos
  539. */
  540. keyboardDisplayRequiresUserAction?: boolean;
  541. /**
  542. * A String value that indicates which URLs the WebView's file can then
  543. * reference in scripts, AJAX requests, and CSS imports. This is only used
  544. * for WebViews that are loaded with a source.uri set to a `'file://'` URL.
  545. *
  546. * If not provided, the default is to only allow read access to the URL
  547. * provided in source.uri itself.
  548. * @platform macos
  549. */
  550. allowingReadAccessToURL?: string;
  551. /**
  552. * Function that is invoked when the WebKit WebView content process gets terminated.
  553. * @platform macos
  554. */
  555. onContentProcessDidTerminate?: (event: WebViewTerminatedEvent) => void;
  556. }
  557. export interface AndroidWebViewProps extends WebViewSharedProps {
  558. onNavigationStateChange?: (event: WebViewNavigation) => void;
  559. onContentSizeChange?: (event: WebViewEvent) => void;
  560. /**
  561. * https://developer.android.com/reference/android/webkit/WebSettings.html#setCacheMode(int)
  562. * Set the cacheMode. Possible values are:
  563. *
  564. * - `'LOAD_DEFAULT'` (default)
  565. * - `'LOAD_CACHE_ELSE_NETWORK'`
  566. * - `'LOAD_NO_CACHE'`
  567. * - `'LOAD_CACHE_ONLY'`
  568. *
  569. * @platform android
  570. */
  571. cacheMode?: CacheMode;
  572. /**
  573. * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
  574. * Sets the overScrollMode. Possible values are:
  575. *
  576. * - `'always'` (default)
  577. * - `'content'`
  578. * - `'never'`
  579. *
  580. * @platform android
  581. */
  582. overScrollMode?: OverScrollModeType;
  583. /**
  584. * Boolean that controls whether the web content is scaled to fit
  585. * the view and enables the user to change the scale. The default value
  586. * is `true`.
  587. */
  588. scalesPageToFit?: boolean;
  589. /**
  590. * Sets whether Geolocation is enabled. The default is false.
  591. * @platform android
  592. */
  593. geolocationEnabled?: boolean;
  594. /**
  595. * Boolean that sets whether JavaScript running in the context of a file
  596. * scheme URL should be allowed to access content from other file scheme URLs.
  597. * Including accessing content from other file scheme URLs
  598. * @platform android
  599. */
  600. allowFileAccessFromFileURLs?: boolean;
  601. /**
  602. * Boolean that sets whether JavaScript running in the context of a file
  603. * scheme URL should be allowed to access content from any origin.
  604. * Including accessing content from other file scheme URLs
  605. * @platform android
  606. */
  607. allowUniversalAccessFromFileURLs?: boolean;
  608. /**
  609. * Sets whether the webview allow access to file system.
  610. * @platform android
  611. */
  612. allowFileAccess?: boolean;
  613. /**
  614. * Used on Android only, controls whether form autocomplete data should be saved
  615. * @platform android
  616. */
  617. saveFormDataDisabled?: boolean;
  618. /**
  619. * Used on Android only, controls whether the given list of URL prefixes should
  620. * make {@link com.facebook.react.views.webview.ReactWebViewClient} to launch a
  621. * default activity intent for those URL instead of loading it within the webview.
  622. * Use this to list URLs that WebView cannot handle, e.g. a PDF url.
  623. * @platform android
  624. */
  625. urlPrefixesForDefaultIntent?: readonly string[];
  626. /**
  627. * Boolean value to disable Hardware Acceleration in the `WebView`. Used on Android only
  628. * as Hardware Acceleration is a feature only for Android. The default value is `false`.
  629. * @platform android
  630. */
  631. androidHardwareAccelerationDisabled?: boolean;
  632. /**
  633. * Boolean value to enable third party cookies in the `WebView`. Used on
  634. * Android Lollipop and above only as third party cookies are enabled by
  635. * default on Android Kitkat and below and on iOS. The default value is `true`.
  636. * @platform android
  637. */
  638. thirdPartyCookiesEnabled?: boolean;
  639. /**
  640. * Boolean value to control whether DOM Storage is enabled. Used only in
  641. * Android.
  642. * @platform android
  643. */
  644. domStorageEnabled?: boolean;
  645. /**
  646. * Sets the user-agent for the `WebView`.
  647. * @platform android
  648. */
  649. userAgent?: string;
  650. /**
  651. * Sets number that controls text zoom of the page in percent.
  652. * @platform android
  653. */
  654. textZoom?: number;
  655. /**
  656. * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
  657. *
  658. * Possible values for `mixedContentMode` are:
  659. *
  660. * - `'never'` (default) - WebView will not allow a secure origin to load content from an insecure origin.
  661. * - `'always'` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
  662. * - `'compatibility'` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
  663. * @platform android
  664. */
  665. mixedContentMode?: 'never' | 'always' | 'compatibility';
  666. /**
  667. * Sets ability to open fullscreen videos on Android devices.
  668. */
  669. allowsFullscreenVideo?: boolean;
  670. }
  671. export interface WebViewSharedProps extends ViewProps {
  672. /**
  673. * Loads static html or a uri (with optional headers) in the WebView.
  674. */
  675. source?: WebViewSource;
  676. /**
  677. * Boolean value to enable JavaScript in the `WebView`. Used on Android only
  678. * as JavaScript is enabled by default on iOS. The default value is `true`.
  679. * @platform android
  680. */
  681. javaScriptEnabled?: boolean;
  682. /**
  683. * Stylesheet object to set the style of the container view.
  684. */
  685. containerStyle?: StyleProp<ViewStyle>;
  686. /**
  687. * Function that returns a view to show if there's an error.
  688. */
  689. renderError?: (
  690. errorDomain: string | undefined,
  691. errorCode: number,
  692. errorDesc: string,
  693. ) => ReactElement; // view to show if there's an error
  694. /**
  695. * Function that returns a loading indicator.
  696. */
  697. renderLoading?: () => ReactElement;
  698. /**
  699. * Function that is invoked when the `WebView` scrolls.
  700. */
  701. onScroll?: (event: NativeScrollEvent) => void;
  702. /**
  703. * Function that is invoked when the `WebView` has finished loading.
  704. */
  705. onLoad?: (event: WebViewNavigationEvent) => void;
  706. /**
  707. * Function that is invoked when the `WebView` load succeeds or fails.
  708. */
  709. onLoadEnd?: (event: WebViewNavigationEvent | WebViewErrorEvent) => void;
  710. /**
  711. * Function that is invoked when the `WebView` starts loading.
  712. */
  713. onLoadStart?: (event: WebViewNavigationEvent) => void;
  714. /**
  715. * Function that is invoked when the `WebView` load fails.
  716. */
  717. onError?: (event: WebViewErrorEvent) => void;
  718. /**
  719. * Function that is invoked when the `WebView` receives an error status code.
  720. * Works on iOS and Android (minimum API level 23).
  721. */
  722. onHttpError?: (event: WebViewHttpErrorEvent) => void;
  723. /**
  724. * Function that is invoked when the `WebView` loading starts or ends.
  725. */
  726. onNavigationStateChange?: (event: WebViewNavigation) => void;
  727. /**
  728. * Function that is invoked when the webview calls `window.ReactNativeWebView.postMessage`.
  729. * Setting this property will inject this global into your webview.
  730. *
  731. * `window.ReactNativeWebView.postMessage` accepts one argument, `data`, which will be
  732. * available on the event object, `event.nativeEvent.data`. `data` must be a string.
  733. */
  734. onMessage?: (event: WebViewMessageEvent) => void;
  735. /**
  736. * Function that is invoked when the `WebView` is loading.
  737. */
  738. onLoadProgress?: (event: WebViewProgressEvent) => void;
  739. /**
  740. * Boolean value that forces the `WebView` to show the loading view
  741. * on the first load.
  742. */
  743. startInLoadingState?: boolean;
  744. /**
  745. * Set this to provide JavaScript that will be injected into the web page
  746. * when the view loads.
  747. */
  748. injectedJavaScript?: string;
  749. /**
  750. * Set this to provide JavaScript that will be injected into the web page
  751. * once the webview is initialized but before the view loads any content.
  752. */
  753. injectedJavaScriptBeforeContentLoaded?: string;
  754. /**
  755. * Boolean value that determines whether a horizontal scroll indicator is
  756. * shown in the `WebView`. The default value is `true`.
  757. */
  758. showsHorizontalScrollIndicator?: boolean;
  759. /**
  760. * Boolean value that determines whether a vertical scroll indicator is
  761. * shown in the `WebView`. The default value is `true`.
  762. */
  763. showsVerticalScrollIndicator?: boolean;
  764. /**
  765. * Boolean that determines whether HTML5 audio and video requires the user
  766. * to tap them before they start playing. The default value is `true`.
  767. */
  768. mediaPlaybackRequiresUserAction?: boolean;
  769. /**
  770. * List of origin strings to allow being navigated to. The strings allow
  771. * wildcards and get matched against *just* the origin (not the full URL).
  772. * If the user taps to navigate to a new page but the new page is not in
  773. * this whitelist, we will open the URL in Safari.
  774. * The default whitelisted origins are "http://*" and "https://*".
  775. */
  776. originWhitelist?: readonly string[];
  777. /**
  778. * Function that allows custom handling of any web view requests. Return
  779. * `true` from the function to continue loading the request and `false`
  780. * to stop loading. The `navigationType` is always `other` on android.
  781. */
  782. onShouldStartLoadWithRequest?: OnShouldStartLoadWithRequest;
  783. /**
  784. * Override the native component used to render the WebView. Enables a custom native
  785. * WebView which uses the same JavaScript as the original WebView.
  786. */
  787. nativeConfig?: WebViewNativeConfig;
  788. /**
  789. * Should caching be enabled. Default is true.
  790. */
  791. cacheEnabled?: boolean;
  792. }