blobRect static method
The frame of the travelling droplet (Blob B) for one morph frame.
Size follows LiquidMorphState.sizeT and position follows LiquidMorphState.pathT; keeping them on separate curves is what opens the gap the metaball neck stretches across.
Center displacement is driven by sizeT with anchor-drift clamped to at
most 8 px (rawAnchorDrift.clamp(-8, 8)), pinning the base of the expanding
blob to the trigger button during flight. This achieves GlassMenu's
cohesive "one animated blob" feel that grows and shrinks smoothly.
On close undershoot (sizeT <= 0.0), the droplet squeezes relative to
the trigger's own dimensions rather than subtracting destination delta,
preventing 0 px collapse.
Implementation
static Rect blobRect({
required Rect trigger,
required Rect destination,
required double pathT,
required double sizeT,
double scaleDelta = 1.0,
bool isClosing = false,
double travelDx = 0.0,
double travelDy = 0.0,
}) {
// Wide/pill triggers (tw > th) launch from and collapse back into a
// centered compact circular core (`shortestSide × shortestSide` at
// `trigger.center`), matching native iOS 27 MagicMorphView. Square triggers
// keep `originSide == trigger.width == trigger.height` unchanged.
final double originSide = trigger.shortestSide;
final double width;
final double height;
if (sizeT <= 0.0) {
// Close undershoot bounce: droplet is at the trigger, squeeze relative
// to the compact trigger core — never subtract destination delta!
final squeeze = (1.0 + sizeT * 0.25).clamp(0.5, 1.0);
width = originSide * squeeze;
height = originSide * squeeze;
} else {
width = lerpDouble(originSide, destination.width, sizeT)!.clamp(0.0, 1e6);
height =
lerpDouble(originSide, destination.height, sizeT)!.clamp(0.0, 1e6);
}
const double maxAnchorDrift = 8.0;
final double finalDx = destination.center.dx - trigger.center.dx;
final double finalDy = destination.center.dy - trigger.center.dy;
final double rawAnchorDriftX = finalDx * (pathT - sizeT);
final double anchorDriftX =
rawAnchorDriftX.clamp(-maxAnchorDrift, maxAnchorDrift);
final double effectiveDx = finalDx * sizeT + anchorDriftX;
final double rawAnchorDriftY = finalDy * (pathT - sizeT);
final double anchorDriftY =
rawAnchorDriftY.clamp(-maxAnchorDrift, maxAnchorDrift);
final double effectiveDy = finalDy * sizeT + anchorDriftY;
final double centerX = trigger.center.dx + effectiveDx;
final double centerY = trigger.center.dy + effectiveDy;
return Rect.fromLTWH(
centerX - width / 2.0,
centerY - height / 2.0,
width,
height,
);
}