ImageSource.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  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. * @flow
  8. * @format
  9. */
  10. 'use strict';
  11. // This is to sync with ImageSourcePropTypes.js.
  12. // We explicitly don't want this to be strict so that we can pass in objects
  13. // that might have more keys. This also has to be inexact to support taking
  14. // instances of classes like FBIcon.
  15. // https://fburl.com/8lynhvtw
  16. export type ImageURISource = $ReadOnly<{
  17. /**
  18. * `uri` is a string representing the resource identifier for the image, which
  19. * could be an http address, a local file path, or the name of a static image
  20. * resource (which should be wrapped in the `require('./path/to/image.png')`
  21. * function).
  22. */
  23. uri?: ?string,
  24. /**
  25. * `bundle` is the iOS asset bundle which the image is included in. This
  26. * will default to [NSBundle mainBundle] if not set.
  27. * @platform ios
  28. */
  29. bundle?: ?string,
  30. /**
  31. * `method` is the HTTP Method to use. Defaults to GET if not specified.
  32. */
  33. method?: ?string,
  34. /**
  35. * `headers` is an object representing the HTTP headers to send along with the
  36. * request for a remote image.
  37. */
  38. headers?: ?Object,
  39. /**
  40. * `body` is the HTTP body to send with the request. This must be a valid
  41. * UTF-8 string, and will be sent exactly as specified, with no
  42. * additional encoding (e.g. URL-escaping or base64) applied.
  43. */
  44. body?: ?string,
  45. /**
  46. * `cache` determines how the requests handles potentially cached
  47. * responses.
  48. *
  49. * - `default`: Use the native platforms default strategy. `useProtocolCachePolicy` on iOS.
  50. *
  51. * - `reload`: The data for the URL will be loaded from the originating source.
  52. * No existing cache data should be used to satisfy a URL load request.
  53. *
  54. * - `force-cache`: The existing cached data will be used to satisfy the request,
  55. * regardless of its age or expiration date. If there is no existing data in the cache
  56. * corresponding the request, the data is loaded from the originating source.
  57. *
  58. * - `only-if-cached`: The existing cache data will be used to satisfy a request, regardless of
  59. * its age or expiration date. If there is no existing data in the cache corresponding
  60. * to a URL load request, no attempt is made to load the data from the originating source,
  61. * and the load is considered to have failed.
  62. *
  63. * @platform ios
  64. */
  65. cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'),
  66. /**
  67. * `width` and `height` can be specified if known at build time, in which case
  68. * these will be used to set the default `<Image/>` component dimensions.
  69. */
  70. width?: ?number,
  71. height?: ?number,
  72. /**
  73. * `scale` is used to indicate the scale factor of the image. Defaults to 1.0 if
  74. * unspecified, meaning that one image pixel equates to one display point / DIP.
  75. */
  76. scale?: ?number,
  77. ...
  78. }>;
  79. // We have to export any because of an issue in Flow with objects that come from Relay:
  80. // https://fburl.com/8ljo5tmr
  81. // https://fb.facebook.com/groups/flow/permalink/1824103160971624/
  82. export type ImageSource = ImageURISource | number | Array<ImageURISource>;