Skip to content

Commit d38c756

Browse files
paradowstackmeta-codesync[bot]
authored andcommitted
feat: add viewport size to LayoutContext class (#56209)
Summary: Add viewport size to `LayoutContext` and wire it through Android and iOS layout setup so viewport dimensions are available during layout. This was extracted from the larger `calc()` work in PR #56162. ## Changelog: [GENERAL] [ADDED] - Add viewport size to LayoutContext Pull Request resolved: #56209 Test Plan: - This change is limited to internal layout plumbing in React Native core and does not alter external behavior on its own. - Validation for the actual `calc()` use cases will be covered in the follow-up work that consumes this plumbing. Reviewed By: christophpurrer Differential Revision: D98004758 Pulled By: NickGerleman fbshipit-source-id: 3fd6257b2c280442a41308af3e6eff30b51a3397
1 parent a92bea8 commit d38c756

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ - (void)setMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize viewp
214214
if (!isnan(viewportOffset.x) && !isnan(viewportOffset.y)) {
215215
layoutContext.viewportOffset = RCTPointFromCGPoint(viewportOffset);
216216
}
217+
layoutContext.viewportSize = layoutConstraints.maximumSize;
217218

218219
_surfaceHandler->constraintLayout(layoutConstraints, layoutContext);
219220
}
@@ -236,6 +237,8 @@ - (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximu
236237
layoutConstraints.minimumSize = RCTSizeFromCGSize(minimumSize);
237238
layoutConstraints.maximumSize = RCTSizeFromCGSize(maximumSize);
238239

240+
layoutContext.viewportSize = layoutConstraints.maximumSize;
241+
239242
return RCTCGSizeFromSize(_surfaceHandler->measure(layoutConstraints, layoutContext));
240243
}
241244

packages/react-native/ReactAndroid/src/main/jni/react/fabric/SurfaceHandlerBinding.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void SurfaceHandlerBinding::setLayoutConstraints(
6060
context.swapLeftAndRightInRTL = (doLeftAndRightSwapInRTL != 0u);
6161
context.pointScaleFactor = pixelDensity;
6262
context.viewportOffset = {.x = offsetX, .y = offsetY};
63+
context.viewportSize = {.width = maxWidth, .height = maxHeight};
6364
context.fontSizeMultiplier = fontScale;
6465

6566
surfaceHandler_.constraintLayout(constraints, context);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ struct LayoutContext {
5959
* If React Native takes up entire screen, it will be {0, 0}.
6060
*/
6161
Point viewportOffset{};
62+
63+
/*
64+
* Viewport size is size of the React Native's root view.
65+
*/
66+
Size viewportSize{};
6267
};
6368

6469
inline bool operator==(const LayoutContext &lhs, const LayoutContext &rhs)
@@ -68,13 +73,15 @@ inline bool operator==(const LayoutContext &lhs, const LayoutContext &rhs)
6873
lhs.affectedNodes,
6974
lhs.swapLeftAndRightInRTL,
7075
lhs.fontSizeMultiplier,
71-
lhs.viewportOffset) ==
76+
lhs.viewportOffset,
77+
lhs.viewportSize) ==
7278
std::tie(
7379
rhs.pointScaleFactor,
7480
rhs.affectedNodes,
7581
rhs.swapLeftAndRightInRTL,
7682
rhs.fontSizeMultiplier,
77-
rhs.viewportOffset);
83+
rhs.viewportOffset,
84+
rhs.viewportSize);
7885
}
7986

8087
} // namespace facebook::react

0 commit comments

Comments
 (0)