No Description

WebViewTypes.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow
  9. */
  10. 'use strict';
  11. import type { Node, Element, ComponentType } from 'react';
  12. import type { SyntheticEvent } from 'CoreEventTypes';
  13. import type { EdgeInsetsProp } from 'EdgeInsetsPropType';
  14. import type { ViewStyleProp } from 'StyleSheet';
  15. import type { ViewProps } from 'ViewPropTypes';
  16. export type WebViewNativeEvent = $ReadOnly<{|
  17. url: string,
  18. loading: boolean,
  19. title: string,
  20. canGoBack: boolean,
  21. canGoForward: boolean,
  22. lockIdentifier: number,
  23. |}>;
  24. export type WebViewProgressEvent = $ReadOnly<{|
  25. ...WebViewNativeEvent,
  26. progress: number,
  27. |}>;
  28. export type WebViewNavigation = $ReadOnly<{|
  29. ...WebViewNativeEvent,
  30. navigationType:
  31. | 'click'
  32. | 'formsubmit'
  33. | 'backforward'
  34. | 'reload'
  35. | 'formresubmit'
  36. | 'other',
  37. |}>;
  38. export type WebViewMessage = $ReadOnly<{|
  39. ...WebViewNativeEvent,
  40. data: string,
  41. |}>;
  42. export type WebViewError = $ReadOnly<{|
  43. ...WebViewNativeEvent,
  44. /**
  45. * `domain` is only used on iOS
  46. */
  47. domain: ?string,
  48. code: number,
  49. description: string,
  50. |}>;
  51. export type WebViewEvent = SyntheticEvent<WebViewNativeEvent>;
  52. export type WebViewNavigationEvent = SyntheticEvent<WebViewNavigation>;
  53. export type WebViewMessageEvent = SyntheticEvent<WebViewMessage>;
  54. export type WebViewErrorEvent = SyntheticEvent<WebViewError>;
  55. export type DataDetectorTypes =
  56. | 'phoneNumber'
  57. | 'link'
  58. | 'address'
  59. | 'calendarEvent'
  60. | 'trackingNumber'
  61. | 'flightNumber'
  62. | 'lookupSuggestion'
  63. | 'none'
  64. | 'all';
  65. export type OverScrollModeType = 'always' | 'content' | 'never';
  66. export type WebViewSourceUri = $ReadOnly<{|
  67. /**
  68. * The URI to load in the `WebView`. Can be a local or remote file.
  69. */
  70. uri?: ?string,
  71. /**
  72. * The HTTP Method to use. Defaults to GET if not specified.
  73. * NOTE: On Android, only GET and POST are supported.
  74. */
  75. method?: string,
  76. /**
  77. * Additional HTTP headers to send with the request.
  78. * NOTE: On Android, this can only be used with GET requests.
  79. */
  80. headers?: Object,
  81. /**
  82. * The HTTP body to send with the request. This must be a valid
  83. * UTF-8 string, and will be sent exactly as specified, with no
  84. * additional encoding (e.g. URL-escaping or base64) applied.
  85. * NOTE: On Android, this can only be used with POST requests.
  86. */
  87. body?: string,
  88. |}>;
  89. export type WebViewSourceHtml = $ReadOnly<{|
  90. /**
  91. * A static HTML page to display in the WebView.
  92. */
  93. html?: ?string,
  94. /**
  95. * The base URL to be used for any relative links in the HTML.
  96. */
  97. baseUrl?: ?string,
  98. |}>;
  99. export type WebViewSource = WebViewSourceUri | WebViewSourceHtml;
  100. export type WebViewNativeConfig = $ReadOnly<{|
  101. /**
  102. * The native component used to render the WebView.
  103. */
  104. component?: ComponentType<WebViewSharedProps>,
  105. /**
  106. * Set props directly on the native component WebView. Enables custom props which the
  107. * original WebView doesn't pass through.
  108. */
  109. props?: ?Object,
  110. /**
  111. * Set the ViewManager to use for communication with the native side.
  112. * @platform ios
  113. */
  114. viewManager?: ?Object,
  115. |}>;
  116. export type OnShouldStartLoadWithRequest = (
  117. event: WebViewNavigation,
  118. ) => boolean;
  119. export type IOSWebViewProps = $ReadOnly<{|
  120. /**
  121. * If true, use WKWebView instead of UIWebView.
  122. * @platform ios
  123. */
  124. useWebKit?: ?boolean,
  125. /**
  126. * Boolean value that determines whether the web view bounces
  127. * when it reaches the edge of the content. The default value is `true`.
  128. * @platform ios
  129. */
  130. bounces?: ?boolean,
  131. /**
  132. * A floating-point number that determines how quickly the scroll view
  133. * decelerates after the user lifts their finger. You may also use the
  134. * string shortcuts `"normal"` and `"fast"` which match the underlying iOS
  135. * settings for `UIScrollViewDecelerationRateNormal` and
  136. * `UIScrollViewDecelerationRateFast` respectively:
  137. *
  138. * - normal: 0.998
  139. * - fast: 0.99 (the default for iOS web view)
  140. * @platform ios
  141. */
  142. decelerationRate?: ?('fast' | 'normal' | number),
  143. /**
  144. * Boolean value that determines whether scrolling is enabled in the
  145. * `WebView`. The default value is `true`.
  146. * @platform ios
  147. */
  148. scrollEnabled?: ?boolean,
  149. /**
  150. * If the value of this property is true, the scroll view stops on multiples
  151. * of the scroll view’s bounds when the user scrolls.
  152. * The default value is false.
  153. * @platform ios
  154. */
  155. pagingEnabled?: ?boolean,
  156. /**
  157. * The amount by which the web view content is inset from the edges of
  158. * the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
  159. * @platform ios
  160. */
  161. contentInset?: ?EdgeInsetsProp,
  162. /**
  163. * Determines the types of data converted to clickable URLs in the web view's content.
  164. * By default only phone numbers are detected.
  165. *
  166. * You can provide one type or an array of many types.
  167. *
  168. * Possible values for `dataDetectorTypes` are:
  169. *
  170. * - `'phoneNumber'`
  171. * - `'link'`
  172. * - `'address'`
  173. * - `'calendarEvent'`
  174. * - `'none'`
  175. * - `'all'`
  176. *
  177. * With the new WebKit implementation, we have three new values:
  178. * - `'trackingNumber'`,
  179. * - `'flightNumber'`,
  180. * - `'lookupSuggestion'`,
  181. *
  182. * @platform ios
  183. */
  184. dataDetectorTypes?: ?DataDetectorTypes | $ReadOnlyArray<DataDetectorTypes>,
  185. /**
  186. * Boolean that determines whether HTML5 videos play inline or use the
  187. * native full-screen controller. The default value is `false`.
  188. *
  189. * **NOTE** : In order for video to play inline, not only does this
  190. * property need to be set to `true`, but the video element in the HTML
  191. * document must also include the `webkit-playsinline` attribute.
  192. * @platform ios
  193. */
  194. allowsInlineMediaPlayback?: ?boolean,
  195. /**
  196. * Hide the accessory view when the keyboard is open. Default is false to be
  197. * backward compatible.
  198. */
  199. hideKeyboardAccessoryView?: ?boolean,
  200. /**
  201. * A Boolean value indicating whether horizontal swipe gestures will trigger
  202. * back-forward list navigations.
  203. */
  204. allowsBackForwardNavigationGestures?: ?boolean,
  205. /**
  206. * The custom user agent string.
  207. */
  208. userAgent?: ?string,
  209. /**
  210. * A Boolean value that determines whether pressing on a link
  211. * displays a preview of the destination for the link.
  212. *
  213. * This property is available on devices that support 3D Touch.
  214. * In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
  215. * @platform ios
  216. */
  217. allowsLinkPreview?: ?boolean,
  218. |}>;
  219. export type AndroidWebViewProps = $ReadOnly<{|
  220. onNavigationStateChange?: (event: WebViewNavigation) => mixed,
  221. onContentSizeChange?: (event: WebViewEvent) => mixed,
  222. /**
  223. * https://developer.android.com/reference/android/view/View#OVER_SCROLL_NEVER
  224. * Sets the overScrollMode. Possible values are:
  225. *
  226. * - `'always'` (default)
  227. * - `'content'`
  228. * - `'never'`
  229. *
  230. * @platform android
  231. */
  232. overScrollMode?: ?OverScrollModeType,
  233. /**
  234. * Sets whether Geolocation is enabled. The default is false.
  235. * @platform android
  236. */
  237. geolocationEnabled?: ?boolean,
  238. /**
  239. * Boolean that sets whether JavaScript running in the context of a file
  240. * scheme URL should be allowed to access content from any origin.
  241. * Including accessing content from other file scheme URLs
  242. * @platform android
  243. */
  244. allowUniversalAccessFromFileURLs?: ?boolean,
  245. /**
  246. * Sets whether the webview allow access to file system.
  247. * @platform android
  248. */
  249. allowFileAccess?: ?boolean,
  250. /**
  251. * Used on Android only, controls whether form autocomplete data should be saved
  252. * @platform android
  253. */
  254. saveFormDataDisabled?: ?boolean,
  255. /**
  256. * Used on Android only, controls whether the given list of URL prefixes should
  257. * make {@link com.facebook.react.views.webview.ReactWebViewClient} to launch a
  258. * default activity intent for those URL instead of loading it within the webview.
  259. * Use this to list URLs that WebView cannot handle, e.g. a PDF url.
  260. * @platform android
  261. */
  262. urlPrefixesForDefaultIntent?: $ReadOnlyArray<string>,
  263. /**
  264. * Boolean value to enable JavaScript in the `WebView`. Used on Android only
  265. * as JavaScript is enabled by default on iOS. The default value is `true`.
  266. * @platform android
  267. */
  268. javaScriptEnabled?: ?boolean,
  269. /**
  270. * Boolean value to enable third party cookies in the `WebView`. Used on
  271. * Android Lollipop and above only as third party cookies are enabled by
  272. * default on Android Kitkat and below and on iOS. The default value is `true`.
  273. * @platform android
  274. */
  275. thirdPartyCookiesEnabled?: ?boolean,
  276. /**
  277. * Boolean value to control whether DOM Storage is enabled. Used only in
  278. * Android.
  279. * @platform android
  280. */
  281. domStorageEnabled?: ?boolean,
  282. /**
  283. * Sets the user-agent for the `WebView`.
  284. * @platform android
  285. */
  286. userAgent?: ?string,
  287. /**
  288. * Specifies the mixed content mode. i.e WebView will allow a secure origin to load content from any other origin.
  289. *
  290. * Possible values for `mixedContentMode` are:
  291. *
  292. * - `'never'` (default) - WebView will not allow a secure origin to load content from an insecure origin.
  293. * - `'always'` - WebView will allow a secure origin to load content from any other origin, even if that origin is insecure.
  294. * - `'compatibility'` - WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content.
  295. * @platform android
  296. */
  297. mixedContentMode?: ?('never' | 'always' | 'compatibility'),
  298. |}>;
  299. export type WebViewSharedProps = $ReadOnly<{|
  300. ...ViewProps,
  301. ...IOSWebViewProps,
  302. ...AndroidWebViewProps,
  303. /**
  304. * Deprecated. Use `source` instead.
  305. */
  306. url?: ?string,
  307. /**
  308. * Deprecated. Use `source` instead.
  309. */
  310. html?: ?string,
  311. /**
  312. * Loads static html or a uri (with optional headers) in the WebView.
  313. */
  314. source?: ?WebViewSource,
  315. /**
  316. * Function that returns a view to show if there's an error.
  317. */
  318. renderError: (
  319. errorDomain: ?string,
  320. errorCode: number,
  321. errorDesc: string,
  322. ) => Element<any>, // view to show if there's an error
  323. /**
  324. * Function that returns a loading indicator.
  325. */
  326. renderLoading: () => Element<any>,
  327. /**
  328. * Function that is invoked when the `WebView` has finished loading.
  329. */
  330. onLoad: (event: WebViewNavigationEvent) => mixed,
  331. /**
  332. * Function that is invoked when the `WebView` load succeeds or fails.
  333. */
  334. onLoadEnd: (event: WebViewNavigationEvent | WebViewErrorEvent) => mixed,
  335. /**
  336. * Function that is invoked when the `WebView` starts loading.
  337. */
  338. onLoadStart: (event: WebViewNavigationEvent) => mixed,
  339. /**
  340. * Function that is invoked when the `WebView` load fails.
  341. */
  342. onError: (event: WebViewErrorEvent) => mixed,
  343. /**
  344. * Controls whether to adjust the content inset for web views that are
  345. * placed behind a navigation bar, tab bar, or toolbar. The default value
  346. * is `true`.
  347. */
  348. automaticallyAdjustContentInsets?: ?boolean,
  349. /**
  350. * Function that is invoked when the `WebView` loading starts or ends.
  351. */
  352. onNavigationStateChange?: (event: WebViewNavigation) => mixed,
  353. /**
  354. * A function that is invoked when the webview calls `window.postMessage`.
  355. * Setting this property will inject a `postMessage` global into your
  356. * webview, but will still call pre-existing values of `postMessage`.
  357. *
  358. * `window.postMessage` accepts one argument, `data`, which will be
  359. * available on the event object, `event.nativeEvent.data`. `data`
  360. * must be a string.
  361. */
  362. onMessage?: (event: WebViewMessageEvent) => mixed,
  363. /**
  364. * Function that is invoked when the `WebView` is loading.
  365. */
  366. onLoadProgress?: (event: WebViewProgressEvent) => mixed,
  367. /**
  368. * Boolean value that forces the `WebView` to show the loading view
  369. * on the first load.
  370. */
  371. startInLoadingState?: ?boolean,
  372. /**
  373. * Set this to provide JavaScript that will be injected into the web page
  374. * when the view loads.
  375. */
  376. injectedJavaScript?: ?string,
  377. /**
  378. * Boolean that controls whether the web content is scaled to fit
  379. * the view and enables the user to change the scale. The default value
  380. * is `true`.
  381. *
  382. * On iOS, when `useWebKit=true`, this prop will not work.
  383. */
  384. scalesPageToFit?: ?boolean,
  385. /**
  386. * Boolean that determines whether HTML5 audio and video requires the user
  387. * to tap them before they start playing. The default value is `true`.
  388. */
  389. mediaPlaybackRequiresUserAction?: ?boolean,
  390. /**
  391. * List of origin strings to allow being navigated to. The strings allow
  392. * wildcards and get matched against *just* the origin (not the full URL).
  393. * If the user taps to navigate to a new page but the new page is not in
  394. * this whitelist, we will open the URL in Safari.
  395. * The default whitelisted origins are "http://*" and "https://*".
  396. */
  397. originWhitelist?: $ReadOnlyArray<string>,
  398. /**
  399. * Function that allows custom handling of any web view requests. Return
  400. * `true` from the function to continue loading the request and `false`
  401. * to stop loading. The `navigationType` is always `other` on android.
  402. */
  403. onShouldStartLoadWithRequest?: OnShouldStartLoadWithRequest,
  404. /**
  405. * Override the native component used to render the WebView. Enables a custom native
  406. * WebView which uses the same JavaScript as the original WebView.
  407. */
  408. nativeConfig?: ?WebViewNativeConfig,
  409. style?: ViewStyleProp,
  410. children: Node,
  411. |}>;