Skip to content

Commit 5ca2170

Browse files
authored
fix(react-native): replace deprecated sync methods with async equivalents (#552)
Replace deprecated sync API methods with their async equivalents in React Native "New Runtime" code examples in the data binding docs.
1 parent 69c6599 commit 5ca2170

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

runtimes/react-native/data-binding.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ import { Demos } from "/snippets/demos.jsx";
3636
const { riveFile } = useRiveFile(require('./my_file.riv'));
3737

3838
// Get reference by name
39-
const namedVM = riveFile?.viewModelByName('My View Model');
39+
const namedVM = await riveFile?.viewModelByNameAsync('My View Model');
4040

41-
// Get reference by index
42-
const indexVM = riveFile?.viewModelByIndex(0);
41+
// Get all view model names
42+
const vmNames = await riveFile?.getViewModelNamesAsync(); // ['My View Model', ...]
4343

4444
// Get reference to the default artboard view model
45-
const defaultVM = riveFile?.defaultArtboardViewModel();
45+
const defaultVM = await riveFile?.defaultArtboardViewModelAsync();
4646
```
4747
</Tab>
4848
<Tab title="Legacy Runtime">
@@ -75,17 +75,17 @@ import { Demos } from "/snippets/demos.jsx";
7575
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings', instanceName: 'UserSettings' });
7676

7777
// From a ViewModel object
78-
const viewModel = riveFile?.viewModelByName('My View Model');
78+
const viewModel = await riveFile?.viewModelByNameAsync('My View Model');
7979
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
8080
const newInstance = useViewModelInstance(viewModel, { useNew: true });
8181

8282
// With required: true (throws if null, use with Error Boundary)
8383
const instance = useViewModelInstance(riveFile, { required: true });
8484

85-
// With onInit to set initial values synchronously
85+
// With onInit to set initial values
8686
const instance = useViewModelInstance(riveFile, {
8787
onInit: (vmi) => {
88-
vmi.numberProperty('health')!.value = 100;
88+
vmi.numberProperty('health')?.set(100);
8989
},
9090
});
9191

@@ -680,10 +680,10 @@ import { Demos } from "/snippets/demos.jsx";
680680
} = useRiveList('todos', instance);
681681

682682
// Add a new todo item
683-
const handleAddItem = () => {
684-
const todoItemViewModel = riveFile?.viewModelByName('TodoItem');
683+
const handleAddItem = async () => {
684+
const todoItemViewModel = await riveFile?.viewModelByNameAsync('TodoItem');
685685
if (todoItemViewModel) {
686-
const newTodoItem = todoItemViewModel.createInstance();
686+
const newTodoItem = await todoItemViewModel.createBlankInstanceAsync();
687687
if (newTodoItem) {
688688
// Set some initial values
689689
newTodoItem.stringProperty('description')?.set('Buy groceries');
@@ -693,10 +693,10 @@ import { Demos } from "/snippets/demos.jsx";
693693
};
694694

695695
// Insert item at specific index
696-
const handleInsertItem = () => {
697-
const todoItemViewModel = riveFile?.viewModelByName('TodoItem');
696+
const handleInsertItem = async () => {
697+
const todoItemViewModel = await riveFile?.viewModelByNameAsync('TodoItem');
698698
if (todoItemViewModel) {
699-
const newTodoItem = todoItemViewModel.createInstance();
699+
const newTodoItem = await todoItemViewModel.createBlankInstanceAsync();
700700
if (newTodoItem) {
701701
addInstanceAt(newTodoItem, 0); // Insert at beginning
702702
}

0 commit comments

Comments
 (0)