Skip to content
Closed
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
32 changes: 22 additions & 10 deletions example/__tests__/reconfigure.harness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Fit,
type RiveFile,
type RiveViewRef,
type ViewModelNumberProperty,
} from '@rive-app/react-native';

const BOUNCING_BALL = require('../assets/rive/bouncing_ball.riv');
Expand Down Expand Up @@ -74,11 +75,17 @@ describe('RiveView reconfigure (file switch)', () => {
await render(<Wrapper />);
await waitFor(() => expect(context.ref).not.toBeNull(), { timeout: 5000 });

// Confirm bouncing_ball is animating via its ypos ViewModel property
const vmi1 = context.ref!.getViewModelInstance();
expect(vmi1).not.toBeNull();
const ypos1 = vmi1!.numberProperty('ypos');
expect(ypos1).toBeDefined();
// The ViewModel instance and its properties resolve asynchronously a short
// time after the view ref is assigned, so poll until the property is
// available rather than reading it the instant the ref exists.
let ypos1: ViewModelNumberProperty | undefined;
await waitFor(
() => {
ypos1 = context.ref!.getViewModelInstance()?.numberProperty('ypos');
expect(ypos1).toBeDefined();
},
{ timeout: 5000 }
);
const valueBefore = ypos1!.value;
await delay(500);
expect(ypos1!.value).not.toBe(valueBefore);
Expand All @@ -93,11 +100,16 @@ describe('RiveView reconfigure (file switch)', () => {
await delay(600);
expect(context.error).toBeNull();

// Animation should still be running on the reconfigured view
const vmi2 = context.ref!.getViewModelInstance();
expect(vmi2).not.toBeNull();
const ypos2 = vmi2!.numberProperty('ypos');
expect(ypos2).toBeDefined();
// Animation should still be running on the reconfigured view. The
// reconfigured instance also resolves asynchronously, so poll for it too.
let ypos2: ViewModelNumberProperty | undefined;
await waitFor(
() => {
ypos2 = context.ref!.getViewModelInstance()?.numberProperty('ypos');
expect(ypos2).toBeDefined();
},
{ timeout: 5000 }
);
const valueAfterSwitch = ypos2!.value;
await delay(500);
expect(ypos2!.value).not.toBe(valueAfterSwitch);
Expand Down
4 changes: 2 additions & 2 deletions example/src/demos/DataBindingArtboardsExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Fit,
RiveView,
useRiveFile,
useViewModelInstance,
useViewModelInstanceAsync,
type RiveFile,
type BindableArtboard,
} from '@rive-app/react-native';
Expand Down Expand Up @@ -78,7 +78,7 @@ function ArtboardSwapper({
mainFile: RiveFile;
assetsFile: RiveFile;
}) {
const { instance, error } = useViewModelInstance(mainFile);
const { instance, error } = useViewModelInstanceAsync(mainFile);
const [currentArtboard, setCurrentArtboard] = useState<string>('Dragon');
const initializedRef = useRef(false);

Expand Down
4 changes: 2 additions & 2 deletions example/src/demos/QuickStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useRiveFile,
useRiveNumber,
useRiveTrigger,
useViewModelInstance,
useViewModelInstanceAsync,
Fit,
} from '@rive-app/react-native';
import type { Metadata } from '../shared/metadata';
Expand All @@ -23,7 +23,7 @@ export default function QuickStart() {
require('../../assets/rive/quick_start.riv')
);
const { riveViewRef, setHybridRef } = useRive();
const { instance: viewModelInstance } = useViewModelInstance(riveFile, {
const { instance: viewModelInstance } = useViewModelInstanceAsync(riveFile, {
onInit: (vmi) => vmi.numberProperty('health')!.set(9),
});

Expand Down
4 changes: 2 additions & 2 deletions example/src/exercisers/FontFallbackExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useRive,
useRiveFile,
useRiveString,
useViewModelInstance,
useViewModelInstanceAsync,
type FontSource,
type FallbackFont,
} from '@rive-app/react-native';
Expand Down Expand Up @@ -258,7 +258,7 @@ function MountedView({ text }: { text: string }) {
// https://rive.app/marketplace/26480-49641-simple-test-text-property/
require('../../assets/rive/font_fallback.riv')
);
const { instance } = useViewModelInstance(riveFile);
const { instance } = useViewModelInstanceAsync(riveFile);

const { setValue: setRiveText, error: textError } = useRiveString(
TEXT_PROPERTY,
Expand Down
4 changes: 2 additions & 2 deletions example/src/exercisers/MenuListExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
type RiveFile,
useRiveFile,
useRiveList,
useViewModelInstance,
useViewModelInstanceAsync,
} from '@rive-app/react-native';
import { type Metadata } from '../shared/metadata';

Expand All @@ -41,7 +41,7 @@ export default function MenuListExample() {
}

function MenuList({ file }: { file: RiveFile }) {
const { instance, error } = useViewModelInstance(file);
const { instance, error } = useViewModelInstanceAsync(file);

if (error) {
console.error(error.message);
Expand Down
4 changes: 2 additions & 2 deletions example/src/exercisers/NestedViewModelExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RiveView,
useRiveFile,
useRiveString,
useViewModelInstance,
useViewModelInstanceAsync,
type ViewModelInstance,
type RiveFile,
type RiveViewRef,
Expand Down Expand Up @@ -41,7 +41,7 @@ export default function NestedViewModelExample() {
}

function WithViewModelSetup({ file }: { file: RiveFile }) {
const { instance, error } = useViewModelInstance(file);
const { instance, error } = useViewModelInstanceAsync(file);

if (error) {
console.error(error.message);
Expand Down
4 changes: 2 additions & 2 deletions example/src/exercisers/RiveDataBindingExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Fit,
RiveView,
useRiveNumber,
useViewModelInstance,
useViewModelInstanceAsync,
type ViewModelInstance,
type RiveFile,
useRiveString,
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function WithRiveFile() {
}

function WithViewModelSetup({ file }: { file: RiveFile }) {
const { instance, error } = useViewModelInstance(file);
const { instance, error } = useViewModelInstanceAsync(file);

if (error) {
console.error(error.message);
Expand Down
4 changes: 2 additions & 2 deletions example/src/reproducers/Issue297ThreadRace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Fit,
RiveView,
useRiveFile,
useViewModelInstance,
useViewModelInstanceAsync,
type ViewModelInstance,
type RiveFile,
} from '@rive-app/react-native';
Expand Down Expand Up @@ -130,7 +130,7 @@ function StressRunner({
}

function WithViewModelSetup({ file }: { file: RiveFile }) {
const { instance, error } = useViewModelInstance(file);
const { instance, error } = useViewModelInstanceAsync(file);

if (error) {
return <Text style={styles.errorText}>{error.message}</Text>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"homepage": "https://github.com/rive-app/rive-nitro-react-native#readme",
"runtimeVersions": {
"ios": "6.20.4",
"android": "11.4.1"
"android": "11.6.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
Expand Down
Loading
Loading