Media shows an image from a URL in a box with rounded corners and a set aspect ratio. A skeleton fills the box until the image loads. It extends Flex props, so radius, border, margin and sizes work as on any Flex. See the web Media page for the web version.
Set loading to show the skeleton instead of the image, for example while you fetch the URL. caption adds a line of text under the image.
Pass onPress to make the image a button. onClick works too, as on the web. The image dims while it is pressed.
With stretch, the image fills the box it is in and ignores aspectRatio. Use it for a background inside a sized container.
- Images only. The web's enlarge overlay, video and YouTube embeds are not in the native package.
- aspectRatio defaults to "original", which takes the image's own ratio once it loads. Until then, the box is height rem tall, or the 80 spacing step when height is not set.
- objectFit maps to React Native's resizeMode: cover and contain stay the same, fill becomes stretch, none becomes center and scale-down becomes contain.
- An empty alt hides the image from screen readers, as on the web. With alt, the image is read out by it.
- fillWidth is on by default.
Media extends Flex props, so spacing, radius, border, sizes and the rest apply.