Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/src/main/java/com/rive/RiveReactNativeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
if (reload) {
val hasDataBinding = when (config.bindData) {
is BindData.None -> false
is BindData.Auto -> config.riveFile.viewModelCount > 0
is BindData.Auto -> false
is BindData.Instance, is BindData.ByName -> true
}
riveAnimationView?.setRiveFile(
Expand Down
79 changes: 79 additions & 0 deletions example/__tests__/autoplay.harness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import type { ViewModelInstance } from '@rive-app/react-native';
// Source: https://rive.app/community/files/25997-48571-demo-for-tracking-rive-property-in-react-native/
const BOUNCING_BALL = require('../assets/rive/bouncing_ball.riv');

// Simple animation with ViewModels defined but no default ViewModel assigned to the artboard
// Source: https://rive.app/community/files/27026-50856-no-default-vm-for-artboard/
const NO_DEFAULT_VM = require('../assets/rive/nodefaultbouncing.riv');

function expectDefined<T>(value: T): asserts value is NonNullable<T> {
expect(value).toBeDefined();
}
Expand Down Expand Up @@ -264,3 +268,78 @@ describe('autoPlay prop (issue #138)', () => {
cleanup();
});
});

describe('Auto dataBind with no default ViewModel (issue #189)', () => {
it('auto-binds default ViewModel when one exists', async () => {
const file = await RiveFileFactory.fromSource(BOUNCING_BALL, undefined);

const context: TestContext = { ref: null, error: null };
await render(
<View style={{ width: 200, height: 200 }}>
<RiveView
hybridRef={{
f: (ref: RiveViewRef | null) => {
context.ref = ref;
},
}}
style={{ flex: 1 }}
file={file}
autoPlay={true}
fit={Fit.Contain}
onError={(e) => {
context.error = e.message;
}}
/>
</View>
);

await waitFor(
() => {
expect(context.ref).not.toBeNull();
},
{ timeout: 5000 }
);

expect(context.error).toBeNull();

const vmi = context.ref!.getViewModelInstance();
expect(vmi).not.toBeNull();
expect(vmi!.numberProperty('ypos')).toBeDefined();

cleanup();
});

it('plays without error when file has ViewModels but no artboard default', async () => {
const file = await RiveFileFactory.fromSource(NO_DEFAULT_VM, undefined);

const context: TestContext = { ref: null, error: null };
await render(
<View style={{ width: 200, height: 200 }}>
<RiveView
hybridRef={{
f: (ref: RiveViewRef | null) => {
context.ref = ref;
},
}}
style={{ flex: 1 }}
file={file}
autoPlay={true}
fit={Fit.Contain}
onError={(e) => {
context.error = e.message;
}}
/>
</View>
);

await waitFor(
() => {
expect(context.ref).not.toBeNull();
},
{ timeout: 5000 }
);

expect(context.error).toBeNull();
cleanup();
});
});
Binary file added example/assets/rive/nodefaultbouncing.riv
Binary file not shown.
Loading