MCPcopy Create free account
hub / github.com/adobe/react-spectrum / isNearEdge

Function isNearEdge

packages/react-stately/src/virtualizer/ScrollAnchor.ts:127–140  ·  view source on GitHub ↗
(
  visibleRect: Rect,
  contentSize: Size,
  edge: ScrollAnchorEdge,
  axis: ScrollAnchorAxis,
  threshold: number
)

Source from the content-addressed store, hash-verified

125 * Virtualizer to compute wasNearAnchorEdge generically, without any layout-specific state.
126 */
127export function isNearEdge(
128 visibleRect: Rect,
129 contentSize: Size,
130 edge: ScrollAnchorEdge,
131 axis: ScrollAnchorAxis,
132 threshold: number
133): boolean {
134 if (edge === 'start') {
135 return visibleRect[axis] <= threshold;
136 }
137 let dimension = dimensionForAxis(axis);
138 let distanceFromEnd = contentSize[dimension] - (visibleRect[axis] + visibleRect[dimension]);
139 return distanceFromEnd <= threshold;
140}
141
142/**
143 * Works out the new scroll position after content changes. Tries to keep the anchor

Callers 2

resolveAfterLayoutMethod · 0.85

Calls 1

dimensionForAxisFunction · 0.85

Tested by

no test coverage detected