Skip to content

Commit 8acecb6

Browse files
quark-zjufacebook-github-bot
authored andcommitted
AnimatedReorderGroup: ignore small distance animation to workaround VSCode button rendering
Summary: I notice that when committing, while the optimistic state matches the final state, the commits below moves up and down unnecessarily. Upon debugging using a breakpoint in AnimatedReorderGroup when it decides to animate, I found a 4px animation, and the VSCode buttons [Uncommit] [Split] were in its "primary" style, with a larger height first rendered. Apparently the VSCode button then change to the specified "icon" style, with a different height, but it does not do that in the first render. There are enough pitfalls in VSCode toolkit we might want to just replace it... but for now let's workaround the issue by ignoring small distance animation. Screenshot when hitting the breakpoint - buttons have wrong style and height: {F1272099178} Reviewed By: zzl0 Differential Revision: D52667618 fbshipit-source-id: c183d7c60ce0e5da19afd39bf696cff89f5650a3
1 parent 7342957 commit 8acecb6

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

addons/isl/src/AnimatedReorderGroup.tsx

+11-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import React, {useRef, useLayoutEffect} from 'react';
1111
type ReorderGroupProps = {
1212
children: React.ReactElement[];
1313
animationDuration?: number;
14+
animationMinPixel?: number;
1415
};
1516

1617
type PreviousState = {
@@ -40,14 +41,15 @@ const emptyPreviousState: Readonly<PreviousState> = {
4041
export const AnimatedReorderGroup: React.FC<ReorderGroupProps> = ({
4142
children,
4243
animationDuration,
44+
animationMinPixel,
4345
...props
4446
}) => {
4547
const containerRef = useRef<HTMLDivElement | null>(null);
4648
const previousStateRef = useRef<Readonly<PreviousState>>(emptyPreviousState);
4749

4850
useLayoutEffect(() => {
49-
updatePreviousState(containerRef, previousStateRef, true, animationDuration);
50-
}, [children, animationDuration]);
51+
updatePreviousState(containerRef, previousStateRef, true, animationDuration, animationMinPixel);
52+
}, [children, animationDuration, animationMinPixel]);
5153

5254
// Try to get the rects of old children right before rendering new children
5355
// and calling the LayoutEffect callback. This captures position changes
@@ -76,6 +78,7 @@ function updatePreviousState(
7678
previousStateRef: React.MutableRefObject<Readonly<PreviousState>>,
7779
animate = false,
7880
animationDuration = 200,
81+
animationMinPixel = 5,
7982
) {
8083
const elements = scanElements(containerRef);
8184
const idList: Array<string> = [];
@@ -93,10 +96,12 @@ function updatePreviousState(
9396
// Animate from old to the new (current) rect.
9497
const dx = oldBox.left - newBox.left;
9598
const dy = oldBox.top - newBox.top;
96-
element.animate(
97-
[{transform: `translate(${dx}px,${dy}px)`}, {transform: 'translate(0,0)'}],
98-
{duration: animationDuration, easing: 'ease-out'},
99-
);
99+
if (Math.abs(dx) + Math.abs(dy) > animationMinPixel) {
100+
element.animate(
101+
[{transform: `translate(${dx}px,${dy}px)`}, {transform: 'translate(0,0)'}],
102+
{duration: animationDuration, easing: 'ease-out'},
103+
);
104+
}
100105
}
101106
}
102107
rectMap.set(reorderId, newBox);

0 commit comments

Comments
 (0)