From a0dc252dc89699f7bd0d733642b98762d0db423a Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Thu, 27 Aug 2020 15:18:22 -0700 Subject: [PATCH] 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 --- Libraries/Image/ImageSource.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Libraries/Image/ImageSource.js b/Libraries/Image/ImageSource.js index e2f280f66a0..b2ee46baa1b 100644 --- a/Libraries/Image/ImageSource.js +++ b/Libraries/Image/ImageSource.js @@ -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 `` 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; +export type ImageSource = + | number + | ImageURISource + | $ReadOnlyArray;