Rive React Native

9.8.2 · maintenance · verified Sun Apr 19

This package, currently at stable version 9.8.2, provides a React Native runtime library for integrating real-time interactive animations created with the Rive design tool into iOS and Android applications. It acts as a wrapper around the native Rive iOS and Android runtimes, exposing a `Rive` component and a ref pattern for controlling animations and state machines within React Native. While actively maintained with frequent updates to synchronize with the native Rive SDKs and address critical bugs, this package is explicitly identified as a *legacy runtime*. The Rive team is actively promoting migration to a new, performance-optimized `@rive-app/react-native` (Nitro runtime), with a long-term goal for full transition to the new package. Its release cadence involves minor version bumps and bug fixes, typically related to native runtime synchronization and platform-specific build issues.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to embed a Rive animation from a local asset (e.g., 'truck_delivery_loop.riv') in a React Native component, including basic autoplay, specifying artboards/animations, and interacting with the Rive component via a ref.

import React from 'react';
import { View, StyleSheet, Text } from 'react-native';
import { Rive, RiveRef } from 'rive-react-native';

const RiveAnimationScreen: React.FC = () => {
  const riveRef = React.useRef<RiveRef>(null);

  // Example of how you might interact with the Rive component via its ref
  React.useEffect(() => {
    // For instance, activating a state machine input after 3 seconds
    const timer = setTimeout(() => {
      if (riveRef.current) {
        console.log('Activating input...');
        riveRef.current.fireState('Motion', 'Trigger1'); // Example: assumes a state machine 'Motion' with a trigger input 'Trigger1'
      }
    }, 3000);
    return () => clearTimeout(timer);
  }, []);

  return (
    <View style={styles.container}>
      <Text style={styles.header}>Loading Rive Animation</Text>
      <Rive
        ref={riveRef}
        resourceName="truck_delivery_loop" // Ensure 'truck_delivery_loop.riv' is in your native project's assets
        autoplay={true}
        artboardName="New Artboard" // Optional: specify a particular artboard
        animationName="Timeline 1" // Optional: specify a particular animation
        style={styles.riveAnimation}
        onLoad={() => console.log('Rive file loaded successfully!')}
        onError={(error) => console.error('Rive error:', error)}
      />
      <Text style={styles.footer}>Interactive Rive animation</Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  header: {
    fontSize: 20,
    marginBottom: 20,
  },
  riveAnimation: {
    width: 300,
    height: 300,
    backgroundColor: 'transparent',
  },
  footer: {
    marginTop: 20,
    fontSize: 16,
    color: '#666',
  },
});

export default RiveAnimationScreen;

view raw JSON →