computeFirstAnimatingVisibleIndex method

int computeFirstAnimatingVisibleIndex()

Returns the smallest _visibleOrder index among all currently-animating nodes, or visibleNodeCount when none are visible / none are animating.

Used by the render object to skip the O(N) Pass 1 offset rescan during animation: everything before the returned index has stable offset and extent from the prior frame, so only indices >= firstAnimatingIndex need to be recomputed.

Complexity is O(A) in the number of animating nodes, which is normally much smaller than the visible-order length.

Implementation

int computeFirstAnimatingVisibleIndex() {
  if (!hasActiveAnimations) return _order.length;
  // Cache key combines animation generation with structure generation:
  // the result depends on which keys are animating AND their visible indices.
  final sig =
      _anim.animationGeneration ^ (_structureGeneration * 2654435761);
  if (sig == _firstAnimatingIndexCacheSig &&
      _firstAnimatingIndexCacheVal <= _order.length) {
    return _firstAnimatingIndexCacheVal;
  }
  // Force the mirror rebuild via the coordinator. Iterate the
  // animating-keys cache (the union across all three sources) and find
  // the smallest visible index.
  final animatingKeys = _anim.ensureAnimatingKeys();
  int min = _order.length;
  for (final key in animatingKeys) {
    final idx = _order.indexOf(key);
    if (idx != VisibleOrderBuffer.kNotVisible && idx < min) {
      min = idx;
    }
  }
  _firstAnimatingIndexCacheSig = sig;
  _firstAnimatingIndexCacheVal = min;
  return min;
}