| 1108 | if (auto* anchor = preserveDescendantAtY(scrollNode, probeY); anchor != nullptr && anchor->getRawId() != 0) { |
| 1109 | scrollState.setPreserveAnchor(anchor->getRawId(), preserveAnchorAbsoluteTop(scrollNode, anchor) - offsetY); |
| 1110 | } else { |
| 1111 | scrollState.clearPreserveAnchor(); |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | } // namespace |
| 1116 | |
| 1117 | void ViewNode::handleOnScroll(const Point& directionDependentContentOffset, |
| 1118 | const Point& directionDependentUnclampedContentOffset, |
| 1119 | const Point& directionDependentVelocity) { |
| 1120 | VALDI_TRACE("Valdi.handleOnScroll"); |
| 1121 | auto tree = Ref(getViewNodeTree()); |
| 1122 | |
| 1123 | tree->getContext()->withAttribution([&]() { |
| 1124 | auto disableUpdates = tree->beginDisableUpdates(); |
| 1125 | auto& scrollState = getOrCreateScrollState(); |
| 1126 | auto shouldUpdateAttributeSync = scrollState.onScrollCallbackPrefersSyncCalls(); |
| 1127 | |
| 1128 | auto directionAgnosticContentOffset = |
| 1129 | scrollState.resolveDirectionAgnosticContentOffset(directionDependentContentOffset); |
| 1130 | auto directionAgnosticUnclampedContentOffset = |
| 1131 | scrollState.resolveDirectionAgnosticContentOffset(directionDependentUnclampedContentOffset); |
| 1132 | |
| 1133 | updateScrollAttributeValueIfNeeded( |
| 1134 | DefaultAttributeContentOffsetX, directionAgnosticContentOffset.x, shouldUpdateAttributeSync); |
| 1135 | updateScrollAttributeValueIfNeeded( |
| 1136 | DefaultAttributeContentOffsetY, directionAgnosticContentOffset.y, shouldUpdateAttributeSync); |
| 1137 | |
| 1138 | scrollState.notifyOnScroll( |
| 1139 | directionAgnosticContentOffset, directionAgnosticUnclampedContentOffset, directionDependentVelocity); |
| 1140 | |
| 1141 | // Keep the preserveScrollPosition anchor in sync with the live scroll position. Layout |
| 1142 | // passes (updateScrollState) only run on relayout, but the offset also moves on scroll and |
| 1143 | // clamp; refreshing here means a later content reflow pins the node the user is actually |
| 1144 | // looking at, not a stale one captured at an old offset. |
no test coverage detected