Skeleton
Loading placeholder block sized by className to mirror final layout, with a reduced-motion-safe opacity pulse. Hidden from assistive tech; announce loading at the region level.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add skeletonSource files
Expand a file to read the source the installer copies into your app.
components/ui/skeleton/Skeleton.tsx
import * as React from 'react'
import type { ViewProps } from 'react-native'
import Animated, {
useAnimatedStyle,
useReducedMotion,
useSharedValue,
withRepeat,
withTiming,
} from 'react-native-reanimated'
import { cn } from '@/lib/utils'
import { motionDurations } from '@/lib/motion'
export interface SkeletonProps extends ViewProps {
className?: string
/** Gentle opacity pulse. Automatically static under reduced motion. */
pulse?: boolean
}
/** Loading placeholder that mirrors final geometry. Hidden from assistive
* tech — mark the loading region busy at the screen level instead. */
function Skeleton({ className, pulse = true, ...props }: SkeletonProps) {
const reduced = useReducedMotion()
const opacity = useSharedValue(1)
const pulseStyle = useAnimatedStyle(() => ({ opacity: opacity.value }))
const pulsing = pulse && !reduced
React.useEffect(() => {
opacity.value = pulsing ? withRepeat(withTiming(0.55, { duration: motionDurations.slow * 2 }), -1, true) : 1
}, [pulsing, opacity])
return (
<Animated.View
aria-hidden
style={pulsing ? pulseStyle : undefined}
className={cn('bg-muted rounded-md', className)}
{...props}
/>
)
}
export { Skeleton }
components/ui/skeleton/index.ts
export { Skeleton, type SkeletonProps } from './Skeleton'
Dependencies
Registry items
npm packages
react-native-reanimated