@@ -176,30 +176,38 @@ export function disconnectUiEffect(block: BlockSvg) {
176176 }
177177 // Start the animation.
178178 wobblingBlock = block ;
179- disconnectUiStep ( block , magnitude , new Date ( ) ) ;
179+ disconnectUiStep ( block , magnitude , new Date ( ) , 0 ) ;
180180}
181181
182182/**
183183 * Animate a brief wiggle of a disconnected block.
184184 *
185185 * @param block Block to animate.
186186 * @param magnitude Maximum degrees skew (reversed for RTL).
187- * @param start Date of animation's start.
187+ * @param start Date of animation's start for deciding when to stop.
188+ * @param step Which step of the animation we're on.
188189 */
189- function disconnectUiStep ( block : BlockSvg , magnitude : number , start : Date ) {
190+ function disconnectUiStep (
191+ block : BlockSvg ,
192+ magnitude : number ,
193+ start : Date ,
194+ step : number ,
195+ ) {
190196 const DURATION = 200 ; // Milliseconds.
191- const WIGGLES = 3 ; // Half oscillations.
192-
193- const ms = new Date ( ) . getTime ( ) - start . getTime ( ) ;
194- const percent = ms / DURATION ;
197+ const WIGGLES = [ 0.66 , 1 , 0.66 , 0 , - 0.66 , - 1 , - 0.66 , 0 ] ; // Single cycle
195198
196199 let skew = '' ;
197- if ( percent <= 1 ) {
198- const val = Math . round (
199- Math . sin ( percent * Math . PI * WIGGLES ) * ( 1 - percent ) * magnitude ,
200- ) ;
200+ if ( start . getTime ( ) + DURATION > new Date ( ) . getTime ( ) ) {
201+ const val = Math . round ( WIGGLES [ step % WIGGLES . length ] * magnitude ) ;
201202 skew = `skewX(${ val } )` ;
202- disconnectPid = setTimeout ( disconnectUiStep , 10 , block , magnitude , start ) ;
203+ disconnectPid = setTimeout (
204+ disconnectUiStep ,
205+ 15 ,
206+ block ,
207+ magnitude ,
208+ start ,
209+ step + 1 ,
210+ ) ;
203211 }
204212
205213 block
0 commit comments