A placeholder block for first-load content (muted fill, pulsing; no pulse with reduced motion). Size and corner radius come from class, widths computed from data from style, so the blocks take the shape of the real content and nothing jumps when data arrives. A load that ends quickly should not flash a skeleton: delayed keeps it transparent for SKELETON_DELAY (300ms) after it mounts.
Status: stable · Components: Skeleton
Import
Section titled “Import”import { Skeleton } from 'nacre'One Skeleton is one block: give it the same height and width as the real text line with h-* / w-*.
import { View } from 'nsh'import { Skeleton } from 'nacre'
export function SkeletonUsage() { return ( <View class="w-[320px] max-w-full gap-2"> <Skeleton testID="demo-skeleton-line" class="h-2.5 w-full" /> <Skeleton class="h-2.5 w-5/6" /> <Skeleton class="h-2.5 w-2/3" /> </View> )}Examples
Section titled “Examples”List row
Section titled “List row”The avatar uses rounded-full; the title and subtitle are one long, one short. The row height matches a real ListRow.
import { View } from 'nsh'import { Skeleton, TOUCH } from 'nacre'
export function SkeletonListRow() { return ( <View class={`${TOUCH ? 'w-full' : 'w-[280px] max-w-full rounded-xl border border-border'} p-1.5 gap-0.5`}> {[0, 1, 2].map(() => ( <View class="h-[52px] px-2.5 flex-row items-center gap-2.5"> <Skeleton class="w-[22px] h-[22px] rounded-full" /> <View class="flex-1 gap-2"> <Skeleton class="h-3 w-1/2" /> <Skeleton class="h-2.5 w-3/4" /> </View> </View> ))} </View> )}The stat card’s title, value and change each get a block; the card frame is drawn as usual.
import { View } from 'nsh'import { Card, Skeleton, TOUCH } from 'nacre'
export function SkeletonCard() { return ( <View classList={{ 'flex-row gap-[21px] p-[21px] rounded-xl bg-plane': !TOUCH, 'gap-3': TOUCH }}> {[0, 1, 2].map(() => ( <View class="flex-1"> <Card variant="tile" size="sm"> <Skeleton class="h-3 w-16" /> <Skeleton class="h-6 w-24" /> <Skeleton class="h-2.5 w-20" /> </Card> </View> ))} </View> )}Loading transition
Section titled “Loading transition”The first load shows a skeleton, replaced by real content when data arrives; placeholder and content are the same height, so nothing jumps.
import { Text, View, signal } from 'nsh'import { Avatar, Button, Skeleton, TEXT_SIZE } from 'nacre'
export function SkeletonLoading() { const loading = signal(true) return ( <View class="gap-3"> <View class="w-[280px] max-w-full h-[52px] px-2.5 flex-row items-center gap-2.5 rounded-xl border border-border"> <If when={!loading()} else={ <> <Skeleton class="w-[22px] h-[22px] rounded-full" /> <View class="flex-1 gap-2"> <Skeleton class="h-3 w-1/2" /> <Skeleton class="h-2.5 w-3/4" /> </View> </> } > <Avatar name="Lin Jiayi" size={22} /> <View class="flex-1 gap-0.5"> <Text class={`${TEXT_SIZE.body} text-foreground`}>Lin Jiayi</Text> <Text class={`${TEXT_SIZE.caption} text-muted-foreground`}>HK stock account opening · Tier 1</Text> </View> </If> </View> <View class="flex-row"> <Button size="sm" variant="outline" onPress={() => loading.update((v) => !v)}> {loading() ? 'Simulate data arrival' : 'Reload'} </Button> </View> </View> )}Accessibility
Section titled “Accessibility”- Skeleton blocks are not in the accessibility tree; give the loading region a separate readable state (such as the list’s “Loading”).
Do / Don’t
Section titled “Do / Don’t”Do
- Match the row height and column width of the real content
- Use skeletons only on first load (when there is no previous data)
- Show about as many skeleton rows as the real content fills, and only what is in view
- Show the skeleton only after SKELETON_DELAY of loading (delayed, or delayed(when) for your own state)
- Let one container pulse a group of bars, with pulse={false} on each bar
Don’t
- Swap the whole block for a skeleton on paging or refresh (keep the old data and show loading)
- Use brand colors or custom animation on skeleton blocks
- Show only a skeleton after several seconds of loading (show an error or retry)
Property descriptions follow the Chinese source comments.
Skeleton
Section titled “Skeleton”| Prop | Type | Default | Description |
|---|---|---|---|
class |
string |
— | |
style |
StyleProp<ViewStyle> |
— | 直接给尺寸、位置(按数据算出来的宽度),省掉外面再套一层定宽 View |
testID |
string |
— | |
pulse |
boolean |
— | 自己脉动(默认);一组灰条由外层容器统一脉动时传 false,一屏只跑一个动画 |
delayed |
boolean |
— | 挂上后先透明 SKELETON_DELAY,加载很快结束时不闪 |
* required