mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add position type to LayoutMetrics (#41819)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41819 This will be needed in order to access the position type while implementing offsetLeft/Top, which needs to know if a node is static or not to get the proper offset. This is simply making the position type available to be read from LayoutMetrics. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D51412428 fbshipit-source-id: b101d8065ddfe0322f77f64d1de0f9ead3975c60
This commit is contained in:
committed by
Facebook GitHub Bot
parent
37c7f8433f
commit
3fb47c5411
@@ -98,6 +98,18 @@ inline std::optional<Float> optionalFloatFromYogaValue(
|
||||
}
|
||||
}
|
||||
|
||||
static inline PositionType positionTypeFromYogaPositionType(
|
||||
yoga::PositionType positionType) {
|
||||
switch (positionType) {
|
||||
case yoga::PositionType::Static:
|
||||
return PositionType::Static;
|
||||
case yoga::PositionType::Relative:
|
||||
return PositionType::Relative;
|
||||
case yoga::PositionType::Absolute:
|
||||
return PositionType::Absolute;
|
||||
}
|
||||
}
|
||||
|
||||
inline LayoutMetrics layoutMetricsFromYogaNode(yoga::Node& yogaNode) {
|
||||
auto layoutMetrics = LayoutMetrics{};
|
||||
|
||||
@@ -129,6 +141,9 @@ inline LayoutMetrics layoutMetricsFromYogaNode(yoga::Node& yogaNode) {
|
||||
yogaNode.getStyle().display() == yoga::Display::None ? DisplayType::None
|
||||
: DisplayType::Flex;
|
||||
|
||||
layoutMetrics.positionType =
|
||||
positionTypeFromYogaPositionType(yogaNode.getStyle().positionType());
|
||||
|
||||
layoutMetrics.layoutDirection =
|
||||
YGNodeLayoutGetDirection(&yogaNode) == YGDirectionRTL
|
||||
? LayoutDirection::RightToLeft
|
||||
|
||||
@@ -29,6 +29,8 @@ struct LayoutMetrics {
|
||||
EdgeInsets borderWidth{0};
|
||||
// See `DisplayType` for all possible options.
|
||||
DisplayType displayType{DisplayType::Flex};
|
||||
// See `PositionType` for all possible options.
|
||||
PositionType positionType{PositionType::Static};
|
||||
// See `LayoutDirection` for all possible options.
|
||||
LayoutDirection layoutDirection{LayoutDirection::Undefined};
|
||||
// Whether React Native treated cardinal directions as flow-relative
|
||||
|
||||
@@ -22,6 +22,12 @@ enum class DisplayType {
|
||||
Inline = 2,
|
||||
};
|
||||
|
||||
enum class PositionType {
|
||||
Static = 0,
|
||||
Relative = 1,
|
||||
Absolute = 2,
|
||||
};
|
||||
|
||||
/*
|
||||
* User interface layout direction.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user