Nessuna descrizione

WebViewTypes.ts 32KB

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