To locate the answer, examine the react-native
source code found within
/node_modules/react-native/Libraries/Image
, specifically reviewing the files
ImageSourcePropType
and
ImageProps
.
As per the specifications outlined in ImageSourcePropType
, a URI object should adhere to the following structure (allowing for any defined properties as long as the data type matches the expected format):
const ImageURISourcePropType = PropTypes.shape({
uri: PropTypes.string,
bundle: PropTypes.string,
method: PropTypes.string,
headers: PropTypes.objectOf(PropTypes.string),
body: PropTypes.string,
cache: PropTypes.oneOf([
'default',
'reload',
'force-cache',
'only-if-cached',
]),
width: PropTypes.number,
height: PropTypes.number,
scale: PropTypes.number,
});
According to ImageProps
, the source
attribute can accept an object conforming to the shape of ImageSourcePropType
, an array containing such objects, or a number (pertaining to local assets where require('imgs/image1.png')
yields a unique identifier for that asset). Here is the relevant code snippet:
const ImageSourcePropType = PropTypes.oneOfType([
ImageURISourcePropType,
// Opaque type returned by require('./image.jpg')
PropTypes.number,
// Multiple sources
PropTypes.arrayOf(ImageURISourcePropType),
]);
Hence, the source
property can accept either a single object conforming to ImageURISourcePropType
or an array of such objects.
To effectively pass multiple remote images while specifying their respective widths, the process would resemble the following example:
<Image
source={[
{
uri: 'https://image.location.com',
width: 500,
height: 500
},
{
uri: 'https://image2.location.com',
width: 600,
height: 600
},
{
uri: 'https://image3.location.com',
width: 700,
height: 700
},
]}
/>