| 1087 | // we would anchor to the first id-less node (content top) and jump the viewport. |
| 1088 | if (depth <= 0 || id == 0) |
| 1089 | return nullptr; |
| 1090 | for (auto* child : *node) { |
| 1091 | if (child->getRawId() == id) |
| 1092 | return child; |
| 1093 | auto* found = preserveFindDescendantById(child, id, depth - 1); |
| 1094 | if (found) |
| 1095 | return found; |
| 1096 | } |
| 1097 | return nullptr; |
| 1098 | } |
| 1099 | |
| 1100 | // Re-pick the anchor (the node at the viewport center) and remember its id + screen position |
| 1101 | // (absolute top relative to the viewport top) so a later content reflow can pin it back. Called |
| 1102 | // from both layout (updateScrollState) and scroll (handleOnScroll) so the anchor never goes stale |
| 1103 | // between layout passes. |
| 1104 | void refreshPreserveAnchor(ViewNode* scrollNode, ViewNodeScrollState& scrollState, float offsetY, float viewportH) { |
| 1105 | float probeY = offsetY + viewportH * 0.5f; |
| 1106 | // Only anchor on a node with a real, trackable rawId. id 0 (unset/default) can't be re-found |
| 1107 | // across passes, so don't record it -- clear instead and re-pick next pass. |
| 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(); |
no test coverage detected