No Description

WebViewTypes.js 13KB

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