Skip to content

Commit 164180e

Browse files
committed
fix!: useRiveFile error is now Error, riveFile undefined while loading
Align useRiveFile with useViewModelInstance semantics: riveFile is undefined while loading (was null), error is Error object (was string). isLoading kept for convenience. Memoize error in useViewModelInstance, accept undefined source to avoid ?? null at call sites.
1 parent f71f8b4 commit 164180e

17 files changed

+57
-42
lines changed

example/src/demos/DataBindingArtboardsExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function DataBindingArtboardsExample() {
6262
return (
6363
<View style={styles.container}>
6464
<Text style={styles.errorText}>
65-
{error || 'Failed to load Rive files'}
65+
{error?.message || 'Failed to load Rive files'}
6666
</Text>
6767
</View>
6868
);

example/src/exercisers/FontFallbackExample.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function MountedView({ text }: { text: string }) {
258258
// https://rive.app/marketplace/26480-49641-simple-test-text-property/
259259
require('../../assets/rive/font_fallback.riv')
260260
);
261-
const { instance } = useViewModelInstance(riveFile ?? null);
261+
const { instance } = useViewModelInstance(riveFile);
262262

263263
const { setValue: setRiveText, error: textError } = useRiveString(
264264
TEXT_PROPERTY,
@@ -285,7 +285,9 @@ function MountedView({ text }: { text: string }) {
285285
if (error || !riveFile) {
286286
return (
287287
<View style={styles.riveContainer}>
288-
<Text style={styles.errorText}>{error || 'Failed to load file'}</Text>
288+
<Text style={styles.errorText}>
289+
{error?.message || 'Failed to load file'}
290+
</Text>
289291
</View>
290292
);
291293
}

example/src/exercisers/MenuListExample.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export default function MenuListExample() {
3232
) : riveFile ? (
3333
<MenuList file={riveFile} />
3434
) : (
35-
<Text style={styles.errorText}>{error || 'Unexpected error'}</Text>
35+
<Text style={styles.errorText}>
36+
{error?.message || 'Unexpected error'}
37+
</Text>
3638
)}
3739
</View>
3840
);

example/src/exercisers/NestedViewModelExample.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export default function NestedViewModelExample() {
3131
) : riveFile ? (
3232
<WithViewModelSetup file={riveFile} />
3333
) : (
34-
<Text style={styles.errorText}>{error || 'Unexpected error'}</Text>
34+
<Text style={styles.errorText}>
35+
{error?.message || 'Unexpected error'}
36+
</Text>
3537
)}
3638
</View>
3739
);

example/src/exercisers/OutOfBandAssets.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export default function OutOfBandAssetsExample() {
4949

5050
if (isLoading) {
5151
return <ActivityIndicator />;
52-
} else if (error != null) {
52+
} else if (error) {
5353
return (
5454
<View style={styles.safeAreaViewContainer}>
55-
<Text>Error loading Rive file</Text>
55+
<Text>Error loading Rive file: {error.message}</Text>
5656
</View>
5757
);
5858
}

example/src/exercisers/OutOfBandAssetsWithSuspense.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ function RiveContent({ imageUrl }: { imageUrl: ImageURLS }) {
102102

103103
if (isLoading) {
104104
return <ActivityIndicator />;
105-
} else if (error != null) {
105+
} else if (error) {
106106
return (
107107
<View style={styles.safeAreaViewContainer}>
108-
<Text>Error loading Rive file: {error}</Text>
108+
<Text>Error loading Rive file: {error.message}</Text>
109109
</View>
110110
);
111111
}

example/src/exercisers/ResponsiveLayouts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function ResponsiveLayoutsExample() {
4646
{isLoading ? (
4747
<ActivityIndicator size="large" color="#0000ff" />
4848
) : error ? (
49-
<Text style={styles.errorText}>{error}</Text>
49+
<Text style={styles.errorText}>{error.message}</Text>
5050
) : riveFile ? (
5151
<RiveView
5252
hybridRef={{ f: (ref) => (riveRef.current = ref) }}

example/src/exercisers/RiveDataBindingExample.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export default function WithRiveFile() {
2727
) : riveFile ? (
2828
<WithViewModelSetup file={riveFile} />
2929
) : (
30-
<Text style={styles.errorText}>{error || 'Unexpected error'}</Text>
30+
<Text style={styles.errorText}>
31+
{error?.message || 'Unexpected error'}
32+
</Text>
3133
)}
3234
</View>
3335
</View>

example/src/exercisers/RiveDataBindingExampleExpApi.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export default function WithRiveFile() {
2626
) : riveFile ? (
2727
<WithViewModelSetup file={riveFile} />
2828
) : (
29-
<Text style={styles.errorText}>{error || 'Unexpected error'}</Text>
29+
<Text style={styles.errorText}>
30+
{error?.message || 'Unexpected error'}
31+
</Text>
3032
)}
3133
</View>
3234
</View>

example/src/exercisers/RiveEventsExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function EventsExample() {
5050
{isLoading ? (
5151
<ActivityIndicator size="large" color="#0000ff" />
5252
) : error ? (
53-
<Text style={styles.errorText}>{error}</Text>
53+
<Text style={styles.errorText}>{error.message}</Text>
5454
) : riveFile ? (
5555
<RiveView
5656
style={styles.rive}

0 commit comments

Comments
 (0)