# React Native Skeleton

> A React Native skeleton loader for iOS, Android and the web: placeholder shapes that pulse while content loads, hidden from screen readers and still when the OS asks to reduce motion.

# Skeleton

A placeholder in the shape of content that's still loading. It pulses gently, so the screen shows its layout before the data arrives.

```tsx
import { Skeleton } from 'patine-ui';
```

```tsx live
import { useEffect, useState } from 'react';
import { Image } from 'react-native';
import { Avatar, Button, Card, CardContent, HStack, Skeleton, Text, VStack } from 'patine-ui';

export default function Example() {
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    if (!loading) return;
    const id = setTimeout(() => setLoading(false), 1800);
    return () => clearTimeout(id);
  }, [loading]);
  return (
    <VStack gap="sm" style={{ maxWidth: 380, width: '100%' }}>
      <Card style={{ overflow: 'hidden' }} aria-busy={loading}>
        <CardContent style={{ paddingTop: 16, gap: 12 }}>
          <HStack gap="md" align="center">
            {loading ? <Skeleton width={40} height={40} radius="full" /> : <Avatar name="Maya Cohen" src="https://picsum.photos/id/64/160/160" />}
            <VStack gap="xs" style={{ flex: 1 }}>
              {loading ? <Skeleton width="50%" /> : <Text weight="medium">Maya Cohen</Text>}
              {loading ? <Skeleton width="30%" height={12} /> : <Text size="sm" color="textSecondary">2 hours ago</Text>}
            </VStack>
          </HStack>
          {loading ? (
            <VStack gap="sm">
              <Skeleton />
              <Skeleton width="80%" />
            </VStack>
          ) : (
            <Text>Golden hour at the falls. Worth the 6am start ☀️</Text>
          )}
          {loading ? <Skeleton height={180} radius="md" /> : <Image source={{ uri: 'https://picsum.photos/id/1018/760/360' }} style={{ height: 180, borderRadius: 12 }} alt="Mountains at sunrise" />}
        </CardContent>
      </Card>
      <Button variant="outline" onPress={() => setLoading(true)} disabled={loading}>Reload</Button>
    </VStack>
  );
}
```

## Example: a weather card

A weather widget while the forecast loads: the skeleton has the card's real shape, the big temperature, the line under it and the hourly row, so nothing moves when the data arrives.

```tsx live
import { useEffect, useState } from 'react';
import { Box, Button, HStack, Skeleton, Text, VStack } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const HOURS = [
  { at: 'Now', icon: 'sun', t: 14 },
  { at: '13', icon: 'sun', t: 15 },
  { at: '14', icon: 'cloud', t: 15 },
  { at: '15', icon: 'cloud', t: 13 },
  { at: '16', icon: 'droplet', t: 11 },
] as const;

export default function Example() {
  const [loading, setLoading] = useState(true);
  useEffect(() => {
    if (!loading) return;
    const id = setTimeout(() => setLoading(false), 1600);
    return () => clearTimeout(id);
  }, [loading]);
  return (
    <VStack gap="sm" style={{ width: '100%', maxWidth: 340 }}>
      <Box border radius="lg" padding="lg" gap="md" aria-busy={loading}>
        <VStack gap="xs">
          {loading ? <Skeleton width={110} height={44} /> : <Text size="3xl" weight="semibold">14°</Text>}
          {loading ? <Skeleton width="60%" height={14} /> : <Text color="textSecondary">Lisbon · Sunny, rain after 4 pm</Text>}
        </VStack>
        <HStack justify="space-between">
          {HOURS.map((h) => (
            <VStack key={h.at} gap="xs" align="center">
              {loading ? <Skeleton width={28} height={12} /> : <Text size="xs" color="textSecondary">{h.at}</Text>}
              {loading ? <Skeleton width={24} height={24} radius="full" /> : <Icon name={h.icon} color={h.icon === 'sun' ? 'warning' : 'textSecondary'} />}
              {loading ? <Skeleton width={24} height={14} /> : <Text size="sm">{h.t}°</Text>}
            </VStack>
          ))}
        </HStack>
      </Box>
      <Button variant="outline" disabled={loading} onPress={() => setLoading(true)}>
        Refresh
      </Button>
    </VStack>
  );
}
```

## Shapes

`width` and `height` take points or percentages; `radius` takes a step, `'full'` for a circle or pill, or points.

```tsx live
import { HStack, Skeleton } from 'patine-ui';

export default function Example() {
  return (
    <HStack gap="md" align="center" wrap>
      <Skeleton width={48} height={48} radius="full" />
      <Skeleton width={64} height={64} radius="md" />
      <Skeleton width={96} height={32} radius="full" />
      <Skeleton width={140} height={16} />
      <Skeleton width={80} height={80} radius={0} />
    </HStack>
  );
}
```

## A list loading

Repeat the row's shape a few times. Vary the widths a little so it doesn't look like a barcode.

```tsx live
import { HStack, Skeleton, VStack } from 'patine-ui';

const WIDTHS = ['70%', '55%', '80%', '60%'] as const;

export default function Example() {
  return (
    <VStack gap="lg" style={{ maxWidth: 380, width: '100%' }} aria-busy accessibilityLabel="Loading contacts">
      {WIDTHS.map((width, i) => (
        <HStack key={i} gap="md" align="center">
          <Skeleton width={40} height={40} radius="full" />
          <VStack gap="xs" style={{ flex: 1 }}>
            <Skeleton width={width} />
            <Skeleton width="35%" height={12} />
          </VStack>
          <Skeleton width={56} height={28} radius="full" />
        </HStack>
      ))}
    </VStack>
  );
}
```

## A product grid loading

```tsx live
import { HStack, Skeleton, VStack } from 'patine-ui';

export default function Example() {
  return (
    <HStack gap="md" wrap>
      {[0, 1, 2].map((i) => (
        <VStack key={i} gap="sm" style={{ width: 120 }}>
          <Skeleton height={120} radius="md" />
          <Skeleton width="85%" />
          <Skeleton width="40%" height={14} />
        </VStack>
      ))}
    </HStack>
  );
}
```

## Accessibility

Skeletons are hidden from screen readers. Mark the region that's loading with `aria-busy` so assistive technology knows to wait, and the pulse stops when the OS asks to reduce motion.

## Props

Skeleton also takes `View` props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `width` | `DimensionValue` | `'100%'` | Points or a percentage. |
| `height` | `DimensionValue` | `16` | About a line of text by default. |
| `radius` | `'sm' \| 'md' \| 'lg' \| 'full' \| number` | `'sm'` | A radius step, `full` for a circle or pill, or points. |
| `theme` | `DeepPartial<Theme>` | — | Theme override. |
