-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRiveStateMachineInputsExample.tsx
More file actions
91 lines (86 loc) · 2.37 KB
/
RiveStateMachineInputsExample.tsx
File metadata and controls
91 lines (86 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
import { useEffect } from 'react';
import { Fit, RiveView, useRive, useRiveFile } from 'react-native-rive';
import { type Metadata } from '../helpers/metadata';
export default function StateMachineInputsExample() {
const { riveViewRef, setHybridRef } = useRive();
const { riveFile, isLoading, error } = useRiveFile(
require('../../assets/rive/rating.riv')
);
useEffect(() => {
if (riveViewRef) {
try {
// Original value
console.log(
'Number value: ',
riveViewRef.getNumberInputValue('rating')
);
// Set the value of the input
riveViewRef.setNumberInputValue('rating', 3.0);
// On Android, this will return the value of the input after it has been set the next frame
console.log(
'Number value: ',
riveViewRef.getNumberInputValue('rating')
);
// Add a delay to allow the view controller to be ready
setTimeout(() => {
console.log(
'Number value after delay: ',
riveViewRef.getNumberInputValue('rating')
);
}, 16);
} catch (err) {
console.error(err);
}
}
}, [riveViewRef]);
return (
<View style={styles.container}>
<View style={styles.riveContainer}>
{isLoading ? (
<ActivityIndicator size="large" color="#0000ff" />
) : error ? (
<Text style={styles.errorText}>{error}</Text>
) : riveFile ? (
<RiveView
style={styles.rive}
autoBind={false}
autoPlay={true}
fit={Fit.Contain}
file={riveFile}
hybridRef={setHybridRef}
/>
) : null}
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
padding: 20,
},
riveContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f5f5f5',
borderRadius: 10,
overflow: 'hidden',
},
rive: {
width: '100%',
height: '100%',
},
errorText: {
color: 'red',
textAlign: 'center',
padding: 20,
},
});
StateMachineInputsExample.metadata = {
name: 'State Machine Inputs',
description:
'Shows how to get and set state machine input values programmatically',
} satisfies Metadata;