Açıklama Yok

WebViewTypes.ts 32KB

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