Skip to content

Commit 1e0211b

Browse files
huaxiabuluoian.lxl
andauthored
fix: basic shapes update (#336)
Co-authored-by: ian.lxl <ian.lxl@antgroup.com>
1 parent 91751ca commit 1e0211b

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

packages/f-engine/src/canvas/render/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,16 @@ function createElement(parent: VNode, element: JSX.Element): VNode | VNode[] | n
188188
function destroyElement(vNode: VNode | VNode[] | null) {
189189
Children.map(vNode, (node: VNode | null) => {
190190
if (!node) return;
191-
const { component, children } = node;
191+
const { component, children, shape, tag } = node;
192192
if (component) {
193193
component.willUnmount();
194194
destroyElement(children);
195195
component.didUnmount();
196196
component.destroy();
197-
} else {
197+
} else if (children) {
198198
destroyElement(children);
199+
} else if (tag === Shape && shape) {
200+
shape.destroy();
199201
}
200202
});
201203
}
3.39 KB
Loading

packages/f-engine/test/canvas/render/vnodeUpdate.test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,41 @@ describe('vnode 更新', () => {
4242

4343
expect(ref.current._vNode.props.update).toBe(true);
4444
});
45+
it('基础图形更新', async () => {
46+
const context = createContext();
47+
const { props } = (
48+
<Canvas context={context}>
49+
<rect
50+
style={{
51+
width: 36,
52+
height: 36,
53+
fill: 'red',
54+
}}
55+
/>
56+
</Canvas>
57+
);
58+
59+
const canvas = new Canvas(props);
60+
await canvas.render();
61+
62+
const { props: nextProps } = (
63+
<Canvas context={context}>
64+
<circle
65+
style={{
66+
cx: 80,
67+
cy: 30,
68+
r: 20,
69+
lineWidth: 2,
70+
stroke: '#e45649',
71+
fill: 'blue',
72+
}}
73+
/>
74+
</Canvas>
75+
);
76+
await delay(500);
77+
await canvas.update(nextProps);
78+
79+
await delay(200);
80+
expect(context).toMatchImageSnapshot();
81+
});
4582
});

0 commit comments

Comments
 (0)