mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
1 parent
39f694a748
commit
a0dc252dc8
1 file changed
+20
-11
@@ -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
|
||||
@@ -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.
|
||||
@@ -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>;
|
||||
Reference in new issue
Block a user