FEngine
FEngine copied to clipboard
fix: 基础 shape destroy 逻辑
当 Canvas 的实例调用 render 方法完成首次渲染后,再次执行 update 方法更新画布,如果使用了 line | circle | rect | ... 等基础图形标签,会导致上一屏的基础图形不会被正确擦除。
对于下面测试用例:
const context = createContext();
const { props } = (
<Canvas context={context}>
<rect
style={{
width: 36,
height: 36,
fill: 'red',
}}
/>
</Canvas>
);
const canvas = new Canvas(props);
await canvas.render();
const { props: nextProps } = (
<Canvas context={context}>
<circle
style={{
cx: 80,
cy: 30,
r: 20,
lineWidth: 2,
stroke: '#e45649',
fill: 'blue',
}}
/>
</Canvas>
);
await delay(500);
await canvas.update(nextProps);
await delay(200);
expect(context).toMatchImageSnapshot();
-
Before (update 渲染异常,
rect没有销毁擦除) -
After (update 渲染正常,
rect被销毁擦除)
/gemini review
关于 F2 的动画设计,达成几项一致:
- leave/appear 配置,不管是单 shape 还是多 shape,都应该被执行
- 除非多 shape 的后者(A->B 的 B),指定了 update,则跳过 leave/appear
- 多 shape 过渡,A leave -> B appear,决定采用串行,比较符合上层业务的预期直觉
关于 F2 的动画设计,达成几项一致:
- leave/appear 配置,不管是单 shape 还是多 shape,都应该被执行
- 除非多 shape 的后者(A->B 的 B),指定了 update,则跳过 leave/appear
- 多 shape 过渡,A leave -> B appear,决定采用串行,比较符合上层业务的预期直觉
补充: 可以渐进式修改,先修改无动画情况,把带动画的单测全部去掉,以免造成混乱