Skip to content

Commit

Permalink
fix:snapshot为上一帧执行完动画的shape
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed May 23, 2024
1 parent 99b9eea commit d979e6a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/f-engine/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Children from './children';
import { IContext } from './types';
import { VNode } from './canvas/vnode';
import { isEqual } from '@antv/util';
import applyStyle from './canvas/render/applyStyle';

// 播放状态
type playState = 'play' | 'pause' | 'finish';
Expand Down Expand Up @@ -38,10 +39,16 @@ function cloneNode(vnode) {
if (!child) {
return;
}
const { shape, children } = child;
const { shape, children, animator } = child;
const { end = {} } = animator;

// 拿到上一帧的snapshot
const snapshot = shape.cloneNode();
applyStyle(snapshot, end);

return {
...child,
shape: shape.cloneNode(),
shape: snapshot,
children: cloneNode(children),
};
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packages/f-engine/test/timeline/keyFrames.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,44 @@ describe('player', () => {
expect(context).toMatchImageSnapshot();
});

it('keyFrames-连续变化', async () => {
const context = createContext('连续变化');
const { props } = (
<Canvas context={context}>
<Player
state="play"
keyFrames={[
// 变宽
{
view: {
to: {
width: '10px',
},
},
},
{
view: {
to: {
visible: true,
width: '80px',
},
duration: 500,
},
},
{},
]}
>
<View key={'view'} />
</Player>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();
await delay(2000);
expect(context).toMatchImageSnapshot();
});

it.skip('leave 动画', async () => {
const context = createContext('动画 finish');
const ref = { current: null };
Expand Down

0 comments on commit d979e6a

Please sign in to comment.