2016-06-01 17:32:20 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-01 17:32:20 +00:00
|
|
|
*
|
|
|
|
* @providesModule ImageSourcePropType
|
|
|
|
* @no-flow
|
2018-01-15 03:32:26 +00:00
|
|
|
* @format
|
2016-06-01 17:32:20 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-06-12 22:59:06 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2016-06-01 17:32:20 +00:00
|
|
|
|
2016-07-28 20:58:50 +00:00
|
|
|
const ImageURISourcePropType = PropTypes.shape({
|
|
|
|
/**
|
|
|
|
* `uri` is a string representing the resource identifier for the image, which
|
|
|
|
* could be an http address, a local file path, or the name of a static image
|
|
|
|
* resource (which should be wrapped in the `require('./path/to/image.png')`
|
|
|
|
* function).
|
|
|
|
*/
|
|
|
|
uri: PropTypes.string,
|
2016-09-01 00:30:50 +00:00
|
|
|
/**
|
|
|
|
* `bundle` is the iOS asset bundle which the image is included in. This
|
|
|
|
* will default to [NSBundle mainBundle] if not set.
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
bundle: PropTypes.string,
|
2016-07-28 20:58:50 +00:00
|
|
|
/**
|
|
|
|
* `method` is the HTTP Method to use. Defaults to GET if not specified.
|
|
|
|
*/
|
|
|
|
method: PropTypes.string,
|
|
|
|
/**
|
|
|
|
* `headers` is an object representing the HTTP headers to send along with the
|
|
|
|
* request for a remote image.
|
|
|
|
*/
|
|
|
|
headers: PropTypes.objectOf(PropTypes.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: PropTypes.string,
|
2017-01-18 00:58:27 +00:00
|
|
|
/**
|
|
|
|
* `cache` determines how the requests handles potentially cached
|
|
|
|
* responses.
|
|
|
|
*
|
|
|
|
* - `default`: Use the native platforms default strategy. `useProtocolCachePolicy` on iOS.
|
|
|
|
*
|
|
|
|
* - `reload`: The data for the URL will be loaded from the originating source.
|
|
|
|
* No existing cache data should be used to satisfy a URL load request.
|
|
|
|
*
|
|
|
|
* - `force-cache`: The existing cached data will be used to satisfy the request,
|
|
|
|
* regardless of its age or expiration date. If there is no existing data in the cache
|
|
|
|
* corresponding the request, the data is loaded from the originating source.
|
|
|
|
*
|
|
|
|
* - `only-if-cached`: The existing cache data will be used to satisfy a request, regardless of
|
|
|
|
* its age or expiration date. If there is no existing data in the cache corresponding
|
|
|
|
* to a URL load request, no attempt is made to load the data from the originating source,
|
|
|
|
* and the load is considered to have failed.
|
|
|
|
*
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
cache: PropTypes.oneOf([
|
|
|
|
'default',
|
|
|
|
'reload',
|
|
|
|
'force-cache',
|
|
|
|
'only-if-cached',
|
|
|
|
]),
|
2016-07-28 20:58:50 +00:00
|
|
|
/**
|
|
|
|
* `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: PropTypes.number,
|
|
|
|
height: PropTypes.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: PropTypes.number,
|
|
|
|
});
|
|
|
|
|
2016-06-01 17:32:20 +00:00
|
|
|
const ImageSourcePropType = PropTypes.oneOfType([
|
2016-07-28 20:58:50 +00:00
|
|
|
ImageURISourcePropType,
|
2016-06-01 17:32:20 +00:00
|
|
|
// Opaque type returned by require('./image.jpg')
|
|
|
|
PropTypes.number,
|
2016-07-28 20:58:50 +00:00
|
|
|
// Multiple sources
|
|
|
|
PropTypes.arrayOf(ImageURISourcePropType),
|
2016-06-01 17:32:20 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
module.exports = ImageSourcePropType;
|