IntersectionObserverEntry.fromRects constructor

IntersectionObserverEntry.fromRects({
  1. required Rect boundingClientRect,
  2. required Rect rootBounds,
})

Constructs a IntersectionObserverEntry from element bounds and a corresponding clipping rectangle.

boundingClientRect and rootBounds are expected to be in the same coordinate system.

Implementation

factory IntersectionObserverEntry.fromRects({
  required Rect boundingClientRect,
  required Rect rootBounds,
}) {

  // Compute the intersection in the element's local coordinates.
  final intersectionRect = boundingClientRect.overlaps(rootBounds)
      ? boundingClientRect
          .intersect(rootBounds)
          .shift(-boundingClientRect.topLeft)
      : Rect.zero;

  return IntersectionObserverEntry(
      boundingClientRect: boundingClientRect,
      intersectionRect: intersectionRect,
      rootBounds: rootBounds,
      size: boundingClientRect.size);
}