Skip to content

Commit 3acce86

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

2 files changed

Lines changed: 56 additions & 4 deletions

File tree

runtimes/data-binding.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,27 @@ Once we have a reference to a view model, it can be used to create an instance.
601601
// Get default instance from RiveFile (recommended)
602602
const instance = useViewModelInstance(riveFile);
603603

604+
// Get a specific instance by name from the default artboard's ViewModel
605+
const instance = useViewModelInstance(riveFile, { instanceName: 'PersonInstance' });
606+
607+
// Get the ViewModel assigned to a specific artboard
608+
const instance = useViewModelInstance(riveFile, { artboardName: 'MainArtboard' });
609+
610+
// Get a specific instance from a specific artboard
611+
const instance = useViewModelInstance(riveFile, {
612+
artboardName: 'MainArtboard',
613+
instanceName: 'SpecificInstance',
614+
});
615+
616+
// Get a ViewModel by name (file-wide lookup)
617+
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings' });
618+
619+
// Get a specific instance from a named ViewModel
620+
const instance = useViewModelInstance(riveFile, {
621+
viewModelName: 'Settings',
622+
instanceName: 'UserSettings',
623+
});
624+
604625
// Get instance by name from a ViewModel
605626
const viewModel = riveFile?.viewModelByName('My View Model');
606627
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
@@ -628,6 +649,13 @@ Once we have a reference to a view model, it can be used to create an instance.
628649
);
629650
```
630651

652+
When using a `RiveFile` source, `artboardName` and `viewModelName` are mutually exclusive:
653+
- No params: uses the default artboard's ViewModel and creates the default instance
654+
- `artboardName`: gets the ViewModel assigned to that artboard
655+
- `viewModelName`: looks up a ViewModel by name across the entire file
656+
657+
`instanceName` can be combined with any of the above. If provided, it creates a specific named instance via `createInstanceByName()`. Otherwise, the default instance is created.
658+
631659
You can also get the auto-bound instance from a `RiveViewRef`:
632660

633661
```tsx

runtimes/react-native/react-native.mdx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,36 @@ This guide documents how to get started using the Rive React Native runtime. The
379379
// Get default instance from RiveFile (recommended)
380380
const instance = useViewModelInstance(riveFile);
381381

382-
// or
382+
// Get a specific instance by name from the default artboard's ViewModel
383+
const instance = useViewModelInstance(riveFile, { instanceName: 'PersonInstance' });
384+
385+
// Get the ViewModel assigned to a specific artboard
386+
const instance = useViewModelInstance(riveFile, { artboardName: 'MainArtboard' });
387+
388+
// Get a specific instance from a specific artboard
389+
const instance = useViewModelInstance(riveFile, {
390+
artboardName: 'MainArtboard',
391+
instanceName: 'SpecificInstance',
392+
});
393+
394+
// Get a ViewModel by name (file-wide lookup)
395+
const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings' });
396+
397+
// Get a specific instance from a named ViewModel
398+
const instance = useViewModelInstance(riveFile, {
399+
viewModelName: 'Settings',
400+
instanceName: 'UserSettings',
401+
});
402+
383403
// Get named instance from a ViewModel
384404
const namedInstance = useViewModelInstance(viewModel, { name: 'My Instance' });
385405

386-
// or
387406
// Create a new blank instance from a ViewModel
388407
const newInstance = useViewModelInstance(viewModel, { useNew: true });
389408

390-
// or
391409
// With required: true (throws if null, use with Error Boundary)
392410
const instance = useViewModelInstance(riveFile, { required: true });
393411

394-
// or
395412
// With onInit to set initial values synchronously
396413
const instance = useViewModelInstance(riveFile, {
397414
onInit: (vmi) => {
@@ -401,6 +418,13 @@ This guide documents how to get started using the Rive React Native runtime. The
401418
});
402419
```
403420

421+
When using a `RiveFile` source, `artboardName` and `viewModelName` are mutually exclusive:
422+
- No params: uses the default artboard's ViewModel and creates the default instance
423+
- `artboardName`: gets the ViewModel assigned to that artboard
424+
- `viewModelName`: looks up a ViewModel by name across the entire file
425+
426+
`instanceName` can be combined with any of the above. If provided, it creates a specific named instance via `createInstanceByName()`. Otherwise, the default instance is created.
427+
404428
Pass the `dataBind` prop in `RiveView`.
405429
```ts
406430
return (

0 commit comments

Comments
 (0)