@rive-app/react-native 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/margelo/nitro/rive/HybridRiveFile.kt +13 -4
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModel.kt +1 -0
- package/android/src/main/java/com/margelo/nitro/rive/HybridViewModelColorProperty.kt +1 -1
- package/ios/HybridRiveFile.swift +1 -0
- package/ios/HybridViewModel.swift +1 -0
- package/lib/module/core/RiveView.js +38 -9
- package/lib/module/core/RiveView.js.map +1 -1
- package/lib/module/hooks/useRive.js +56 -38
- package/lib/module/hooks/useRive.js.map +1 -1
- package/lib/module/hooks/useRiveBoolean.js +17 -5
- package/lib/module/hooks/useRiveBoolean.js.map +1 -1
- package/lib/module/hooks/useRiveColor.js +38 -10
- package/lib/module/hooks/useRiveColor.js.map +1 -1
- package/lib/module/hooks/useRiveEnum.js +21 -9
- package/lib/module/hooks/useRiveEnum.js.map +1 -1
- package/lib/module/hooks/useRiveList.js +170 -54
- package/lib/module/hooks/useRiveList.js.map +1 -1
- package/lib/module/hooks/useRiveNumber.js +17 -5
- package/lib/module/hooks/useRiveNumber.js.map +1 -1
- package/lib/module/hooks/useRiveProperty.js +2 -2
- package/lib/module/hooks/useRiveProperty.js.map +1 -1
- package/lib/module/hooks/useRiveString.js +17 -5
- package/lib/module/hooks/useRiveString.js.map +1 -1
- package/lib/module/hooks/useRiveTrigger.js +50 -15
- package/lib/module/hooks/useRiveTrigger.js.map +1 -1
- package/lib/module/hooks/useViewModelInstance.js +97 -12
- package/lib/module/hooks/useViewModelInstance.js.map +1 -1
- package/lib/typescript/src/hooks/useRiveEnum.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useViewModelInstance.d.ts +82 -13
- package/lib/typescript/src/hooks/useViewModelInstance.d.ts.map +1 -1
- package/lib/typescript/src/specs/RiveView.nitro.d.ts +1 -1
- package/lib/typescript/src/specs/RiveView.nitro.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/hooks/useRiveEnum.ts +5 -4
- package/src/hooks/useViewModelInstance.ts +198 -35
- package/src/specs/RiveView.nitro.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useEffect","useRef","callDispose","
|
|
1
|
+
{"version":3,"names":["useMemo","useEffect","useRef","callDispose","ArtboardByName","isRiveViewRef","source","isRiveFile","createInstance","instanceName","artboardName","viewModelName","useNew","instance","needsDispose","vmi","getViewModelInstance","viewModel","viewModelByName","error","defaultArtboardViewModel","undefined","createInstanceByName","createDefaultInstance","useViewModelInstance","params","fileInstanceName","viewModelInstanceName","name","required","onInit","prevInstanceRef","result","created","current","Error"],"sourceRoot":"../../../src","sources":["hooks/useViewModelInstance.ts"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAIlD,SAASC,WAAW,QAAQ,wBAAqB;AACjD,SAASC,cAAc,QAAQ,wBAAqB;;AA0BpD;AACA;AACA;;AAOA;AACA;AACA;;AAUA;AACA;AACA;AACA;;AAiCA,SAASC,aAAaA,CAACC,MAA8B,EAAyB;EAC5E,OAAOA,MAAM,KAAK,IAAI,IAAI,sBAAsB,IAAIA,MAAM;AAC5D;AAEA,SAASC,UAAUA,CAACD,MAA8B,EAAsB;EACtE,OAAOA,MAAM,KAAK,IAAI,IAAI,0BAA0B,IAAIA,MAAM;AAChE;AAQA,SAASE,cAAcA,CACrBF,MAA8B,EAC9BG,YAAgC,EAChCC,YAAgC,EAChCC,aAAiC,EACjCC,MAAe,EACO;EACtB,IAAI,CAACN,MAAM,EAAE;IACX,OAAO;MAAEO,QAAQ,EAAE,IAAI;MAAEC,YAAY,EAAE;IAAM,CAAC;EAChD;EAEA,IAAIT,aAAa,CAACC,MAAM,CAAC,EAAE;IACzB,MAAMS,GAAG,GAAGT,MAAM,CAACU,oBAAoB,CAAC,CAAC;IACzC,OAAO;MAAEH,QAAQ,EAAEE,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ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRiveEnum.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useRiveEnum.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRiveEnum.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useRiveEnum.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOtD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI,GAC3C,qBAAqB,CAAC,MAAM,CAAC,CAM/B"}
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type { ViewModel, ViewModelInstance } from '../specs/ViewModel.nitro';
|
|
2
2
|
import type { RiveFile } from '../specs/RiveFile.nitro';
|
|
3
3
|
import type { RiveViewRef } from '../index';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get a specifically named instance from the ViewModel.
|
|
7
|
-
*/
|
|
8
|
-
name?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Create a new (blank) instance from the ViewModel.
|
|
11
|
-
*/
|
|
12
|
-
useNew?: boolean;
|
|
4
|
+
interface UseViewModelInstanceBaseParams {
|
|
13
5
|
/**
|
|
14
6
|
* If true, throws an error when the instance cannot be obtained.
|
|
15
7
|
* This is useful with Error Boundaries and ensures TypeScript knows
|
|
@@ -23,12 +15,60 @@ export interface UseViewModelInstanceParams {
|
|
|
23
15
|
*/
|
|
24
16
|
onInit?: (instance: ViewModelInstance) => void;
|
|
25
17
|
}
|
|
26
|
-
|
|
18
|
+
interface UseViewModelInstanceFileBaseParams extends UseViewModelInstanceBaseParams {
|
|
19
|
+
/**
|
|
20
|
+
* The ViewModel instance name (uses `createInstanceByName()`).
|
|
21
|
+
* If not provided, creates the default instance.
|
|
22
|
+
*/
|
|
23
|
+
instanceName?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Use the ViewModel assigned to the default artboard.
|
|
27
|
+
*/
|
|
28
|
+
interface UseViewModelInstanceFileDefault extends UseViewModelInstanceFileBaseParams {
|
|
29
|
+
artboardName?: never;
|
|
30
|
+
viewModelName?: never;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Use the ViewModel assigned to a specific artboard.
|
|
34
|
+
*/
|
|
35
|
+
interface UseViewModelInstanceFileByArtboard extends UseViewModelInstanceFileBaseParams {
|
|
36
|
+
/**
|
|
37
|
+
* Get the ViewModel assigned to this artboard.
|
|
38
|
+
*/
|
|
39
|
+
artboardName: string;
|
|
40
|
+
viewModelName?: never;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Use a ViewModel by name (file-wide lookup).
|
|
44
|
+
* ViewModels are defined at the file level, not per-artboard.
|
|
45
|
+
*/
|
|
46
|
+
interface UseViewModelInstanceFileByViewModelName extends UseViewModelInstanceFileBaseParams {
|
|
47
|
+
artboardName?: never;
|
|
48
|
+
/**
|
|
49
|
+
* The name of the ViewModel to use (uses `viewModelByName()`).
|
|
50
|
+
* ViewModels are defined at the file level and looked up by name across the entire file.
|
|
51
|
+
*/
|
|
52
|
+
viewModelName: string;
|
|
53
|
+
}
|
|
54
|
+
export type UseViewModelInstanceFileParams = UseViewModelInstanceFileDefault | UseViewModelInstanceFileByArtboard | UseViewModelInstanceFileByViewModelName;
|
|
55
|
+
export interface UseViewModelInstanceViewModelParams extends UseViewModelInstanceBaseParams {
|
|
56
|
+
/**
|
|
57
|
+
* The ViewModel instance name (uses `createInstanceByName()`).
|
|
58
|
+
* If not provided, creates the default instance.
|
|
59
|
+
*/
|
|
60
|
+
name?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Create a new (blank) instance from the ViewModel.
|
|
63
|
+
*/
|
|
64
|
+
useNew?: boolean;
|
|
65
|
+
}
|
|
66
|
+
export type UseViewModelInstanceRefParams = UseViewModelInstanceBaseParams;
|
|
27
67
|
/**
|
|
28
68
|
* Hook for getting a ViewModelInstance from a RiveFile, ViewModel, or RiveViewRef.
|
|
29
69
|
*
|
|
30
70
|
* @param source - The RiveFile, ViewModel, or RiveViewRef to get an instance from
|
|
31
|
-
* @param params - Configuration for which instance to retrieve
|
|
71
|
+
* @param params - Configuration for which instance to retrieve
|
|
32
72
|
* @returns The ViewModelInstance or null if not found
|
|
33
73
|
*
|
|
34
74
|
* @example
|
|
@@ -40,6 +80,27 @@ type ViewModelSource = ViewModel | RiveFile | RiveViewRef;
|
|
|
40
80
|
*
|
|
41
81
|
* @example
|
|
42
82
|
* ```tsx
|
|
83
|
+
* // From RiveFile with specific instance name
|
|
84
|
+
* const { riveFile } = useRiveFile(require('./animation.riv'));
|
|
85
|
+
* const instance = useViewModelInstance(riveFile, { instanceName: 'PersonInstance' });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* // From RiveFile with specific ViewModel name
|
|
91
|
+
* const { riveFile } = useRiveFile(require('./animation.riv'));
|
|
92
|
+
* const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings' });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* // From RiveFile with specific artboard
|
|
98
|
+
* const { riveFile } = useRiveFile(require('./animation.riv'));
|
|
99
|
+
* const instance = useViewModelInstance(riveFile, { artboardName: 'MainArtboard' });
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
43
104
|
* // From RiveViewRef (get auto-bound instance)
|
|
44
105
|
* const { riveViewRef, setHybridRef } = useRive();
|
|
45
106
|
* const instance = useViewModelInstance(riveViewRef);
|
|
@@ -78,9 +139,17 @@ type ViewModelSource = ViewModel | RiveFile | RiveViewRef;
|
|
|
78
139
|
* // Values are already set here
|
|
79
140
|
* ```
|
|
80
141
|
*/
|
|
81
|
-
export declare function useViewModelInstance(source:
|
|
142
|
+
export declare function useViewModelInstance(source: RiveFile, params: UseViewModelInstanceFileParams & {
|
|
143
|
+
required: true;
|
|
144
|
+
}): ViewModelInstance;
|
|
145
|
+
export declare function useViewModelInstance(source: RiveFile | null, params?: UseViewModelInstanceFileParams): ViewModelInstance | null;
|
|
146
|
+
export declare function useViewModelInstance(source: ViewModel, params: UseViewModelInstanceViewModelParams & {
|
|
147
|
+
required: true;
|
|
148
|
+
}): ViewModelInstance;
|
|
149
|
+
export declare function useViewModelInstance(source: ViewModel | null, params?: UseViewModelInstanceViewModelParams): ViewModelInstance | null;
|
|
150
|
+
export declare function useViewModelInstance(source: RiveViewRef, params: UseViewModelInstanceRefParams & {
|
|
82
151
|
required: true;
|
|
83
152
|
}): ViewModelInstance;
|
|
84
|
-
export declare function useViewModelInstance(source:
|
|
153
|
+
export declare function useViewModelInstance(source: RiveViewRef | null, params?: UseViewModelInstanceRefParams): ViewModelInstance | null;
|
|
85
154
|
export {};
|
|
86
155
|
//# sourceMappingURL=useViewModelInstance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useViewModelInstance.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useViewModelInstance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"useViewModelInstance.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useViewModelInstance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,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AoB,CAClC,MAAM,EAAE,QAAQ,GAAG,IAAI,EACvB,MAAM,CAAC,EAAE,8BAA8B,GACtC,iBAAiB,GAAG,IAAI,CAAC;AAG5B,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,mCAAmC,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAC/D,iBAAiB,CAAC;AACrB,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,GAAG,IAAI,EACxB,MAAM,CAAC,EAAE,mCAAmC,GAC3C,iBAAiB,GAAG,IAAI,CAAC;AAG5B,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,6BAA6B,GAAG;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GACzD,iBAAiB,CAAC;AACrB,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,GAAG,IAAI,EAC1B,MAAM,CAAC,EAAE,6BAA6B,GACrC,iBAAiB,GAAG,IAAI,CAAC"}
|
|
@@ -19,7 +19,7 @@ export interface DataBindByName {
|
|
|
19
19
|
export interface RiveViewProps extends HybridViewProps {
|
|
20
20
|
/** Name of the artboard to display from the Rive file */
|
|
21
21
|
artboardName?: string;
|
|
22
|
-
/** Name of the state
|
|
22
|
+
/** Name of the state machine to play */
|
|
23
23
|
stateMachineName?: string;
|
|
24
24
|
/** Whether to automatically start playing the state machine */
|
|
25
25
|
autoPlay?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RiveView.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/RiveView.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,EAA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AC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzD;;;;;;OAMG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE;;;;;;OAMG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3D;;;;;OAKG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD;;;;;;OAMG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClE;;;;;;OAMG;IACH,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACtD;AAED,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC,GAAG;IAC5E,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,CAAC;CAC5D,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rive-app/react-native",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Rive React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"@types/react": "^19.0.0",
|
|
85
85
|
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
86
86
|
"@typescript-eslint/parser": "^8.46.4",
|
|
87
|
+
"babel-plugin-react-compiler": "^1.0.0",
|
|
87
88
|
"commitlint": "^19.6.1",
|
|
88
89
|
"del-cli": "^5.1.0",
|
|
89
90
|
"eslint": "^9.22.0",
|
|
@@ -167,7 +168,8 @@
|
|
|
167
168
|
[
|
|
168
169
|
"module",
|
|
169
170
|
{
|
|
170
|
-
"esm": true
|
|
171
|
+
"esm": true,
|
|
172
|
+
"configFile": true
|
|
171
173
|
}
|
|
172
174
|
],
|
|
173
175
|
[
|
package/src/hooks/useRiveEnum.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
1
|
import {
|
|
3
2
|
type ViewModelEnumProperty,
|
|
4
3
|
type ViewModelInstance,
|
|
@@ -6,6 +5,10 @@ import {
|
|
|
6
5
|
import type { UseRivePropertyResult } from '../types';
|
|
7
6
|
import { useRiveProperty } from './useRiveProperty';
|
|
8
7
|
|
|
8
|
+
const ENUM_PROPERTY_OPTIONS = {
|
|
9
|
+
getProperty: (vmi: ViewModelInstance, p: string) => vmi.enumProperty(p),
|
|
10
|
+
};
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* Hook for interacting with enum ViewModel instance properties.
|
|
11
14
|
*
|
|
@@ -20,8 +23,6 @@ export function useRiveEnum(
|
|
|
20
23
|
const [value, setValue, error] = useRiveProperty<
|
|
21
24
|
ViewModelEnumProperty,
|
|
22
25
|
string
|
|
23
|
-
>(viewModelInstance, path,
|
|
24
|
-
getProperty: useCallback((vmi, p) => vmi.enumProperty(p), []),
|
|
25
|
-
});
|
|
26
|
+
>(viewModelInstance, path, ENUM_PROPERTY_OPTIONS);
|
|
26
27
|
return { value, setValue, error };
|
|
27
28
|
}
|
|
@@ -3,16 +3,9 @@ import type { ViewModel, ViewModelInstance } from '../specs/ViewModel.nitro';
|
|
|
3
3
|
import type { RiveFile } from '../specs/RiveFile.nitro';
|
|
4
4
|
import type { RiveViewRef } from '../index';
|
|
5
5
|
import { callDispose } from '../core/callDispose';
|
|
6
|
+
import { ArtboardByName } from '../specs/ArtboardBy';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get a specifically named instance from the ViewModel.
|
|
10
|
-
*/
|
|
11
|
-
name?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Create a new (blank) instance from the ViewModel.
|
|
14
|
-
*/
|
|
15
|
-
useNew?: boolean;
|
|
8
|
+
interface UseViewModelInstanceBaseParams {
|
|
16
9
|
/**
|
|
17
10
|
* If true, throws an error when the instance cannot be obtained.
|
|
18
11
|
* This is useful with Error Boundaries and ensures TypeScript knows
|
|
@@ -27,27 +20,93 @@ export interface UseViewModelInstanceParams {
|
|
|
27
20
|
onInit?: (instance: ViewModelInstance) => void;
|
|
28
21
|
}
|
|
29
22
|
|
|
23
|
+
interface UseViewModelInstanceFileBaseParams
|
|
24
|
+
extends UseViewModelInstanceBaseParams {
|
|
25
|
+
/**
|
|
26
|
+
* The ViewModel instance name (uses `createInstanceByName()`).
|
|
27
|
+
* If not provided, creates the default instance.
|
|
28
|
+
*/
|
|
29
|
+
instanceName?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Use the ViewModel assigned to the default artboard.
|
|
34
|
+
*/
|
|
35
|
+
interface UseViewModelInstanceFileDefault
|
|
36
|
+
extends UseViewModelInstanceFileBaseParams {
|
|
37
|
+
artboardName?: never;
|
|
38
|
+
viewModelName?: never;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Use the ViewModel assigned to a specific artboard.
|
|
43
|
+
*/
|
|
44
|
+
interface UseViewModelInstanceFileByArtboard
|
|
45
|
+
extends UseViewModelInstanceFileBaseParams {
|
|
46
|
+
/**
|
|
47
|
+
* Get the ViewModel assigned to this artboard.
|
|
48
|
+
*/
|
|
49
|
+
artboardName: string;
|
|
50
|
+
viewModelName?: never;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Use a ViewModel by name (file-wide lookup).
|
|
55
|
+
* ViewModels are defined at the file level, not per-artboard.
|
|
56
|
+
*/
|
|
57
|
+
interface UseViewModelInstanceFileByViewModelName
|
|
58
|
+
extends UseViewModelInstanceFileBaseParams {
|
|
59
|
+
artboardName?: never;
|
|
60
|
+
/**
|
|
61
|
+
* The name of the ViewModel to use (uses `viewModelByName()`).
|
|
62
|
+
* ViewModels are defined at the file level and looked up by name across the entire file.
|
|
63
|
+
*/
|
|
64
|
+
viewModelName: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type UseViewModelInstanceFileParams =
|
|
68
|
+
| UseViewModelInstanceFileDefault
|
|
69
|
+
| UseViewModelInstanceFileByArtboard
|
|
70
|
+
| UseViewModelInstanceFileByViewModelName;
|
|
71
|
+
|
|
72
|
+
export interface UseViewModelInstanceViewModelParams
|
|
73
|
+
extends UseViewModelInstanceBaseParams {
|
|
74
|
+
/**
|
|
75
|
+
* The ViewModel instance name (uses `createInstanceByName()`).
|
|
76
|
+
* If not provided, creates the default instance.
|
|
77
|
+
*/
|
|
78
|
+
name?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Create a new (blank) instance from the ViewModel.
|
|
81
|
+
*/
|
|
82
|
+
useNew?: boolean;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type UseViewModelInstanceRefParams = UseViewModelInstanceBaseParams;
|
|
86
|
+
|
|
30
87
|
type ViewModelSource = ViewModel | RiveFile | RiveViewRef;
|
|
31
88
|
|
|
32
89
|
function isRiveViewRef(source: ViewModelSource | null): source is RiveViewRef {
|
|
33
|
-
return
|
|
34
|
-
source !== null && source !== undefined && 'getViewModelInstance' in source
|
|
35
|
-
);
|
|
90
|
+
return source !== null && 'getViewModelInstance' in source;
|
|
36
91
|
}
|
|
37
92
|
|
|
38
93
|
function isRiveFile(source: ViewModelSource | null): source is RiveFile {
|
|
39
|
-
return
|
|
40
|
-
source !== null &&
|
|
41
|
-
source !== undefined &&
|
|
42
|
-
'defaultArtboardViewModel' in source
|
|
43
|
-
);
|
|
94
|
+
return source !== null && 'defaultArtboardViewModel' in source;
|
|
44
95
|
}
|
|
45
96
|
|
|
97
|
+
type CreateInstanceResult = {
|
|
98
|
+
instance: ViewModelInstance | null;
|
|
99
|
+
needsDispose: boolean;
|
|
100
|
+
error?: string;
|
|
101
|
+
};
|
|
102
|
+
|
|
46
103
|
function createInstance(
|
|
47
104
|
source: ViewModelSource | null,
|
|
48
|
-
|
|
105
|
+
instanceName: string | undefined,
|
|
106
|
+
artboardName: string | undefined,
|
|
107
|
+
viewModelName: string | undefined,
|
|
49
108
|
useNew: boolean
|
|
50
|
-
):
|
|
109
|
+
): CreateInstanceResult {
|
|
51
110
|
if (!source) {
|
|
52
111
|
return { instance: null, needsDispose: false };
|
|
53
112
|
}
|
|
@@ -58,15 +117,55 @@ function createInstance(
|
|
|
58
117
|
}
|
|
59
118
|
|
|
60
119
|
if (isRiveFile(source)) {
|
|
61
|
-
|
|
62
|
-
|
|
120
|
+
let viewModel: ViewModel | undefined;
|
|
121
|
+
if (viewModelName) {
|
|
122
|
+
viewModel = source.viewModelByName(viewModelName);
|
|
123
|
+
if (!viewModel) {
|
|
124
|
+
return {
|
|
125
|
+
instance: null,
|
|
126
|
+
needsDispose: false,
|
|
127
|
+
error: `ViewModel '${viewModelName}' not found`,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
viewModel = source.defaultArtboardViewModel(
|
|
132
|
+
artboardName ? ArtboardByName(artboardName) : undefined
|
|
133
|
+
);
|
|
134
|
+
if (!viewModel) {
|
|
135
|
+
if (artboardName) {
|
|
136
|
+
return {
|
|
137
|
+
instance: null,
|
|
138
|
+
needsDispose: false,
|
|
139
|
+
error: `Artboard '${artboardName}' not found or has no ViewModel`,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return { instance: null, needsDispose: false };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const vmi = instanceName
|
|
146
|
+
? viewModel.createInstanceByName(instanceName)
|
|
147
|
+
: viewModel.createDefaultInstance();
|
|
148
|
+
if (!vmi && instanceName) {
|
|
149
|
+
return {
|
|
150
|
+
instance: null,
|
|
151
|
+
needsDispose: false,
|
|
152
|
+
error: `ViewModel instance '${instanceName}' not found`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
63
155
|
return { instance: vmi ?? null, needsDispose: true };
|
|
64
156
|
}
|
|
65
157
|
|
|
66
158
|
// ViewModel source
|
|
67
159
|
let vmi: ViewModelInstance | undefined;
|
|
68
|
-
if (
|
|
69
|
-
vmi = source.createInstanceByName(
|
|
160
|
+
if (instanceName) {
|
|
161
|
+
vmi = source.createInstanceByName(instanceName);
|
|
162
|
+
if (!vmi) {
|
|
163
|
+
return {
|
|
164
|
+
instance: null,
|
|
165
|
+
needsDispose: false,
|
|
166
|
+
error: `ViewModel instance '${instanceName}' not found`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
70
169
|
} else if (useNew) {
|
|
71
170
|
vmi = source.createInstance();
|
|
72
171
|
} else {
|
|
@@ -79,7 +178,7 @@ function createInstance(
|
|
|
79
178
|
* Hook for getting a ViewModelInstance from a RiveFile, ViewModel, or RiveViewRef.
|
|
80
179
|
*
|
|
81
180
|
* @param source - The RiveFile, ViewModel, or RiveViewRef to get an instance from
|
|
82
|
-
* @param params - Configuration for which instance to retrieve
|
|
181
|
+
* @param params - Configuration for which instance to retrieve
|
|
83
182
|
* @returns The ViewModelInstance or null if not found
|
|
84
183
|
*
|
|
85
184
|
* @example
|
|
@@ -91,6 +190,27 @@ function createInstance(
|
|
|
91
190
|
*
|
|
92
191
|
* @example
|
|
93
192
|
* ```tsx
|
|
193
|
+
* // From RiveFile with specific instance name
|
|
194
|
+
* const { riveFile } = useRiveFile(require('./animation.riv'));
|
|
195
|
+
* const instance = useViewModelInstance(riveFile, { instanceName: 'PersonInstance' });
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```tsx
|
|
200
|
+
* // From RiveFile with specific ViewModel name
|
|
201
|
+
* const { riveFile } = useRiveFile(require('./animation.riv'));
|
|
202
|
+
* const instance = useViewModelInstance(riveFile, { viewModelName: 'Settings' });
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```tsx
|
|
207
|
+
* // From RiveFile with specific artboard
|
|
208
|
+
* const { riveFile } = useRiveFile(require('./animation.riv'));
|
|
209
|
+
* const instance = useViewModelInstance(riveFile, { artboardName: 'MainArtboard' });
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```tsx
|
|
94
214
|
* // From RiveViewRef (get auto-bound instance)
|
|
95
215
|
* const { riveViewRef, setHybridRef } = useRive();
|
|
96
216
|
* const instance = useViewModelInstance(riveViewRef);
|
|
@@ -129,20 +249,55 @@ function createInstance(
|
|
|
129
249
|
* // Values are already set here
|
|
130
250
|
* ```
|
|
131
251
|
*/
|
|
252
|
+
// RiveFile overloads
|
|
132
253
|
export function useViewModelInstance(
|
|
133
|
-
source:
|
|
134
|
-
params:
|
|
254
|
+
source: RiveFile,
|
|
255
|
+
params: UseViewModelInstanceFileParams & { required: true }
|
|
135
256
|
): ViewModelInstance;
|
|
136
257
|
export function useViewModelInstance(
|
|
137
|
-
source:
|
|
138
|
-
params?:
|
|
258
|
+
source: RiveFile | null,
|
|
259
|
+
params?: UseViewModelInstanceFileParams
|
|
260
|
+
): ViewModelInstance | null;
|
|
261
|
+
|
|
262
|
+
// ViewModel overloads
|
|
263
|
+
export function useViewModelInstance(
|
|
264
|
+
source: ViewModel,
|
|
265
|
+
params: UseViewModelInstanceViewModelParams & { required: true }
|
|
266
|
+
): ViewModelInstance;
|
|
267
|
+
export function useViewModelInstance(
|
|
268
|
+
source: ViewModel | null,
|
|
269
|
+
params?: UseViewModelInstanceViewModelParams
|
|
139
270
|
): ViewModelInstance | null;
|
|
271
|
+
|
|
272
|
+
// RiveViewRef overloads
|
|
273
|
+
export function useViewModelInstance(
|
|
274
|
+
source: RiveViewRef,
|
|
275
|
+
params: UseViewModelInstanceRefParams & { required: true }
|
|
276
|
+
): ViewModelInstance;
|
|
277
|
+
export function useViewModelInstance(
|
|
278
|
+
source: RiveViewRef | null,
|
|
279
|
+
params?: UseViewModelInstanceRefParams
|
|
280
|
+
): ViewModelInstance | null;
|
|
281
|
+
|
|
282
|
+
// Implementation
|
|
140
283
|
export function useViewModelInstance(
|
|
141
284
|
source: ViewModelSource | null,
|
|
142
|
-
params?:
|
|
285
|
+
params?:
|
|
286
|
+
| UseViewModelInstanceFileParams
|
|
287
|
+
| UseViewModelInstanceViewModelParams
|
|
288
|
+
| UseViewModelInstanceRefParams
|
|
143
289
|
): ViewModelInstance | null {
|
|
144
|
-
const
|
|
145
|
-
|
|
290
|
+
const fileInstanceName = (params as { instanceName?: string } | undefined)
|
|
291
|
+
?.instanceName;
|
|
292
|
+
const viewModelInstanceName = (params as { name?: string } | undefined)?.name;
|
|
293
|
+
const instanceName = fileInstanceName ?? viewModelInstanceName;
|
|
294
|
+
const artboardName = (params as UseViewModelInstanceFileParams | undefined)
|
|
295
|
+
?.artboardName;
|
|
296
|
+
const viewModelName = (params as UseViewModelInstanceFileParams | undefined)
|
|
297
|
+
?.viewModelName;
|
|
298
|
+
const useNew =
|
|
299
|
+
(params as UseViewModelInstanceViewModelParams | undefined)?.useNew ??
|
|
300
|
+
false;
|
|
146
301
|
const required = params?.required ?? false;
|
|
147
302
|
const onInit = params?.onInit;
|
|
148
303
|
|
|
@@ -152,13 +307,19 @@ export function useViewModelInstance(
|
|
|
152
307
|
} | null>(null);
|
|
153
308
|
|
|
154
309
|
const result = useMemo(() => {
|
|
155
|
-
const created = createInstance(
|
|
310
|
+
const created = createInstance(
|
|
311
|
+
source,
|
|
312
|
+
instanceName,
|
|
313
|
+
artboardName,
|
|
314
|
+
viewModelName,
|
|
315
|
+
useNew
|
|
316
|
+
);
|
|
156
317
|
if (created.instance && onInit) {
|
|
157
318
|
onInit(created.instance);
|
|
158
319
|
}
|
|
159
320
|
return created;
|
|
160
321
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- onInit excluded intentionally
|
|
161
|
-
}, [source,
|
|
322
|
+
}, [source, instanceName, artboardName, viewModelName, useNew]);
|
|
162
323
|
|
|
163
324
|
// Dispose previous instance if it changed and needed disposal
|
|
164
325
|
if (
|
|
@@ -186,8 +347,10 @@ export function useViewModelInstance(
|
|
|
186
347
|
|
|
187
348
|
if (required && result.instance === null) {
|
|
188
349
|
throw new Error(
|
|
189
|
-
|
|
190
|
-
|
|
350
|
+
result.error
|
|
351
|
+
? `useViewModelInstance: ${result.error}`
|
|
352
|
+
: 'useViewModelInstance: Failed to get ViewModelInstance. ' +
|
|
353
|
+
'Ensure the source has a valid ViewModel and instance available.'
|
|
191
354
|
);
|
|
192
355
|
}
|
|
193
356
|
|
|
@@ -25,7 +25,7 @@ export interface DataBindByName {
|
|
|
25
25
|
export interface RiveViewProps extends HybridViewProps {
|
|
26
26
|
/** Name of the artboard to display from the Rive file */
|
|
27
27
|
artboardName?: string;
|
|
28
|
-
/** Name of the state
|
|
28
|
+
/** Name of the state machine to play */
|
|
29
29
|
stateMachineName?: string;
|
|
30
30
|
/** Whether to automatically start playing the state machine */
|
|
31
31
|
autoPlay?: boolean;
|