Skip to content

Commit e5a1722

Browse files
Fix unreliable MoveLabwareOnDeck animation.
1 parent 95b9d6e commit e5a1722

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

components/src/hardware-sim/Deck/MoveLabwareOnDeck.tsx

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,36 @@ export function MoveLabwareOnDeck(
116116
animationFinalCoordinates
117117
)
118118

119-
const springProps = useSpring({
120-
reset: shouldReset,
121-
config: { duration: 1000, easing: easings.easeInOutSine },
122-
from: {
123-
...animationInitialCoordinates,
124-
splashOpacity: 0,
125-
deckOpacity: 0,
126-
},
127-
to: [
128-
{ deckOpacity: 1 },
129-
{ splashOpacity: 1 },
130-
{ splashOpacity: 0 },
131-
{ ...animationFinalCoordinates },
132-
{ splashOpacity: 1 },
133-
{ splashOpacity: 0 },
134-
{ deckOpacity: 0 },
135-
],
136-
loop: true,
137-
})
119+
const [springProps] = useSpring(
120+
() => ({
121+
reset: shouldReset,
122+
config: { duration: 1000, easing: easings.easeInOutSine },
123+
from: {
124+
...animationInitialCoordinates,
125+
splashOpacity: 0,
126+
deckOpacity: 0,
127+
},
128+
to: [
129+
{ deckOpacity: 1 },
130+
{ splashOpacity: 1 },
131+
{ splashOpacity: 0 },
132+
{ ...animationFinalCoordinates },
133+
{ splashOpacity: 1 },
134+
{ splashOpacity: 0 },
135+
{ deckOpacity: 0 },
136+
],
137+
loop: true,
138+
}),
139+
// Dependency array:
140+
[
141+
shouldReset,
142+
// react-spring behaves weirdly if its props are updated too frequently.
143+
// So make sure to filter out coordinate "updates" that are just object identity
144+
// updates and not updates to the actual x/y/z components.
145+
...Object.values(animationInitialCoordinates),
146+
...Object.values(animationFinalCoordinates),
147+
]
148+
)
138149

139150
return (
140151
<BaseDeck

0 commit comments

Comments
 (0)