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 (#44822)

Summary:
Pull Request resolved: #44822

Changelog: [Breaking]

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

Reviewed By: NickGerleman

Differential Revision: D58223380

fbshipit-source-id: 4faa1409d9c87e2c92118941aa193ba0a0f34367
  • Loading branch information
realsoelynn authored and facebook-github-bot committed Jun 12, 2024
1 parent fd61881 commit ce588db
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,11 @@ 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,8 @@ 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 +274,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 @@ -122,8 +122,11 @@ class LayoutableShadowNode : public ShadowNode {
* Returns offset which is applied to children's origin in
* `LayoutableShadowNode::getRelativeLayoutMetrics` and
* `LayoutableShadowNode::findNodeAtPoint`.
* i`ncludeTransform` is a flag to include the transform in the offset. This
* is a rare case but needed for case where transform is involved for e.g. in
* ScrollView.
*/
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,8 @@ 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 ce588db

Please sign in to comment.