MCPcopy Create free account
hub / github.com/callstack/agent-device / selectScrollContainer

Function selectScrollContainer

src/utils/scroll-edge-state.ts:168–209  ·  view source on GitHub ↗
(
  nodes: SnapshotNode[],
  hiddenHints: Map<number, HiddenContentHint>,
  edge: ScrollEdge,
  target: ScrollEdgeTarget,
)

Source from the content-addressed store, hash-verified

166}
167
168function selectScrollContainer(
169 nodes: SnapshotNode[],
170 hiddenHints: Map<number, HiddenContentHint>,
171 edge: ScrollEdge,
172 target: ScrollEdgeTarget,
173): SnapshotNode | null {
174 const byIndex = new Map(nodes.map((node) => [node.index, node]));
175 const scrollables = nodes.filter((node) => isScrollableNodeLike(node) && isUsableRect(node.rect));
176 if (scrollables.length === 0) {
177 return null;
178 }
179
180 const targetAncestor = findNearestScrollableAncestor(target.nodeIndex, byIndex);
181 if (targetAncestor) {
182 return targetAncestor;
183 }
184
185 const targetPoint = target.point;
186 if (targetPoint) {
187 const containing = scrollables
188 .filter((node) => node.rect && containsPoint(node.rect, targetPoint))
189 .sort(compareSpecificScrollContainer);
190 if (containing.length > 0) {
191 const withHiddenEdge = containing.find((node) =>
192 hasHiddenContentAtEdge(node, hiddenHints.get(node.index), edge),
193 );
194 return withHiddenEdge ?? containing[0] ?? null;
195 }
196 }
197
198 const withHiddenEdge = scrollables
199 .filter((node) => hasHiddenContentAtEdge(node, hiddenHints.get(node.index), edge))
200 .sort(compareBroadScrollContainer);
201 if (withHiddenEdge.length > 0) {
202 return withHiddenEdge[0] ?? null;
203 }
204
205 const visibleScrollables = scrollables
206 .filter((node) => isNodeVisibleInEffectiveViewport(node, nodes))
207 .sort(compareBroadScrollContainer);
208 return visibleScrollables[0] ?? scrollables.sort(compareBroadScrollContainer)[0] ?? null;
209}
210
211function findNearestScrollableAncestor(
212 nodeIndex: number | undefined,

Callers 1

analyzeScrollEdgeStateFunction · 0.85

Calls 7

isScrollableNodeLikeFunction · 0.90
hasHiddenContentAtEdgeFunction · 0.85
getMethod · 0.80
isUsableRectFunction · 0.70
containsPointFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…