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: [Internal]

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

Differential Revision: D58223380
  • Loading branch information
realsoelynn authored and facebook-github-bot committed Jun 11, 2024
1 parent 53dda9e commit 0bbf3dc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 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 @@ -189,6 +193,11 @@ Transform LayoutableShadowNode::getTransform() const {
}

Point LayoutableShadowNode::getContentOriginOffset() const {
return getContentOriginOffset(false);
}

Point LayoutableShadowNode::getContentOriginOffset(
bool includeTransform) const {
return {0, 0};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class LayoutableShadowNode : public ShadowNode {
*/
virtual Point getContentOriginOffset() const;

/*
* Returns offset which is applied to children's origin in
* `LayoutableShadowNode::getRelativeLayoutMetrics` and
* `LayoutableShadowNode::findNodeAtPoint`.
*/
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

0 comments on commit 0bbf3dc

Please sign in to comment.