frontend-rive
1
总安装量
1
周安装量
#42792
全站排名
安装命令
npx skills add https://smithery.ai
Agent 安装分布
claude-code
1
Skill 文档
Rive
Interactive animations with built-in state machines. Animation logic inside the .riv file.
When to Use
- Animations that REACT to input (hover, click, data)
- Animated buttons, toggles, checkboxes
- Progress indicators driven by values
- Multi-state characters/icons
- Complex state transitions
When NOT to Use
- Simple decorative loops â Lottie
- Static illustrations â SVG
- Quick spinners â CSS/Lottie
Key Concept: State Machines
âââââââââââââââââââââââââââââââââââ
â Rive State Machine â
â ââââââââ hover âââââââââ â
â â Idle â ââââââ⺠â Hover â â
â ââââââââ âââââââââ â
â â² click â â
â âââââââââââââ ââââ â
â â
â Inputs: hover (bool), click â
âââââââââââââââââââââââââââââââââââ
You control inputs â Rive handles animations
Process
SETUP â CONNECT â CONTROL
- Install:
npm install @rive-app/react-canvas - Load .riv file with state machine
- Get inputs via
useStateMachineInput - Connect to UI events
Quick Start
import { useRive, useStateMachineInput } from '@rive-app/react-canvas';
function InteractiveButton() {
const { rive, RiveComponent } = useRive({
src: '/button.riv',
stateMachines: 'ButtonState',
autoplay: true,
});
const hover = useStateMachineInput(rive, 'ButtonState', 'hover');
const press = useStateMachineInput(rive, 'ButtonState', 'pressed');
return (
<RiveComponent
onMouseEnter={() => hover && (hover.value = true)}
onMouseLeave={() => hover && (hover.value = false)}
onMouseDown={() => press && (press.value = true)}
onMouseUp={() => press && (press.value = false)}
/>
);
}
Input Types
Boolean: input.value = true/false # hover, isActive
Number: input.value = 75 # progress (0-100)
Trigger: input.fire() # onClick, onComplete
Common Patterns
Toggle:
- Boolean input "isOn"
- onClick: toggle value
Progress:
- Number input "progress" (0-100)
- useEffect: sync with prop
Notification Bell:
- Number input "count"
- Trigger input "ring"
- onClick: fire() trigger
Decision: Rive vs Lottie
| Need | Use |
|---|---|
| Just plays/loops | Lottie |
| Reacts to hover | Rive |
| Controlled by data | Rive |
| Multiple states | Rive |
| Simple loader | Lottie |
Layout & Sizing
// Container controls size
<div className="w-64 h-64">
<RiveComponent />
</div>
// Responsive with aspect ratio
<div className="w-full aspect-video max-w-2xl">
<RiveComponent />
</div>
SSR & Hydration
// Always 'use client'
'use client'
// Dynamic import for heavy animations
const Animation = dynamic(() => import('./RiveAnimation'), { ssr: false })
// Or mounted check
const [mounted, setMounted] = useState(false)
useEffect(() => setMounted(true), [])
if (!mounted) return <Skeleton />
Performance
// Lazy load
const Rive = dynamic(() => import('./RiveComponent'), { ssr: false })
// Pause when not visible
const { ref, inView } = useInView()
useEffect(() => { inView ? rive?.play() : rive?.pause() }, [inView])
Troubleshooting
"Animation not playing":
â Check autoplay: true
â Check stateMachines name (case-sensitive)
â Check .riv path in public/
"Inputs undefined":
â Always check: if (input) input.value = x
â Verify input names match Rive editor
"Hydration mismatch":
â Add 'use client'
â Use dynamic(() => ..., { ssr: false })
"Wrong size":
â Container needs explicit width/height
â Use aspect-ratio utilities
References
- patterns.md â Toggle, Checkbox, Progress, Like button, Form integration
External Resources
- https://rive.app/docs/runtimes/react â React runtime docs
- https://rive.app/community â Free .riv files
- For latest API â use context7 skill