$ git show skeleton-crossfade
Skeleton to content
A pulsing placeholder holds the layout while loading, then crossfades into the real content in place.
Ada LovelacePosted 2 min ago
// Reanimated 4: the pulse is a CSS animation; enter/exit still use layout animations
const pulse = { from: { opacity: 1 }, to: { opacity: 0.5 } };
function Skeleton() {
return (
<Animated.View style={[styles.row, {
animationName: pulse,
animationDuration: '700ms',
animationIterationCount: 'infinite',
animationDirection: 'alternate',
}]}>
<View style={[styles.avatar, styles.bone]} />
<View style={{ flex: 1, gap: 6 }}>
<View style={[styles.line, styles.bone]} />
<View style={[styles.line, styles.bone, { width: '60%' }]} />
</View>
</Animated.View>
);
}
const [post, setPost] = useState<Post | null>(null);
<View style={{ minHeight: 48 }}> {/* fixed height so nothing jumps */}
{post ? (
<Animated.View key="content" entering={FadeIn.duration(300)} style={styles.row}>
<Image source={{ uri: post.avatar }} style={styles.avatar} />
<View>
<Text style={styles.name}>{post.author}</Text>
<Text style={styles.meta}>{post.time}</Text>
</View>
</Animated.View>
) : (
// Absolute, so the exiting skeleton overlaps the entering content instead of stacking
<Animated.View key="skeleton" exiting={FadeOut.duration(300)} style={StyleSheet.absoluteFill}>
<Skeleton />
</Animated.View>
)}
</View>