react-native-webview.git

WebViewTypes.js 13KB

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