react-native-webview.git

WebViewTypes.js 9.2KB

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