By default, RiveView automatically uses the default artboard and state machine configured in the Editor. In most cases, you only need to provide the file prop.For programmatic control, you can optionally specify artboardName and stateMachineName props to use a different artboard or state machine.export default function PlaybackExample() {
const { riveFile } = useRiveFile(
'https://cdn.rive.app/animations/vehicles.riv'
);
return (
<View style={styles.container}>
<View style={styles.riveContainer}>
{riveFile ? <RiveView file={riveFile} style={styles.rive} /> : null}
</View>
</View>
);
}
Controlling State Machine Playback
For more control, you can manage playback and set the artboard/state machine combination:Automatically start playing the state machine.
The name of the artboard to display.If not set, the default artboard will be used, as configured in the Editor.
The name of the state machine to play.If not set, the default state machine will be used, as configured in the Editor.
And manage play, pause, and reset on the Rive view reference.import { Fit, RiveView, useRive, useRiveFile } from '@rive-app/react-native';
export default function PlaybackExample() {
const { riveViewRef, setHybridRef } = useRive();
const { riveFile } = useRiveFile(
'https://cdn.rive.app/animations/vehicles.riv'
);
const play = () => {
riveViewRef?.play();
};
const pause = () => {
riveViewRef?.pause();
};
const reset = () => {
riveViewRef?.reset();
};
return (
<View style={styles.container}>
<View style={styles.riveContainer}>
{riveFile ? (
<RiveView
file={riveFile}
hybridRef={setHybridRef}
autoPlay={false}
artboardName="Truck" // specify the artboard to play
stateMachineName="bumpy" // specify the state machine to play
style={styles.rive}
/>
) : null}
</View>
<Button onPress={play} title="Play" />
<Button onPress={pause} title="Pause" />
<Button onPress={reset} title="Reset" />
</View>
);
}