scrollTargetFor function

Future<ScrollTarget> scrollTargetFor(
  1. GlintSession session,
  2. Scene scene,
  3. SceneNode hit,
  4. ScrollDirection dir,
)

The scrollable that moves hit along dir's axis (not whatever sits under the default swipe point) and the PageViews around it that must stay on their page; a target with no anchor keeps the default swipe.

Implementation

Future<ScrollTarget> scrollTargetFor(GlintSession session, Scene scene, SceneNode hit, ScrollDirection dir) async {
  const none = (anchor: null, watchedPagedIds: <String>{});
  final id = hit.glintId;
  if (id == null || scene.isInOverlay(id)) return none;
  try {
    final horizontal = dir == ScrollDirection.left || dir == ScrollDirection.right;
    final driven = await scrollableAround(session.runtime, scene, hit, horizontal: horizontal);
    final paged = [
      for (final a in _ancestorsOf(scene.root, hit))
        if (a.glintId != null && kPagedLabels.contains(a.baseLabel)) a.glintId!,
    ];
    final watched = {...paged.skip(driven != null && driven.paged ? 1 : 0)};
    if (driven == null) return (anchor: null, watchedPagedIds: watched);
    final coord = await session.resolver.resolve(scene, id);
    final anchor = coord.hasNonZeroBounds
        ? (glintId: id, x: coord.logicalCenter.x, y: coord.logicalCenter.y, clip: driven.rect)
        : null;
    return (anchor: anchor, watchedPagedIds: watched);
  } on Object {
    return none;
  }
}