YGStyle: wrap all fields into accessors

Summary:
@public

In order to encapsulate property access on `YGStyle`, as a first measure we wrap all fields with accessors.

This will e.g. enable dynamic property storage and instrumentation in the future.

All accessors have a `const` version that allows direct access via `const&`. For mutation, bit fields are wrapped with a custom reference object.

This style allows for the least amount of changes in client code. Property access simply needs appended parens, eg `style.direction` becomes `style.direction`.

Reviewed By: shergin

Differential Revision: D14999096

fbshipit-source-id: fbf29f7ddab520513d4618f5e70094c4f6330b30
This commit is contained in:
David Aurelio
2019-04-23 08:08:51 -07:00
committed by Facebook Github Bot
parent e167642672
commit dee93017f7
7 changed files with 720 additions and 350 deletions

View File

@@ -9,43 +9,46 @@
// Yoga specific properties, not compatible with flexbox specification
bool operator==(const YGStyle& lhs, const YGStyle& rhs) {
bool areNonFloatValuesEqual = lhs.direction == rhs.direction &&
lhs.flexDirection == rhs.flexDirection &&
lhs.justifyContent == rhs.justifyContent &&
lhs.alignContent == rhs.alignContent &&
lhs.alignItems == rhs.alignItems && lhs.alignSelf == rhs.alignSelf &&
lhs.positionType == rhs.positionType && lhs.flexWrap == rhs.flexWrap &&
lhs.overflow == rhs.overflow && lhs.display == rhs.display &&
YGValueEqual(lhs.flexBasis, rhs.flexBasis) && lhs.margin == rhs.margin &&
lhs.position == rhs.position && lhs.padding == rhs.padding &&
lhs.border == rhs.border && lhs.dimensions == rhs.dimensions &&
lhs.minDimensions == rhs.minDimensions &&
lhs.maxDimensions == rhs.maxDimensions;
bool areNonFloatValuesEqual = lhs.direction() == rhs.direction() &&
lhs.flexDirection() == rhs.flexDirection() &&
lhs.justifyContent() == rhs.justifyContent() &&
lhs.alignContent() == rhs.alignContent() &&
lhs.alignItems() == rhs.alignItems() &&
lhs.alignSelf() == rhs.alignSelf() &&
lhs.positionType() == rhs.positionType() &&
lhs.flexWrap() == rhs.flexWrap() && lhs.overflow() == rhs.overflow() &&
lhs.display() == rhs.display() &&
YGValueEqual(lhs.flexBasis(), rhs.flexBasis()) &&
lhs.margin() == rhs.margin() && lhs.position() == rhs.position() &&
lhs.padding() == rhs.padding() && lhs.border() == rhs.border() &&
lhs.dimensions() == rhs.dimensions() &&
lhs.minDimensions() == rhs.minDimensions() &&
lhs.maxDimensions() == rhs.maxDimensions();
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flex.isUndefined() == rhs.flex.isUndefined();
if (areNonFloatValuesEqual && !lhs.flex.isUndefined() &&
!rhs.flex.isUndefined()) {
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex == rhs.flex;
lhs.flex().isUndefined() == rhs.flex().isUndefined();
if (areNonFloatValuesEqual && !lhs.flex().isUndefined() &&
!rhs.flex().isUndefined()) {
areNonFloatValuesEqual = areNonFloatValuesEqual && lhs.flex() == rhs.flex();
}
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flexGrow.isUndefined() == rhs.flexGrow.isUndefined();
if (areNonFloatValuesEqual && !lhs.flexGrow.isUndefined()) {
lhs.flexGrow().isUndefined() == rhs.flexGrow().isUndefined();
if (areNonFloatValuesEqual && !lhs.flexGrow().isUndefined()) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.flexGrow == rhs.flexGrow;
areNonFloatValuesEqual && lhs.flexGrow() == rhs.flexGrow();
}
areNonFloatValuesEqual = areNonFloatValuesEqual &&
lhs.flexShrink.isUndefined() == rhs.flexShrink.isUndefined();
if (areNonFloatValuesEqual && !rhs.flexShrink.isUndefined()) {
lhs.flexShrink().isUndefined() == rhs.flexShrink().isUndefined();
if (areNonFloatValuesEqual && !rhs.flexShrink().isUndefined()) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.flexShrink == rhs.flexShrink;
areNonFloatValuesEqual && lhs.flexShrink() == rhs.flexShrink();
}
if (!(lhs.aspectRatio.isUndefined() && rhs.aspectRatio.isUndefined())) {
if (!(lhs.aspectRatio().isUndefined() && rhs.aspectRatio().isUndefined())) {
areNonFloatValuesEqual =
areNonFloatValuesEqual && lhs.aspectRatio == rhs.aspectRatio;
areNonFloatValuesEqual && lhs.aspectRatio() == rhs.aspectRatio();
}
return areNonFloatValuesEqual;