Skip to content

Commit ebace9f

Browse files
committed
docs(react-native): update useViewModelInstance API for viewModelName and instanceName params
1 parent f52a80e commit ebace9f

2 files changed

Lines changed: 25 additions & 31 deletions

File tree

runtimes/data-binding.mdx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -598,33 +598,30 @@ Once we have a reference to a view model, it can be used to create an instance.
598598

599599
const { riveFile } = useRiveFile(require('./my_file.riv'));
600600

601-
// Get default instance from RiveFile (recommended)
601+
// From RiveFile — default artboard's ViewModel, default instance
602602
const instance = useViewModelInstance(riveFile);
603603

604-
// Get instance by name from a ViewModel
604+
// Specify artboard or ViewModel name (mutually exclusive)
605+
const instance = useViewModelInstance(riveFile, { artboardName: 'MainArtboard' });
606+
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings' });
607+
608+
// instanceName can be combined with any of the above to pick a specific instance
609+
const instance = useViewModelInstance(riveFile, { instanceName: 'PersonInstance' });
610+
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings', instanceName: 'UserSettings' });
611+
612+
// From a ViewModel object
605613
const viewModel = riveFile?.viewModelByName('My View Model');
606614
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
607-
608-
// Create a new blank instance
609615
const newInstance = useViewModelInstance(viewModel, { useNew: true });
610616

611-
// With required: true (throws if null, use with Error Boundary)
617+
// Options: required throws if null; onInit sets values before render
612618
const instance = useViewModelInstance(riveFile, { required: true });
613-
614-
// With onInit to set initial values synchronously
615619
const instance = useViewModelInstance(riveFile, {
616-
onInit: (vmi) => {
617-
vmi.numberProperty('count')?.set(10);
618-
vmi.stringProperty('name')?.set('Initial Name');
619-
}
620+
onInit: (vmi) => vmi.numberProperty('health')!.value = 100,
620621
});
621622

622623
return (
623-
<RiveView
624-
file={riveFile}
625-
dataBind={instance}
626-
autoPlay={true}
627-
/>
624+
<RiveView file={riveFile} dataBind={instance} />
628625
);
629626
```
630627

runtimes/react-native/react-native.mdx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,25 @@ This guide documents how to get started using the Rive React Native runtime. The
376376
Hook to create a view model instance from a `RiveFile`, `ViewModel`, or `RiveViewRef`:
377377

378378
```ts
379-
// Get default instance from RiveFile (recommended)
379+
// From RiveFile — default artboard's ViewModel, default instance
380380
const instance = useViewModelInstance(riveFile);
381381

382-
// or
383-
// Get named instance from a ViewModel
384-
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
382+
// From RiveFile — specify artboard or ViewModel name (mutually exclusive)
383+
const instance = useViewModelInstance(riveFile, { artboardName: 'MainArtboard' });
384+
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings' });
385385

386-
// or
387-
// Create a new blank instance from a ViewModel
386+
// instanceName can be combined with any of the above to pick a specific instance
387+
const instance = useViewModelInstance(riveFile, { instanceName: 'PersonInstance' });
388+
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings', instanceName: 'UserSettings' });
389+
390+
// From a ViewModel object
391+
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
388392
const newInstance = useViewModelInstance(viewModel, { useNew: true });
389393

390-
// or
391-
// With required: true (throws if null, use with Error Boundary)
394+
// Options: required throws if null; onInit sets values before render
392395
const instance = useViewModelInstance(riveFile, { required: true });
393-
394-
// or
395-
// With onInit to set initial values synchronously
396396
const instance = useViewModelInstance(riveFile, {
397-
onInit: (vmi) => {
398-
vmi.numberProperty('count')?.set(10);
399-
vmi.stringProperty('name')?.set('Initial Name');
400-
}
397+
onInit: (vmi) => vmi.numberProperty('health')!.value = 100,
401398
});
402399
```
403400

0 commit comments

Comments
 (0)