Skip to content

Commit a0dc252

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Cleanup ImageSource Flow Type
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
1 parent 39f694a commit a0dc252

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

Libraries/Image/ImageSource.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @flow
7+
* @flow strict
88
* @format
99
*/
1010

1111
'use strict';
1212

13-
// This is to sync with ImageSourcePropTypes.js.
14-
// We explicitly don't want this to be strict so that we can pass in objects
15-
// that might have more keys. This also has to be inexact to support taking
16-
// instances of classes like FBIcon.
17-
// https://fburl.com/8lynhvtw
13+
/**
14+
* Keep this in sync with `DeprecatedImageSourcePropType.js`.
15+
*
16+
* This type is intentinoally inexact in order to permit call sites that supply
17+
* extra properties.
18+
*/
1819
export type ImageURISource = $ReadOnly<{
1920
/**
2021
* `uri` is a string representing the resource identifier for the image, which
@@ -23,27 +24,32 @@ export type ImageURISource = $ReadOnly<{
2324
* function).
2425
*/
2526
uri?: ?string,
27+
2628
/**
2729
* `bundle` is the iOS asset bundle which the image is included in. This
2830
* will default to [NSBundle mainBundle] if not set.
2931
* @platform ios
3032
*/
3133
bundle?: ?string,
34+
3235
/**
3336
* `method` is the HTTP Method to use. Defaults to GET if not specified.
3437
*/
3538
method?: ?string,
39+
3640
/**
3741
* `headers` is an object representing the HTTP headers to send along with the
3842
* request for a remote image.
3943
*/
40-
headers?: ?Object,
44+
headers?: ?{[string]: string},
45+
4146
/**
4247
* `body` is the HTTP body to send with the request. This must be a valid
4348
* UTF-8 string, and will be sent exactly as specified, with no
4449
* additional encoding (e.g. URL-escaping or base64) applied.
4550
*/
4651
body?: ?string,
52+
4753
/**
4854
* `cache` determines how the requests handles potentially cached
4955
* responses.
@@ -65,21 +71,24 @@ export type ImageURISource = $ReadOnly<{
6571
* @platform ios
6672
*/
6773
cache?: ?('default' | 'reload' | 'force-cache' | 'only-if-cached'),
74+
6875
/**
6976
* `width` and `height` can be specified if known at build time, in which case
7077
* these will be used to set the default `<Image/>` component dimensions.
7178
*/
7279
width?: ?number,
7380
height?: ?number,
81+
7482
/**
7583
* `scale` is used to indicate the scale factor of the image. Defaults to 1.0 if
7684
* unspecified, meaning that one image pixel equates to one display point / DIP.
7785
*/
7886
scale?: ?number,
87+
7988
...
8089
}>;
8190

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

0 commit comments

Comments
 (0)