Skip to content

Commit 0a7ca9b

Browse files
authored
fix: Fixed the issue of multiple calls to onResizeEnd in lazy mode (ant-design#53708)
1 parent b23487e commit 0a7ca9b

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

components/splitter/SplitBar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface SplitBarProps {
1515
endCollapsible: boolean;
1616
onOffsetStart: (index: number) => void;
1717
onOffsetUpdate: (index: number, offsetX: number, offsetY: number, lazyEnd?: boolean) => void;
18-
onOffsetEnd: VoidFunction;
18+
onOffsetEnd: (lazyEnd?: boolean) => void;
1919
onCollapse: (index: number, type: 'start' | 'end') => void;
2020
vertical: boolean;
2121
ariaNow: number;
@@ -95,7 +95,7 @@ const SplitBar: React.FC<SplitBarProps> = (props) => {
9595
const handleLazyEnd = useEvent(() => {
9696
onOffsetUpdate(index, constrainedOffsetX, constrainedOffsetY, true);
9797
setConstrainedOffset(0);
98-
onOffsetEnd();
98+
onOffsetEnd(true);
9999
});
100100

101101
React.useEffect(() => {
@@ -138,9 +138,10 @@ const SplitBar: React.FC<SplitBarProps> = (props) => {
138138
const handleTouchEnd = () => {
139139
if (lazy) {
140140
handleLazyEnd();
141+
} else {
142+
onOffsetEnd();
141143
}
142144
setStartPos(null);
143-
onOffsetEnd();
144145
};
145146

146147
window.addEventListener('touchmove', handleTouchMove);

components/splitter/Splitter.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ const Splitter: React.FC<React.PropsWithChildren<SplitterProps>> = (props) => {
119119
}
120120
});
121121

122-
const onInternalResizeEnd = useEvent(() => {
123-
onOffsetEnd();
122+
const onInternalResizeEnd = useEvent((lazyEnd?: boolean) => {
123+
if (lazyEnd) {
124+
onOffsetEnd();
125+
return;
126+
}
124127
onResizeEnd?.(itemPxSizes);
125128
});
126129

components/splitter/__tests__/index.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ describe('Splitter', () => {
155155
// Right
156156
mockDrag(container.querySelector('.ant-splitter-bar-dragger')!, 40);
157157
expect(onResize).toHaveBeenCalledWith([90, 10]);
158+
expect(onResizeEnd).toHaveBeenCalledTimes(1);
158159
expect(onResizeEnd).toHaveBeenCalledWith([90, 10]);
159160

160161
// Left
@@ -176,6 +177,7 @@ describe('Splitter', () => {
176177
// Right
177178
mockTouchDrag(container.querySelector('.ant-splitter-bar-dragger')!, 40);
178179
expect(onResize).toHaveBeenCalledWith([90, 10]);
180+
expect(onResizeEnd).toHaveBeenCalledTimes(1);
179181
expect(onResizeEnd).toHaveBeenCalledWith([90, 10]);
180182

181183
// Left

components/splitter/__tests__/lazy.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ describe('Splitter lazy', () => {
116116

117117
// Right
118118
mockDrag(container.querySelector('.ant-splitter-bar-dragger')!, onResize, 1000);
119+
expect(onResizeEnd).toHaveBeenCalledTimes(1);
119120
expect(onResizeEnd).toHaveBeenCalledWith([70, 30]);
120121

121122
// Left

0 commit comments

Comments
 (0)