clampPrediction static method

  1. @visibleForTesting
double clampPrediction({
  1. required double h,
  2. required double native,
  3. required double animFrom,
  4. required double animTo,
  5. required double current,
})

Caps the LUT prediction h against the fresh native reading. The native value is per-vsync fresh on Android R+ (via WindowInsetsAnimation.onProgress) and iOS (via CADisplayLink); on Android pre-R it snaps to the target up-front, making this a no-op. This trades the LUT's predictive lead for robustness against overshoot when the LUT hasn't adapted to this device's actual curve.

Rising (animTo > animFrom): native is a ceiling the prediction may not overshoot. Closing: native is a floor that can hold the height up while the real keyboard lags, but never raise it — the floor is trusted only inside [animTo, animFrom] and never above current, so a native flash back to the full frame mid-close cannot lift the height.

Implementation

@visibleForTesting
static double clampPrediction({
  required double h,
  required double native,
  required double animFrom,
  required double animTo,
  required double current,
}) {
  if (animTo > animFrom && h > native) {
    return native;
  }
  if (animTo < animFrom && h < native) {
    final floor = math.min(clampDouble(native, animTo, animFrom), current);
    return math.max(h, floor);
  }
  return h;
}