-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRiveTextRunExample.tsx
More file actions
95 lines (90 loc) · 2.31 KB
/
RiveTextRunExample.tsx
File metadata and controls
95 lines (90 loc) · 2.31 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
92
93
94
95
/* eslint-disable @typescript-eslint/no-deprecated */
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
import { useEffect } from 'react';
import { Fit, RiveView, useRive, useRiveFile } from '@rive-app/react-native';
import { type Metadata } from '../shared/metadata';
/**
* @deprecated Setting text run values is deprecated. Use data binding instead.
*
* See https://rive.app/docs/runtimes/data-binding
*
* Demonstrates getting and setting text run values in Rive graphics
*/
export default function TextRunExample() {
const { riveViewRef, setHybridRef } = useRive();
const { riveFile, isLoading, error } = useRiveFile(
require('../../assets/rive/hello_world_text.riv')
);
useEffect(() => {
if (riveViewRef) {
try {
console.log(riveViewRef.getTextRunValue('name'));
riveViewRef.setTextRunValue('name', 'React Native');
console.log(riveViewRef.getTextRunValue('name'));
} 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.message}</Text>
) : riveFile ? (
<RiveView
style={styles.rive}
autoPlay={true}
fit={Fit.Contain}
file={riveFile}
hybridRef={setHybridRef}
/>
) : null}
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
padding: 20,
},
title: {
fontSize: 24,
fontWeight: 'bold',
textAlign: 'center',
marginTop: 20,
marginBottom: 10,
},
subtitle: {
fontSize: 16,
color: '#666',
textAlign: 'center',
marginBottom: 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,
},
});
TextRunExample.metadata = {
name: 'Text Run',
description:
'Demonstrates getting and setting text run values in Rive graphics',
} satisfies Metadata;