No Description

WebViewTypes.ts 28KB

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