### Start Metro Server for Example App Source: https://github.com/rive-app/rive-react-native/blob/main/CONTRIBUTING.md Starts the Metro bundler, which is required to run the example application. ```sh yarn example start ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/rive-app/rive-react-native/blob/main/example/README.md Run this command in your project directory to install all necessary dependencies. ```bash npm install ``` -------------------------------- ### Run Example App on Android Source: https://github.com/rive-app/rive-react-native/blob/main/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. ```sh yarn example android ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/rive-app/rive-react-native/blob/main/CONTRIBUTING.md Builds and runs the example application on an iOS device or simulator. ```sh yarn example ios ``` -------------------------------- ### Install rive-react-native Source: https://github.com/rive-app/rive-react-native/blob/main/docs/usage-guide.md Install the SDK using yarn. For iOS, run pod install. ```sh yarn add rive-react-native ``` -------------------------------- ### Install rive-react-native Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/GUIDE.md Install the rive-react-native library using npm or yarn. ```bash npm install rive-react-native # or yarn add rive-react-native ``` -------------------------------- ### Start the Expo Development Server Source: https://github.com/rive-app/rive-react-native/blob/main/example/README.md This command starts the Expo development server, allowing you to preview your app on various platforms. ```bash npx expo start ``` -------------------------------- ### Update Example Project with Pod Update Source: https://github.com/rive-app/rive-react-native/blob/main/CONTRIBUTING.md After updating the podspec, run this command in the example folder to fetch the new RiveRuntime dependency. ```sh pod update RiveRuntime ``` -------------------------------- ### Complete Character Controller Example Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/api-reference/hooks.md A comprehensive example demonstrating the use of `useRive`, `useRiveNumber`, `useRiveBoolean`, and `useRiveTrigger` to control a Rive animation character. Includes state display and interactive controls. ```typescript import { useEffect, useState } from 'react'; import { Button, View, Text, StyleSheet } from 'react-native'; import Rive, { useRive, useRiveNumber, useRiveBoolean, useRiveTrigger, } from 'rive-react-native'; export default function CharacterController() { const [setRiveRef, riveRef] = useRive(); const [speed, setSpeed] = useRiveNumber(riveRef, 'speed'); const [isJumping, setIsJumping] = useRiveBoolean(riveRef, 'isJumping'); const jumpTrigger = useRiveTrigger(riveRef, 'jump', () => { console.log('Jump completed!'); }); return ( Speed: {speed?.toFixed(2) || '0.00'} Jumping: {isJumping ? 'Yes' : 'No'} ); } ``` -------------------------------- ### FileNotFound Error Example (HTTP) Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/errors.md Demonstrates a FileNotFound error when a URL points to a non-existent or inaccessible animation file. The server returns a 404 or similar error. ```typescript // HTTP: URL returns 404 ``` -------------------------------- ### Example of Native Error Conversion Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/api-reference/utilities.md Shows how to handle errors originating from native code by converting them to RNRiveError and logging unknown errors. ```typescript const nativeError = { type: 'FileNotFound', message: 'Could not load animation.riv' }; const error = convertErrorFromNativeToRN(nativeError); if (error) { handleError(error); } else { console.warn('Unknown error from native:', nativeError); } ``` -------------------------------- ### Set Color Using RiveRGBA Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/types.md Example of how to set a color for an artboard element using the `setColor` method with a `RiveRGBA` object. ```typescript riveRef.current?.setColor('MainArtboard.fillColor', { r: 255, g: 0, b: 0, a: 255 }); ``` -------------------------------- ### Basic Rive Component Usage Source: https://github.com/rive-app/rive-react-native/blob/main/docs/rive-react-native-reference.md Demonstrates the basic setup of the Rive component by providing a resource name for the animation file. Ensure the resource file is available in your project's assets. ```tsx import Rive from 'rive-react-native'; function App() { return ; } ``` -------------------------------- ### onPlay Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/configuration.md Fired when an animation or state machine starts playing. It provides the animation name and a boolean indicating if it's a state machine. ```APIDOC ## onPlay ### Description Fired when animation or state machine starts playing. ### Parameters #### Callback Parameters - **animationName** (string) - The name of the animation or state machine. - **isStateMachine** (boolean) - True if the playing entity is a state machine, false otherwise. ### Example ```typescript { console.log(`Playing: ${animationName} (SM: ${isStateMachine})`); }} {...} /> ``` ``` -------------------------------- ### useRiveString Hook Example Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/api-reference/hooks.md This example demonstrates using the useRiveString hook to synchronize a TextInput component with a string property in a Rive animation. Changes in the text input update the animation's text property. ```typescript import { useRive, useRiveString } from 'rive-react-native'; import { TextInput, View } from 'react-native'; export default function StringExample() { const [setRiveRef, riveRef] = useRive(); const [displayText, setDisplayText] = useRiveString(riveRef, 'MainArtboard.message'); return ( ); } ``` -------------------------------- ### Custom iOS Runtime Version in Podfile.properties.json Source: https://github.com/rive-app/rive-react-native/blob/main/README.md Demonstrates how to set a custom RiveRuntimeIOSVersion for iOS projects by creating or editing the ios/Podfile.properties.json file. After modification, run 'pod install'. ```json { "RiveRuntimeIOSVersion": "6.18.2" } ``` -------------------------------- ### IncorrectRiveFileUrl Error Examples Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/errors.md Illustrates IncorrectRiveFileUrl errors for malformed or unsupported URLs. Ensure the URL is valid HTTP/HTTPS and correctly formatted. ```typescript // Invalid URL ``` -------------------------------- ### Rive React Native Alignment Examples Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/configuration.md Examples showing how to align Rive animations within component bounds. Use 'Center' for default, 'TopLeft' for top-left alignment, and 'BottomRight' for bottom-right alignment. ```typescript // Center animation in bounds ``` ```typescript // Align to top-left ``` ```typescript // Align to bottom-right ``` -------------------------------- ### Handle Animation Playback Start Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/configuration.md Use the onPlay callback to detect when an animation or state machine begins playing. It provides the animation name and a boolean indicating if it's a state machine. ```typescript { console.log(`Playing: ${animationName} (SM: ${isStateMachine})`); }} {...} /> ``` -------------------------------- ### Using Rive with require() Asset Source Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/types.md Example of using the Rive component with an animation file imported using require(). ```typescript import animationFile from './animations/my-animation.riv'; ``` -------------------------------- ### Complete Rive Component Configuration Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/configuration.md Demonstrates a full configuration of the Rive component with animation, fit, alignment, and event handlers. Use this for complex setups requiring precise control over animation playback and display. ```typescript import React, { useRef } from 'react'; import { View, Button, StyleSheet } from 'react-native'; import Rive, { RiveRef, Fit, Alignment, AutoBind, LoopMode, Direction, } from 'rive-react-native'; export default function ConfiguredRive() { const riveRef = useRef(null); return ( console.log(`Playing: ${name}`)} onError={(error) => console.error(`Error: ${error.message}`)} /> ); } ``` -------------------------------- ### Utilities Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/MANIFEST.txt Helper functions for working with Rive data and types. ```APIDOC ## Utilities ### Description Helper functions for working with Rive data and types. ### Available Utilities - **parseColor(hex: string)**: Parses a hex color string into an RGBA object. - **intToRiveRGBA(color: number)**: Converts an integer color representation to an RGBA object. - **parsePossibleSources(sources: any)**: Parses various source formats for Rive assets. - **getPropertyTypeString(type: PropertyType)**: Returns the string name of a property type. - **isEnum(value: any)**: Type guard to check if a value is an enum. - **convertErrorFromNativeToRN(error: any)**: Converts native errors to React Native error format. ``` -------------------------------- ### MalformedFile Error Examples Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/errors.md Illustrates MalformedFile errors for corrupted or invalid Rive files. This can occur with incomplete downloads or manual file corruption. Regenerate or re-download the file. ```typescript // Downloaded incomplete .riv file // Renamed JPG to .riv ``` -------------------------------- ### Get Number State Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/api-reference/Rive.md Retrieves the current value of a root-level number input from a state machine. Returns a Promise resolving to the number value or null if an error occurs. ```typescript const speed = await riveRef.current?.getNumberState('speed'); console.log('Speed:', speed); ``` -------------------------------- ### Verify Code Quality with Yarn Commands Source: https://github.com/rive-app/rive-react-native/blob/main/CONTRIBUTING.md Run these commands to ensure your code adheres to TypeScript and ESLint standards. Use the `--fix` flag to automatically correct formatting issues. ```sh yarn typescript yarn lint ``` ```sh yarn lint --fix ``` -------------------------------- ### Get Boolean State Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/api-reference/Rive.md Retrieves the current value of a root-level boolean input from a state machine. Returns a Promise resolving to the boolean value or null if an error occurs. ```typescript const isMoving = await riveRef.current?.getBooleanState('isMoving'); console.log('Moving:', isMoving); ``` -------------------------------- ### Basic Animation with URL Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/api-reference/Rive.md Load and play a Rive animation from a URL. Ensure the Rive component fills its container using the `style` prop. ```typescript import React, { useRef } from 'react'; import Rive, { RiveRef, Fit, Alignment } from 'rive-react-native'; export default function BasicAnimation() { const riveRef = useRef(null); return ( ); } ``` -------------------------------- ### Properties Methods Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/INDEX.md Set various types of properties on Rive elements. ```APIDOC ## Properties (RiveRef) ### Description Methods for setting properties on Rive elements. ### Methods - `setBoolean(path, value) => void`: Set boolean property. - `setString(path, value) => void`: Set string property. - `setNumber(path, value) => void`: Set number property. - `setColor(path, color) => void`: Set color property. - `setEnum(path, value) => void`: Set enum property. - `trigger(path) => void`: Fire trigger property. - `setTextRunValue(name, value) => void`: Set text run content. - `setTextRunValueAtPath(name, value, path) => void`: Set nested text run. ``` -------------------------------- ### IncorrectStateMachineName Error Example (Ref) Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/errors.md Shows an IncorrectStateMachineName error when calling fireState() with a non-existent state machine name via a ref. Ensure the state machine name is correct. ```typescript // Or via ref riveRef.current?.fireState('InvalidSM', 'trigger'); // state machine doesn't exist ``` -------------------------------- ### Handling Rive Events Source: https://github.com/rive-app/rive-react-native/blob/main/_autodocs/MANIFEST.txt Demonstrates how to listen for and handle various events emitted by the Rive component, such as animation completion or state changes. ```javascript import Rive from '@rive-app/react-native'; function EventHandlingRive() { const handleStateChanged = (event: any) => { console.log('State changed:', event); }; const handleRiveEvent = (event: any) => { console.log('Rive event received:', event); }; return ( ); } ```