Skip to content

Commit c288b4a

Browse files
committed
docs: say how to load an image in Card.Media
1 parent cae4adf commit c288b4a

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ Prior history: these packages were published as `@onlynative/*` through
1212
## Unreleased
1313

1414
**No breaking change.** One fix, two new `ListItem` props and one new
15-
`List` part in `components`, and one fix in the `llms.txt` files.
15+
`List` part in `components`, one fix in the `llms.txt` files, and one new
16+
docs section.
17+
18+
### The Card page says how to load an image
19+
20+
The library has no image component, and the Card page did not say so. A
21+
React Native `Image` in `Card.Media` has no loading state and no error
22+
state, so a slow or broken URL left the region empty. The new "Images"
23+
section says that `Card.Media` sizes the image and does not load it, and
24+
names `expo-image` with `placeholder`, `placeholderContentFit`,
25+
`transition` and `onError`. No code change.
1626

1727
### `List.Headline` for a long list in a `FlatList`
1828

‎docs/docs/components/card.mdx‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,31 @@ The card needs an `onPress` to become interactive. `Link` adds its own navigatio
167167

168168
With `height` or `aspectRatio` set, each child fills the region, so a plain `Image` needs no style of its own. The children stack in order, so a second child is an overlay. A child's own `width` or `height` wins.
169169

170+
### Images
171+
172+
The library has no image component. `Card.Media` sizes the image component that you give it, and it does not load the image. A React Native `Image` has no loading state and no error state, so a slow or broken URL leaves the region empty.
173+
174+
On Expo, use [`expo-image`](https://docs.expo.dev/versions/latest/sdk/image/):
175+
176+
- `placeholder` shows while no image has loaded: a blurhash or a thumbhash from your data, or a local image.
177+
- `placeholderContentFit="cover"` gives the placeholder the same fit as the image. The default, `'scale-down'`, can flicker when the image replaces the placeholder.
178+
- `transition` fades the image in. A number is the time in milliseconds.
179+
- `onError` fires when the load fails. Show your own fallback there.
180+
181+
```tsx
182+
import { Image } from 'expo-image'
183+
184+
<Card.Media height={195}>
185+
<Image
186+
source={{ uri: article.imageUrl }}
187+
placeholder={{ blurhash: article.blurhash }}
188+
placeholderContentFit="cover"
189+
contentFit="cover"
190+
transition={200}
191+
/>
192+
</Card.Media>
193+
```
194+
170195
### Raw children still work
171196

172197
The slots are additive. A card with raw children renders exactly as before and stays unpadded, so you own the spacing:

0 commit comments

Comments
 (0)