Skip to content

Commit ce588db

Browse files
realsoelynnfacebook-github-bot
authored andcommitted
Make getContentOriginOffset to know info about if call-site want transform 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
1 parent fd61881 commit ce588db

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ void ScrollViewShadowNode::layout(LayoutContext layoutContext) {
6363
updateStateIfNeeded();
6464
}
6565

66-
Point ScrollViewShadowNode::getContentOriginOffset() const {
66+
Point ScrollViewShadowNode::getContentOriginOffset(
67+
bool /*includeTransform*/) const {
6768
auto stateData = getStateData();
6869
auto contentOffset = stateData.contentOffset;
70+
6971
return {-contentOffset.x, -contentOffset.y + stateData.scrollAwayPaddingTop};
7072
}
7173

packages/react-native/ReactCommon/react/renderer/components/scrollview/ScrollViewShadowNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ScrollViewShadowNode final : public ConcreteViewShadowNode<
3737
#pragma mark - LayoutableShadowNode
3838

3939
void layout(LayoutContext layoutContext) override;
40-
Point getContentOriginOffset() const override;
40+
Point getContentOriginOffset(bool includeTransform) const override;
4141

4242
private:
4343
void updateStateIfNeeded();

packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
151151
}
152152

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

157161
if (policy.enableOverflowClipping) {
@@ -188,7 +192,8 @@ Transform LayoutableShadowNode::getTransform() const {
188192
return Transform::Identity();
189193
}
190194

191-
Point LayoutableShadowNode::getContentOriginOffset() const {
195+
Point LayoutableShadowNode::getContentOriginOffset(
196+
bool /*includeTransform*/) const {
192197
return {0, 0};
193198
}
194199

@@ -269,7 +274,7 @@ ShadowNode::Shared LayoutableShadowNode::findNodeAtPoint(
269274
}
270275

271276
auto newPoint = point - transformedFrame.origin -
272-
layoutableShadowNode->getContentOriginOffset();
277+
layoutableShadowNode->getContentOriginOffset(false);
273278

274279
auto sortedChildren = node->getChildren();
275280
std::stable_sort(

packages/react-native/ReactCommon/react/renderer/core/LayoutableShadowNode.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ class LayoutableShadowNode : public ShadowNode {
122122
* Returns offset which is applied to children's origin in
123123
* `LayoutableShadowNode::getRelativeLayoutMetrics` and
124124
* `LayoutableShadowNode::findNodeAtPoint`.
125+
* i`ncludeTransform` is a flag to include the transform in the offset. This
126+
* is a rare case but needed for case where transform is involved for e.g. in
127+
* ScrollView.
125128
*/
126-
virtual Point getContentOriginOffset() const;
129+
virtual Point getContentOriginOffset(bool includeTransform) const;
127130

128131
/*
129132
* Sets layout metrics for the shadow node.

packages/react-native/ReactCommon/react/renderer/core/tests/TestComponent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class TestShadowNode final : public ConcreteViewShadowNode<
7676

7777
facebook::react::Point _contentOriginOffset{};
7878

79-
facebook::react::Point getContentOriginOffset() const override {
79+
facebook::react::Point getContentOriginOffset(
80+
bool /*includeTransform*/) const override {
8081
return _contentOriginOffset;
8182
}
8283
};

packages/react-native/ReactCommon/react/renderer/dom/DOM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ DOMPoint getScrollPosition(
357357
return DOMPoint{};
358358
}
359359

360-
auto scrollPosition = layoutableShadowNode->getContentOriginOffset();
360+
auto scrollPosition = layoutableShadowNode->getContentOriginOffset(false);
361361

362362
return DOMPoint{
363363
.x = scrollPosition.x == 0 ? 0 : -scrollPosition.x,

0 commit comments

Comments
 (0)