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
5 changes: 5 additions & 0 deletions .changeset/reanimated-pooled-controller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plextv/react-lightning-plugin-reanimated': patch
---

don't stop a finished, pooled animation controller when a composed animation is cancelled
8 changes: 8 additions & 0 deletions .changeset/renderer-3-7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@plextv/react-lightning': patch
'@plextv/react-native-lightning': patch
'@plextv/react-lightning-plugin-reanimated': patch
'@plextv/react-lightning-plugin-css-transform': patch
---

bump @lightningjs/renderer to 3.7.0
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { AnimationSettings } from '@lightningjs/renderer';
import { describe, expect, it } from 'vitest';

import type { LightningElement } from '@plextv/react-lightning';

import { leafProgram, repeatProgram, sequenceProgram } from './animationProgram';
import { runAnimationProgram } from './runAnimationProgram';

const settings = (
over: Partial<AnimationSettings> = {},
): AnimationSettings => ({
const settings = (over: Partial<AnimationSettings> = {}): AnimationSettings => ({
duration: 10,
easing: 'linear',
delay: 0,
Expand Down Expand Up @@ -96,6 +96,30 @@ describe('runAnimationProgram', () => {
expect(view.applied.length).toBeLessThanOrEqual(1);
});

it('cancel after the program finished does not stop the pooled controller', async () => {
const view = makeView();
let stops = 0;
view.animateStyle = function (key: PropertyKey, value: unknown) {
this.applied.push({ key, value });
return {
waitUntilStopped: () => Promise.resolve(),
stop() {
stops++;
},
};
};

const cancel = runAnimationProgram(
view as unknown as LightningElement,
'x',
leafProgram({ toValue: 1, lngAnimation: settings() }),
);
await flush();
cancel();

expect(stops).toBe(0);
});

it('repeats a finite positive count that many times', async () => {
const view = makeView();

Expand Down
18 changes: 10 additions & 8 deletions packages/plugin-reanimated/src/animation/runAnimationProgram.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { IAnimationController } from '@lightningjs/renderer';
import type {
LightningElement,
LightningElementStyle,
} from '@plextv/react-lightning';

import type { LightningElement, LightningElementStyle } from '@plextv/react-lightning';

import type { AnimationProgram, ProgramLeaf } from './animationProgram';

export type CancelAnimation = () => void;
Expand Down Expand Up @@ -30,16 +29,19 @@ export function runAnimationProgram(
// Call as a method: extracting animateStyle drops `this`, so it throws
// and the catch below silently freezes the whole composed animation.
const animatableView = view as unknown as {
animateStyle: (
key: keyof LightningElementStyle,
value: unknown,
) => IAnimationController;
animateStyle: (key: keyof LightningElementStyle, value: unknown) => IAnimationController;
};
const controller = animatableView.animateStyle(prop, leaf.toValue);

current = controller;

await controller.waitUntilStopped();

// The renderer pools controllers: once stopped this one may already drive
// another animation, so cancel must not stop it.
if (current === controller) {
current = undefined;
}
} catch {
// node was destroyed or recycled mid-flight; stop quietly
cancelled = true;
Expand Down
96 changes: 0 additions & 96 deletions patches/@lightningjs__renderer@3.1.1.patch

This file was deleted.

Loading
Loading