No Description

WebViewTypes.ts 32KB

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