No Description

WebViewTypes.js 12KB

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