Skip to content

Commit 7d9c179

Browse files
committed
fix: handle useViewModelInstance error in examples, fix harness test assertion
1 parent 155776e commit 7d9c179

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

example/__tests__/hooks.harness.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ type UseRiveNumberContext = {
2626
value: number | undefined;
2727
error: Error | null;
2828
setValue: ((v: number) => void) | null;
29+
renderValues: (number | undefined)[];
2930
};
3031

3132
function createUseRiveNumberContext(): UseRiveNumberContext {
32-
return { value: undefined, error: null, setValue: null };
33+
return { value: undefined, error: null, setValue: null, renderValues: [] };
3334
}
3435

3536
type UseViewModelInstanceContext = {
@@ -50,6 +51,8 @@ function UseRiveNumberTestComponent({
5051
}) {
5152
const { value, setValue, error } = useRiveNumber('health', instance);
5253

54+
context.renderValues.push(value);
55+
5356
useEffect(() => {
5457
context.value = value;
5558
context.error = error;
@@ -105,13 +108,13 @@ describe('useRiveNumber Hook', () => {
105108

106109
const context = createUseRiveNumberContext();
107110

108-
// Value must start undefined — not synchronously read from property.value
109-
expect(context.value).toBeUndefined();
110-
111111
await render(
112112
<UseRiveNumberTestComponent instance={instance} context={context} />
113113
);
114114

115+
// First render must produce undefined — not a synchronous read from property.value
116+
expect(context.renderValues[0]).toBeUndefined();
117+
115118
// After listener fires, value should be a number
116119
await waitFor(
117120
() => {

example/src/demos/DataBindingArtboardsExample.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ function ArtboardSwapper({
7878
mainFile: RiveFile;
7979
assetsFile: RiveFile;
8080
}) {
81-
const { instance } = useViewModelInstance(mainFile);
81+
const { instance, error } = useViewModelInstance(mainFile);
82+
83+
if (error) {
84+
console.error(error.message);
85+
}
8286
const [currentArtboard, setCurrentArtboard] = useState<string>('Dragon');
8387
const initializedRef = useRef(false);
8488

example/src/exercisers/MenuListExample.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ export default function MenuListExample() {
4141
function MenuList({ file }: { file: RiveFile }) {
4242
const { instance } = useViewModelInstance(file, { required: true });
4343

44-
if (!instance) {
45-
return <ActivityIndicator size="large" color="#007AFF" />;
46-
}
47-
4844
return <MenuListContent file={file} instance={instance} />;
4945
}
5046

example/src/exercisers/NestedViewModelExample.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export default function NestedViewModelExample() {
3838
}
3939

4040
function WithViewModelSetup({ file }: { file: RiveFile }) {
41-
const { instance } = useViewModelInstance(file);
41+
const { instance, error } = useViewModelInstance(file);
42+
43+
if (error) {
44+
console.error(error.message);
45+
return null;
46+
}
4247

4348
if (!instance) {
4449
return <ActivityIndicator size="large" color="#0000ff" />;

example/src/exercisers/RiveDataBindingExample.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ export default function WithRiveFile() {
3535
}
3636

3737
function WithViewModelSetup({ file }: { file: RiveFile }) {
38-
const { instance } = useViewModelInstance(file);
38+
const { instance, error } = useViewModelInstance(file);
39+
40+
if (error) {
41+
console.error(error.message);
42+
return null;
43+
}
3944

4045
if (!instance) {
4146
return <ActivityIndicator size="large" color="#0000ff" />;

0 commit comments

Comments
 (0)