Skip to content

Commit

Permalink
RN: Cleanup ImageSource Flow Type
Browse files Browse the repository at this point in the history
Summary:
Cleans up the documentation and types for `ImageSource`.

The only material changes here are:

-  `ImageSource`'s array variant will now be `$ReadOnlyArray` instead of `Array`.
- `ImageURISource.headers` is now an object of string properties.

Changelog:
[General][Changed] - Refined `ImageSource` Flow type for array-variant and headers.

Reviewed By: kacieb

Differential Revision: D23355812

fbshipit-source-id: c3407db037dfb1d3514a028d1a237eb76ee6fedd
  • Loading branch information
yungsters authored and facebook-github-bot committed Aug 27, 2020
1 parent 39f694a commit a0dc252
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Libraries/Image/ImageSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @flow strict
* @format
*/

'use strict';

// This is to sync with ImageSourcePropTypes.js.
// We explicitly don't want this to be strict so that we can pass in objects
// that might have more keys. This also has to be inexact to support taking
// instances of classes like FBIcon.
// https://fburl.com/8lynhvtw
/**
* Keep this in sync with `DeprecatedImageSourcePropType.js`.
*
* This type is intentinoally inexact in order to permit call sites that supply
* extra properties.
*/
export type ImageURISource = $ReadOnly<{
/**
* `uri` is a string representing the resource identifier for the image, which
Expand All @@ -23,27 +24,32 @@ export type ImageURISource = $ReadOnly<{
* function).
*/
uri?: ?string,

/**
* `bundle` is the iOS asset bundle which the image is included in. This
* will default to [NSBundle mainBundle] if not set.
* @platform ios
*/
bundle?: ?string,

/**
* `method` is the HTTP Method to use. Defaults to GET if not specified.
*/
method?: ?string,

/**
* `headers` is an object representing the HTTP headers to send along with the
* request for a remote image.
*/
headers?: ?Object,
headers?: ?{[string]: string},

/**
* `body` is the HTTP body to send with the request. This must be a valid
* UTF-8 string, and will be sent exactly as specified, with no
* additional encoding (e.g. URL-escaping or base64) applied.
*/
body?: ?string,

/**
* `cache` determines how the requests handles potentially cached
* responses.
Expand All @@ -65,21 +71,24 @@ export type ImageURISource = $ReadOnly<{
* @platform ios
*/
cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'),

/**
* `width` and `height` can be specified if known at build time, in which case
* these will be used to set the default `<Image/>` component dimensions.
*/
width?: ?number,
height?: ?number,

/**
* `scale` is used to indicate the scale factor of the image. Defaults to 1.0 if
* unspecified, meaning that one image pixel equates to one display point / DIP.
*/
scale?: ?number,

...
}>;

// We have to export any because of an issue in Flow with objects that come from Relay:
// https://fburl.com/8ljo5tmr
// https://fb.facebook.com/groups/flow/permalink/1824103160971624/
export type ImageSource = ImageURISource | number | Array<ImageURISource>;
export type ImageSource =
| number
| ImageURISource
| $ReadOnlyArray<ImageURISource>;

0 comments on commit a0dc252

Please sign in to comment.