Nessuna descrizione

WebViewTypes.js 12KB

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