FEngine icon indicating copy to clipboard operation
FEngine copied to clipboard

fix: 基础 shape destroy 逻辑

Open huaxiabuluo opened this issue 5 months ago • 3 comments

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 没有销毁擦除) vnode-update-test-tsx-vnode-更新-基础图形更新-1-snap

  • After (update 渲染正常, rect 被销毁擦除) vnode-update-test-tsx-vnode-更新-基础图形更新-1-snap

huaxiabuluo avatar Aug 19 '25 03:08 huaxiabuluo

/gemini review

tangying1027 avatar Aug 20 '25 07:08 tangying1027

关于 F2 的动画设计,达成几项一致:

  1. leave/appear 配置,不管是单 shape 还是多 shape,都应该被执行
  2. 除非多 shape 的后者(A->B 的 B),指定了 update,则跳过 leave/appear
  3. 多 shape 过渡,A leave -> B appear,决定采用串行,比较符合上层业务的预期直觉

edokeh avatar Sep 01 '25 13:09 edokeh

关于 F2 的动画设计,达成几项一致:

  1. leave/appear 配置,不管是单 shape 还是多 shape,都应该被执行
  2. 除非多 shape 的后者(A->B 的 B),指定了 update,则跳过 leave/appear
  3. 多 shape 过渡,A leave -> B appear,决定采用串行,比较符合上层业务的预期直觉

补充: 可以渐进式修改,先修改无动画情况,把带动画的单测全部去掉,以免造成混乱

tangying1027 avatar Sep 02 '25 02:09 tangying1027