mirror of
https://github.com/google/blockly.git
synced 2026-01-07 09:00:11 +01:00
* Fix #8194 by using animation steps for the wiggle * Formatting cleanup
This commit is contained in:
@@ -176,7 +176,7 @@ export function disconnectUiEffect(block: BlockSvg) {
|
|||||||
}
|
}
|
||||||
// Start the animation.
|
// Start the animation.
|
||||||
wobblingBlock = block;
|
wobblingBlock = block;
|
||||||
disconnectUiStep(block, magnitude, new Date());
|
disconnectUiStep(block, magnitude, new Date(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,22 +184,30 @@ export function disconnectUiEffect(block: BlockSvg) {
|
|||||||
*
|
*
|
||||||
* @param block Block to animate.
|
* @param block Block to animate.
|
||||||
* @param magnitude Maximum degrees skew (reversed for RTL).
|
* @param magnitude Maximum degrees skew (reversed for RTL).
|
||||||
* @param start Date of animation's start.
|
* @param start Date of animation's start for deciding when to stop.
|
||||||
|
* @param step Which step of the animation we're on.
|
||||||
*/
|
*/
|
||||||
function disconnectUiStep(block: BlockSvg, magnitude: number, start: Date) {
|
function disconnectUiStep(
|
||||||
|
block: BlockSvg,
|
||||||
|
magnitude: number,
|
||||||
|
start: Date,
|
||||||
|
step: number,
|
||||||
|
) {
|
||||||
const DURATION = 200; // Milliseconds.
|
const DURATION = 200; // Milliseconds.
|
||||||
const WIGGLES = 3; // Half oscillations.
|
const WIGGLES = [0.66, 1, 0.66, 0, -0.66, -1, -0.66, 0]; // Single cycle
|
||||||
|
|
||||||
const ms = new Date().getTime() - start.getTime();
|
|
||||||
const percent = ms / DURATION;
|
|
||||||
|
|
||||||
let skew = '';
|
let skew = '';
|
||||||
if (percent <= 1) {
|
if (start.getTime() + DURATION > new Date().getTime()) {
|
||||||
const val = Math.round(
|
const val = Math.round(WIGGLES[step % WIGGLES.length] * magnitude);
|
||||||
Math.sin(percent * Math.PI * WIGGLES) * (1 - percent) * magnitude,
|
|
||||||
);
|
|
||||||
skew = `skewX(${val})`;
|
skew = `skewX(${val})`;
|
||||||
disconnectPid = setTimeout(disconnectUiStep, 10, block, magnitude, start);
|
disconnectPid = setTimeout(
|
||||||
|
disconnectUiStep,
|
||||||
|
15,
|
||||||
|
block,
|
||||||
|
magnitude,
|
||||||
|
start,
|
||||||
|
step + 1,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
block
|
block
|
||||||
|
|||||||
Reference in New Issue
Block a user