Skip to content

Commit

Permalink
fix: 跳转超出总时长
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Jun 24, 2024
1 parent 33713d7 commit b35fe0e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/f-engine/src/canvas/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,28 @@ class Timeline extends EE {
const { frame, animUnits, playState } = this;
let target;

for (let i = 0; i < animUnits.length; i++) {
const cur = animUnits[i];
target = i;
if (time > cur.time) {
for (target = 0; target < animUnits.length; target++) {
const cur = animUnits[target];
if (time >= cur.time) {
time -= cur.time; // 计算剩余时间
} else {
break;
}
}

// 超出了总时长
if (target === animUnits.length && time > 0) {
this.setPlayState('finish');
return;
}

if (frame !== target) {
this.frame = target;
this.drawFrame();
this.animator.run();
this.setPlayState(playState);
}

this.animator.goTo(time);
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions packages/f-engine/test/timeline/player.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,58 @@ describe('clip animation', () => {

expect(context).toMatchImageSnapshot();
});

it('跳转超出总时长', async () => {
const context = createContext('跳转超出总时长');

//结束后重播
const { props } = (
<Canvas context={context}>
<Player
state="finish"
keyFrames={[
{
view: {
to: {
visible: true,
},
duration: 1000,
},
},
]}
>
<View key={'view'} visible={false} />
</Player>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();
await delay(100);

const { props: newProps } = (
<Canvas context={context}>
<Player
state="pause"
goTo={1200}
keyFrames={[
{
view: {
to: {
visible: true,
},
duration: 1000,
},
},
]}
>
<View key={'view'} visible={false} />
</Player>
</Canvas>
);

await canvas.update(newProps);
await delay(100);
expect(context).toMatchImageSnapshot();
});
});

0 comments on commit b35fe0e

Please sign in to comment.