public static boolean isTopLevelScrollItem(
      @Nullable AccessibilityNodeInfoCompat node, @Nullable View view) {
    if (node == null || view == null) {
      return false;
    }

    final View parent = (View) ViewCompat.getParentForAccessibility(view);
    if (parent == null) {
      return false;
    }

    if (node.isScrollable()) {
      return true;
    }

    final List actionList = node.getActionList();
    if (Preconditions.checkNotNull(actionList)
            .contains(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD)
        || actionList.contains(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD)) {
      return true;
    }

    // Top-level items in a scrolling pager are actually two levels down since the first
    // level items in pagers are the pages themselves.
    View grandparent = (View) ViewCompat.getParentForAccessibility(parent);
    if (grandparent != null && getRole(grandparent) == AccessibilityRole.PAGER) {
      return true;
    }

    AccessibilityRole parentRole = getRole(parent);
    return parentRole == AccessibilityRole.LIST
        || parentRole == AccessibilityRole.GRID
        || parentRole == AccessibilityRole.SCROLL_VIEW
        || parentRole == AccessibilityRole.HORIZONTAL_SCROLL_VIEW;
  }
Determines whether the provided {@link View} and {@link AccessibilityNodeInfoCompat} is a
top-level item in a scrollable container.

@param view The {@link View} to evaluate
@param node The {@link AccessibilityNodeInfoCompat} to evaluate
@return {@code true} if it is a top-level item in a scrollable container.
core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java