Skip to content

Commit

Permalink
fix: animation set time 0
Browse files Browse the repository at this point in the history
  • Loading branch information
xuying.xu committed Jun 20, 2024
1 parent 69c2ba2 commit a2b1568
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
13 changes: 11 additions & 2 deletions packages/f-engine/src/canvas/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,21 @@ class Timeline extends EE {
return this.playState;
}

updateState(nextProps) {
updateState(state) {
// 播放状态不同
const { state } = nextProps;
if (state === 'finish') {
this.frame = this.endFrame;
this.drawFrame();
this.animator.run();
}

// 从finish 到 play 的话
// if (this.playState === 'finish') {
// this.frame = 0;
// this.playState = state;
// this.start();
// return;
// }
this.playState = state;
this.setPlayState(state);
}
Expand Down Expand Up @@ -135,6 +142,8 @@ class Timeline extends EE {
this.animator.run();
this.setPlayState(playState);
}
// animation设置time为0时为结束态
if (time === 0) time++;
this.animator.goTo(time);
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/f-engine/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Player extends Component<PlayerProps> {

// state 更新
if (!isEqual(state, timeline.getPlayState())) {
timeline.updateState({ state });
timeline.updateState(state);
}

if (!isEqual(nextTime, lastTime)) {
Expand All @@ -118,6 +118,11 @@ class Player extends Component<PlayerProps> {
}
}

setPlayState(state) {
const { timeline } = this;
timeline.updateState(state);
}

goTo(time) {
const { timeline } = this;
timeline.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.
76 changes: 76 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,82 @@ describe('player', () => {
expect(context).toMatchImageSnapshot();
});

it('0特殊处理', async () => {
const context = createContext('0特殊处理');
const ref = { current: null };
const { props } = (
<Canvas context={context}>
<Player
state="finish"
ref={ref}
keyFrames={[
{
view: {
to: {
width: '80px',
visible: true,
},
},
},
{
view1: {
to: {
width: '80px',
visible: true,
},
},
},
]}
>
<group>
<View key={'view'} visible={false} />
<View key={'view1'} visible={false} fill={'yellow'} />
</group>
</Player>
</Canvas>
);

const canvas = new Canvas(props);
await canvas.render();
await delay(200);
const { props: newProps } = (
<Canvas context={context}>
<Player
state="pause"
goTo={0}
ref={ref}
keyFrames={[
{
view: {
to: {
width: '80px',
visible: true,
},
},
},
{
view1: {
to: {
width: '80px',
visible: true,
},
},
},
]}
>
<group>
<View key={'view'} visible={false} />
<View key={'view1'} visible={false} fill={'yellow'} />
</group>
</Player>
</Canvas>
);

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

it('keyFrames-连续变化', async () => {
const context = createContext('连续变化');
const { props } = (
Expand Down

0 comments on commit a2b1568

Please sign in to comment.