Skip to content

Commit

Permalink
Make getContentOriginOffset to know info about if call-site want tran…
Browse files Browse the repository at this point in the history
…sform or not (facebook#44822)

Summary:
Pull Request resolved: facebook#44822

Changelog: [Internal]

This is to make `getContentOriginOffset` to have `includeTransform` information passed during Layout computation.

Differential Revision: D58223380
  • Loading branch information
realsoelynn authored and kosmydel committed Jun 11, 2024
1 parent 53dda9e commit 1b04157
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ void ScrollViewShadowNode::layout(LayoutContext layoutContext) {
updateStateIfNeeded();
}

Point ScrollViewShadowNode::getContentOriginOffset() const {
Point ScrollViewShadowNode::getContentOriginOffset(
bool /* includeTransform */) const {

auto stateData = getStateData();
auto contentOffset = stateData.contentOffset;

return {-contentOffset.x, -contentOffset.y + stateData.scrollAwayPaddingTop};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ScrollViewShadowNode final : public ConcreteViewShadowNode<
#pragma mark - LayoutableShadowNode

void layout(LayoutContext layoutContext) override;
Point getContentOriginOffset() const override;
Point getContentOriginOffset(bool includeTransform) const override;

private:
void updateStateIfNeeded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
}

if (i != 0 && policy.includeTransform) {
resultFrame.origin += currentShadowNode->getContentOriginOffset();
// Transformation is not applied here and instead we delegated out in
// getContentOriginOffset. The reason is that for `ScrollViewShadowNode`,
// we need to consider `scrollAwayPaddingTop` which should NOT be included
// in the transform.
resultFrame.origin += currentShadowNode->getContentOriginOffset(true);
}

if (policy.enableOverflowClipping) {
Expand Down Expand Up @@ -188,7 +192,9 @@ Transform LayoutableShadowNode::getTransform() const {
return Transform::Identity();
}

Point LayoutableShadowNode::getContentOriginOffset() const {
Point LayoutableShadowNode::getContentOriginOffset(
bool /*includeTransform*/) const {

return {0, 0};
}

Expand Down Expand Up @@ -269,7 +275,7 @@ ShadowNode::Shared LayoutableShadowNode::findNodeAtPoint(
}

auto newPoint = point - transformedFrame.origin -
layoutableShadowNode->getContentOriginOffset();
layoutableShadowNode->getContentOriginOffset(false);

auto sortedChildren = node->getChildren();
std::stable_sort(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class LayoutableShadowNode : public ShadowNode {
* `LayoutableShadowNode::getRelativeLayoutMetrics` and
* `LayoutableShadowNode::findNodeAtPoint`.
*/
virtual Point getContentOriginOffset() const;
virtual Point getContentOriginOffset(bool includeTransform) const;

/*
* Sets layout metrics for the shadow node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class TestShadowNode final : public ConcreteViewShadowNode<

facebook::react::Point _contentOriginOffset{};

facebook::react::Point getContentOriginOffset() const override {
facebook::react::Point getContentOriginOffset(
bool /* includeTransform */) const override {

return _contentOriginOffset;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ DOMPoint getScrollPosition(
return DOMPoint{};
}

auto scrollPosition = layoutableShadowNode->getContentOriginOffset();
auto scrollPosition = layoutableShadowNode->getContentOriginOffset(false);

return DOMPoint{
.x = scrollPosition.x == 0 ? 0 : -scrollPosition.x,
Expand Down

0 comments on commit 1b04157

Please sign in to comment.