File tree Expand file tree Collapse file tree 6 files changed +19
-8
lines changed
packages/react-native/ReactCommon/react/renderer Expand file tree Collapse file tree 6 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,11 @@ void ScrollViewShadowNode::layout(LayoutContext layoutContext) {
63
63
updateStateIfNeeded ();
64
64
}
65
65
66
- Point ScrollViewShadowNode::getContentOriginOffset () const {
66
+ Point ScrollViewShadowNode::getContentOriginOffset (
67
+ bool /* includeTransform*/ ) const {
67
68
auto stateData = getStateData ();
68
69
auto contentOffset = stateData.contentOffset ;
70
+
69
71
return {-contentOffset.x , -contentOffset.y + stateData.scrollAwayPaddingTop };
70
72
}
71
73
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ class ScrollViewShadowNode final : public ConcreteViewShadowNode<
37
37
#pragma mark - LayoutableShadowNode
38
38
39
39
void layout (LayoutContext layoutContext) override ;
40
- Point getContentOriginOffset () const override ;
40
+ Point getContentOriginOffset (bool includeTransform ) const override ;
41
41
42
42
private:
43
43
void updateStateIfNeeded ();
Original file line number Diff line number Diff line change @@ -151,7 +151,11 @@ LayoutMetrics LayoutableShadowNode::computeRelativeLayoutMetrics(
151
151
}
152
152
153
153
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 );
155
159
}
156
160
157
161
if (policy.enableOverflowClipping ) {
@@ -188,7 +192,8 @@ Transform LayoutableShadowNode::getTransform() const {
188
192
return Transform::Identity ();
189
193
}
190
194
191
- Point LayoutableShadowNode::getContentOriginOffset () const {
195
+ Point LayoutableShadowNode::getContentOriginOffset (
196
+ bool /* includeTransform*/ ) const {
192
197
return {0 , 0 };
193
198
}
194
199
@@ -269,7 +274,7 @@ ShadowNode::Shared LayoutableShadowNode::findNodeAtPoint(
269
274
}
270
275
271
276
auto newPoint = point - transformedFrame.origin -
272
- layoutableShadowNode->getContentOriginOffset ();
277
+ layoutableShadowNode->getContentOriginOffset (false );
273
278
274
279
auto sortedChildren = node->getChildren ();
275
280
std::stable_sort (
Original file line number Diff line number Diff line change @@ -122,8 +122,11 @@ class LayoutableShadowNode : public ShadowNode {
122
122
* Returns offset which is applied to children's origin in
123
123
* `LayoutableShadowNode::getRelativeLayoutMetrics` and
124
124
* `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.
125
128
*/
126
- virtual Point getContentOriginOffset () const ;
129
+ virtual Point getContentOriginOffset (bool includeTransform ) const ;
127
130
128
131
/*
129
132
* Sets layout metrics for the shadow node.
Original file line number Diff line number Diff line change @@ -76,7 +76,8 @@ class TestShadowNode final : public ConcreteViewShadowNode<
76
76
77
77
facebook::react::Point _contentOriginOffset{};
78
78
79
- facebook::react::Point getContentOriginOffset () const override {
79
+ facebook::react::Point getContentOriginOffset (
80
+ bool /* includeTransform*/ ) const override {
80
81
return _contentOriginOffset;
81
82
}
82
83
};
Original file line number Diff line number Diff line change @@ -357,7 +357,7 @@ DOMPoint getScrollPosition(
357
357
return DOMPoint{};
358
358
}
359
359
360
- auto scrollPosition = layoutableShadowNode->getContentOriginOffset ();
360
+ auto scrollPosition = layoutableShadowNode->getContentOriginOffset (false );
361
361
362
362
return DOMPoint{
363
363
.x = scrollPosition.x == 0 ? 0 : -scrollPosition.x ,
You can’t perform that action at this time.
0 commit comments