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) {
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
Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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};
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments