Skip to content

Commit e00aaa4

Browse files
committed
feat: add react-query + async APIs for exerciser
Add @tanstack/react-query for async ViewModel loading. Switch to async APIs (defaultArtboardViewModelAsync, createDefaultInstanceAsync). Fix prettier/lint warnings. Keep manual boxing — auto-box requires RN 0.80+.
1 parent 0b0d2e0 commit e00aaa4

4 files changed

Lines changed: 70 additions & 40 deletions

File tree

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@react-native-picker/picker": "^2.11.4",
1919
"@react-navigation/native": "^7.1.9",
2020
"@react-navigation/stack": "^7.3.2",
21+
"@tanstack/react-query": "^5.100.10",
2122
"react": "19.0.0",
2223
"react-native": "0.79.2",
2324
"react-native-gesture-handler": "2.29.1",

example/src/App.tsx

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { NavigationContainer, useNavigation } from '@react-navigation/native';
1212
import { createStackNavigator } from '@react-navigation/stack';
1313
import AsyncStorage from '@react-native-async-storage/async-storage';
14+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
1415
import { PagesList, type PageItem } from './PagesList';
1516
import { HomeMenu } from './shared/HomeMenu';
1617

@@ -95,38 +96,42 @@ function HomeScreen({ navigation }: { navigation: any }) {
9596
);
9697
}
9798

99+
const queryClient = new QueryClient();
100+
98101
export default function App() {
99102
return (
100-
<NavigationContainer>
101-
<Stack.Navigator
102-
screenOptions={{
103-
headerStyle: {
104-
backgroundColor: '#323232',
105-
},
106-
headerTintColor: '#fff',
107-
headerTitleStyle: {
108-
fontWeight: 'bold',
109-
},
110-
}}
111-
>
112-
<Stack.Screen
113-
name="Home"
114-
component={HomeScreen}
115-
options={{
116-
title: 'Rive Examples',
117-
headerRight: HeaderMenuButton,
103+
<QueryClientProvider client={queryClient}>
104+
<NavigationContainer>
105+
<Stack.Navigator
106+
screenOptions={{
107+
headerStyle: {
108+
backgroundColor: '#323232',
109+
},
110+
headerTintColor: '#fff',
111+
headerTitleStyle: {
112+
fontWeight: 'bold',
113+
},
118114
}}
119-
/>
120-
{PagesList.map(({ id, component, name }) => (
115+
>
121116
<Stack.Screen
122-
key={id}
123-
name={id}
124-
component={component}
125-
options={{ title: name }}
117+
name="Home"
118+
component={HomeScreen}
119+
options={{
120+
title: 'Rive Examples',
121+
headerRight: HeaderMenuButton,
122+
}}
126123
/>
127-
))}
128-
</Stack.Navigator>
129-
</NavigationContainer>
124+
{PagesList.map(({ id, component, name }) => (
125+
<Stack.Screen
126+
key={id}
127+
name={id}
128+
component={component}
129+
options={{ title: name }}
130+
/>
131+
))}
132+
</Stack.Navigator>
133+
</NavigationContainer>
134+
</QueryClientProvider>
130135
);
131136
}
132137

example/src/exercisers/RiveToReactNativeExample.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Switch,
88
} from 'react-native';
99
import { useEffect, useMemo, useState } from 'react';
10+
import { useQuery } from '@tanstack/react-query';
1011
import Animated, {
1112
runOnUI,
1213
useSharedValue,
@@ -89,27 +90,31 @@ export default function RiveToReactNativeExample() {
8990
}
9091

9192
function WithViewModelSetup({ file }: { file: RiveFile }) {
92-
// eslint-disable-next-line @typescript-eslint/no-deprecated -- replaced with async API in next PR
93-
const viewModel = useMemo(() => file.defaultArtboardViewModel(), [file]);
94-
const instance = useMemo(
95-
// eslint-disable-next-line @typescript-eslint/no-deprecated
96-
() => viewModel?.createDefaultInstance(),
97-
[viewModel]
98-
);
9993
const [useUIThread, setUseUIThread] = useState(true);
10094

101-
if (!instance || !viewModel) {
95+
const { data: instance, error } = useQuery({
96+
queryKey: ['bouncing-ball-instance', file],
97+
queryFn: async () => {
98+
const vm = await file.defaultArtboardViewModelAsync();
99+
if (!vm) throw new Error('No view model found.');
100+
const inst = await vm.createDefaultInstanceAsync();
101+
if (!inst) throw new Error('Failed to create view model instance');
102+
return inst;
103+
},
104+
});
105+
106+
if (error) {
102107
return (
103108
<View style={styles.errorContainer}>
104-
<Text style={styles.errorText}>
105-
{!viewModel
106-
? 'No view model found.'
107-
: 'Failed to create view model instance'}
108-
</Text>
109+
<Text style={styles.errorText}>{error.message}</Text>
109110
</View>
110111
);
111112
}
112113

114+
if (!instance) {
115+
return <ActivityIndicator size="large" color="#0000ff" />;
116+
}
117+
113118
return (
114119
<BouncingBallTracker
115120
instance={instance}

yarn.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5563,6 +5563,24 @@ __metadata:
55635563
languageName: node
55645564
linkType: hard
55655565

5566+
"@tanstack/query-core@npm:5.100.10":
5567+
version: 5.100.10
5568+
resolution: "@tanstack/query-core@npm:5.100.10"
5569+
checksum: d19351b858bd758ad8a860e9333c9b78c1ec4a564b867f592046a60cf8421580d8aefcb3dfc3c67d59c5f8cf3dee9a3074ac07204e37ec54012fd912246d0dbd
5570+
languageName: node
5571+
linkType: hard
5572+
5573+
"@tanstack/react-query@npm:^5.100.10":
5574+
version: 5.100.10
5575+
resolution: "@tanstack/react-query@npm:5.100.10"
5576+
dependencies:
5577+
"@tanstack/query-core": 5.100.10
5578+
peerDependencies:
5579+
react: ^18 || ^19
5580+
checksum: 90ceb6cafa573a081bcaf03e727ab99e68c71464dc65cede626c3c10c848d136f33ffb6523a04c477448d46d320b202b5d93fbb6f1cb4bef27fd3af3ff43cbee
5581+
languageName: node
5582+
linkType: hard
5583+
55665584
"@testing-library/react-hooks@npm:^8.0.1":
55675585
version: 8.0.1
55685586
resolution: "@testing-library/react-hooks@npm:8.0.1"
@@ -16354,6 +16372,7 @@ __metadata:
1635416372
"@react-native/typescript-config": 0.79.2
1635516373
"@react-navigation/native": ^7.1.9
1635616374
"@react-navigation/stack": ^7.3.2
16375+
"@tanstack/react-query": ^5.100.10
1635716376
"@types/deep-equal": ^1.0.4
1635816377
"@types/react": ^19.0.0
1635916378
babel-plugin-react-compiler: ^1.0.0

0 commit comments

Comments
 (0)