From 5404bb13d473a38e65e6be8bf7dc56cb86ceb983 Mon Sep 17 00:00:00 2001 From: David Hart Date: Wed, 18 Jan 2017 09:14:33 -0800 Subject: [PATCH] Fix bugs introduced with YogaKit improvements Summary: I'm trying to fix some bugs I introduced in my latest PR, but while writing the Unit Tests for them, I saw a really weird behaviour. The following exact piece of code WORKS inside a Yoga C++ unit test, but fails from a Objective-C unit test. I had me completely confused and blocked me in my progression. Any ideas? ``` TEST(YogaTest, stupid_test) { const YGNodeRef node = YGNodeNew(); YGNodeStyleSetPosition(node, YGEdgeLeft, 1); ASSERT_FLOAT_EQ(1, YGNodeStyleGetPosition(node, YGEdgeLeft).value); ASSERT_EQ(YGUnitPixel, YGNodeStyleGetPosition(node, YGEdgeLeft).unit); YGNodeFree(node); } ``` ``` - (void)testPositionalPropertiesWork { YGNodeRef node = YGNodeNew(); YGNodeStyleSetPosition(node, YGEdgeLeft, 1); XCTAssertEqual(1, YGNodeStyleGetPosition(node, YGEdgeLeft).value); XCTAssertEqual(YGUnitPixel, YGNodeStyleGetPosition(node, YGEdgeLeft).unit); YGNodeFree(node); } ``` Closes https://github.com/facebook/yoga/pull/328 Reviewed By: dshahidehpour Differential Revision: D4421504 Pulled By: emilsjolander fbshipit-source-id: f59379edf70aee87a77cd1ad2986313cdfe71b94 --- YogaKit/Tests/YogaKitTests.m | 211 +++++++++++++++++- YogaKit/YGLayout+Private.h | 5 +- YogaKit/YGLayout.m | 203 +++++++++-------- .../YogaKitSample.xcodeproj/project.pbxproj | 119 +++++++++- 4 files changed, 443 insertions(+), 95 deletions(-) diff --git a/YogaKit/Tests/YogaKitTests.m b/YogaKit/Tests/YogaKitTests.m index 41b39925..0e3957aa 100644 --- a/YogaKit/Tests/YogaKitTests.m +++ b/YogaKit/Tests/YogaKitTests.m @@ -10,6 +10,8 @@ #import #import +#import +#import @interface YogaKitTests : XCTestCase @end @@ -50,7 +52,7 @@ #endif -- (void)testUsesYoga +- (void)testIsEnabled { UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; XCTAssertFalse(view.yoga.isEnabled); @@ -384,4 +386,211 @@ [container.yoga applyLayout]; } +- (void)testPositionalPropertiesWork +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + + view.yoga.left = 1; + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).value, 1); + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.left, 1); + + view.yoga.right = 2; + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).value, 2); + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.right, 2); + + view.yoga.top = 3; + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).value, 3); + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.top, 3); + + view.yoga.bottom = 4; + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).value, 4); + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.bottom, 4); + + view.yoga.start = 5; + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).value, 5); + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.start, 5); + + view.yoga.end = 6; + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).value, 6); + XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.end, 6); +} + +- (void)testMarginPropertiesWork +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + + view.yoga.margin = 1; + XCTAssertEqual(view.yoga.marginLeft, 1); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginRight, 1); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginStart, 1); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginEnd, 1); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginTop, 1); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginBottom, 1); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertTrue(isnan(view.yoga.marginHorizontal)); + XCTAssertTrue(isnan(view.yoga.marginVertical)); + XCTAssertTrue(isnan(view.yoga.margin)); + + view.yoga.marginHorizontal = 2; + XCTAssertEqual(view.yoga.marginLeft, 2); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginRight, 2); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginStart, 2); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginEnd, 2); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertTrue(isnan(view.yoga.marginHorizontal)); + + view.yoga.marginVertical = 3; + XCTAssertEqual(view.yoga.marginTop, 3); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginBottom, 3); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertTrue(isnan(view.yoga.marginVertical)); + + view.yoga.marginLeft = 4; + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 4); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginLeft, 4); + + view.yoga.marginRight = 5; + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).value, 5); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginRight, 5); + + view.yoga.marginTop = 6; + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).value, 6); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginTop, 6); + + view.yoga.marginBottom = 7; + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).value, 7); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginBottom, 7); + + view.yoga.marginStart = 8; + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).value, 8); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginStart, 8); + + view.yoga.marginEnd = 9; + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).value, 9); + XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.marginEnd, 9); +} + +- (void)testPaddingPropertiesWork +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + + view.yoga.padding = 1; + XCTAssertEqual(view.yoga.paddingLeft, 1); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingRight, 1); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingStart, 1); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingEnd, 1); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingTop, 1); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingBottom, 1); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertTrue(isnan(view.yoga.paddingHorizontal)); + XCTAssertTrue(isnan(view.yoga.paddingVertical)); + XCTAssertTrue(isnan(view.yoga.padding)); + + view.yoga.paddingHorizontal = 2; + XCTAssertEqual(view.yoga.paddingLeft, 2); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingRight, 2); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingStart, 2); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingEnd, 2); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertTrue(isnan(view.yoga.paddingHorizontal)); + + view.yoga.paddingVertical = 3; + XCTAssertEqual(view.yoga.paddingTop, 3); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingBottom, 3); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertTrue(isnan(view.yoga.paddingVertical)); + + view.yoga.paddingLeft = 4; + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 4); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingLeft, 4); + + view.yoga.paddingRight = 5; + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).value, 5); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingRight, 5); + + view.yoga.paddingTop = 6; + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).value, 6); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingTop, 6); + + view.yoga.paddingBottom = 7; + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).value, 7); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingBottom, 7); + + view.yoga.paddingStart = 8; + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).value, 8); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingStart, 8); + + view.yoga.paddingEnd = 9; + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).value, 9); + XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); + XCTAssertEqual(view.yoga.paddingEnd, 9); +} + +- (void)testBorderWidthPropertiesWork +{ + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + + view.yoga.borderWidth = 1; + XCTAssertEqual(view.yoga.borderLeftWidth, 1); + XCTAssertEqual(view.yoga.borderRightWidth, 1); + XCTAssertEqual(view.yoga.borderStartWidth, 1); + XCTAssertEqual(view.yoga.borderEndWidth, 1); + XCTAssertEqual(view.yoga.borderTopWidth, 1); + XCTAssertEqual(view.yoga.borderBottomWidth, 1); + XCTAssertTrue(isnan(view.yoga.borderWidth)); + + view.yoga.borderLeftWidth = 2; + XCTAssertEqual(view.yoga.borderLeftWidth, 2); + + view.yoga.borderRightWidth = 3; + XCTAssertEqual(view.yoga.borderRightWidth, 3); + + view.yoga.borderTopWidth = 4; + XCTAssertEqual(view.yoga.borderTopWidth, 4); + + view.yoga.borderBottomWidth = 5; + XCTAssertEqual(view.yoga.borderBottomWidth, 5); + + view.yoga.borderStartWidth = 6; + XCTAssertEqual(view.yoga.borderStartWidth, 6); + + view.yoga.borderEndWidth = 7; + XCTAssertEqual(view.yoga.borderEndWidth, 7); +} + @end diff --git a/YogaKit/YGLayout+Private.h b/YogaKit/YGLayout+Private.h index 15232b7e..7113b4c5 100644 --- a/YogaKit/YGLayout+Private.h +++ b/YogaKit/YGLayout+Private.h @@ -8,8 +8,11 @@ */ #import "YGLayout.h" +#import -@interface YGLayout (Private) +@interface YGLayout () + +@property (nonatomic, assign, readonly) YGNodeRef node; - (instancetype)initWithView:(UIView *)view; diff --git a/YogaKit/YGLayout.m b/YogaKit/YGLayout.m index d6a2baf0..23cee161 100644 --- a/YogaKit/YGLayout.m +++ b/YogaKit/YGLayout.m @@ -9,75 +9,99 @@ #import "YGLayout+Private.h" #import "UIView+Yoga.h" -#import -#define YG_STYLE_PROPERTY_IMPL(type, lowercased_name, capitalized_name) \ -- (type)lowercased_name \ -{ \ - return YGNodeStyleGet##capitalized_name(self.node); \ -} \ - \ -- (void)set##capitalized_name:(type)lowercased_name \ -{ \ - YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \ +#define YG_PROPERTY(type, lowercased_name, capitalized_name) \ +- (type)lowercased_name \ +{ \ + return YGNodeStyleGet##capitalized_name(self.node); \ +} \ + \ +- (void)set##capitalized_name:(type)lowercased_name \ +{ \ + YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \ } -#define YG_STYLE_EDGE_PROPERTY_IMPL(lowercased_name, capitalized_name, property, edge) \ -- (CGFloat)lowercased_name { \ - return YGNodeStyleGet##property(self.node, edge); \ -} \ - \ -- (void)set##capitalized_name:(CGFloat)lowercased_name { \ - YGNodeStyleSet##property(self.node, edge, lowercased_name); \ +#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \ +- (CGFloat)lowercased_name \ +{ \ + YGValue value = YGNodeStyleGet##capitalized_name(self.node); \ + if (value.unit == YGUnitPixel) { \ + return value.value; \ + } else { \ + return YGUndefined; \ + } \ +} \ + \ +- (void)set##capitalized_name:(CGFloat)lowercased_name \ +{ \ + YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \ } -#define YG_STYLE_VALUE_PROPERTY_IMPL(lowercased_name, capitalized_name) \ -- (CGFloat)lowercased_name \ -{ \ - YGValue value = YGNodeStyleGet##capitalized_name(self.node); \ - if (value.unit == YGUnitPixel) { \ - return value.value; \ - } else { \ - return YGUndefined; \ - } \ -} \ - \ -- (void)set##capitalized_name:(CGFloat)lowercased_name \ -{ \ - YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \ +#define YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \ +- (CGFloat)lowercased_name \ +{ \ + return YGNodeStyleGet##property(self.node, edge); \ } -#define YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, edge, edge_suffix) \ -- (CGFloat)lowercased_name##edge_suffix \ -{ \ - YGValue value = YGNodeStyleGet##capitalized_name(self.node, edge); \ - if (value.unit == YGUnitPixel) { \ - return value.value; \ - } else { \ - return YGUndefined; \ - } \ -} \ - \ -- (void)set##capitalized_name##edge_suffix:(CGFloat)lowercased_name \ -{ \ - YGNodeStyleSet##capitalized_name(self.node, edge, lowercased_name); \ +#define YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \ +- (CGFloat)lowercased_name \ +{ \ + return YGUndefined; \ } -#define YG_STYLE_ALL_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeLeft, Left) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeTop, Top) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeRight, Right) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeBottom, Bottom) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeStart, Start) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeEnd, End) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeHorizontal, Horizontal) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeVertical, Vertical) \ -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeAll, ) +#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \ +- (void)set##capitalized_name:(CGFloat)lowercased_name \ +{ \ + YGNodeStyleSet##property(self.node, edge, lowercased_name); \ +} + +#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ +YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \ +YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) + +#define YG_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ +YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \ +YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) + +#define YG_VALUE_EDGE_PROPERTY_GETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \ +- (CGFloat)objc_lowercased_name \ +{ \ + YGValue value = YGNodeStyleGet##c_name(self.node, edge); \ + if (value.unit == YGUnitPixel) { \ + return value.value; \ + } else { \ + return YGUndefined; \ + } \ +} + +#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \ +- (void)set##objc_capitalized_name:(CGFloat)objc_lowercased_name \ +{ \ + YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name); \ +} + +#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ +YG_VALUE_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \ +YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) + +#define YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ +YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \ +YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) + +#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \ +YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \ +YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \ +YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \ +YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll) @interface YGLayout () @property (nonatomic, weak, readonly) UIView *view; -@property (nonatomic, assign, readonly) YGNodeRef node; @end @@ -85,6 +109,7 @@ YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeAll, ) @synthesize isEnabled=_isEnabled; @synthesize isIncludedInLayout=_isIncludedInLayout; +@synthesize node=_node; + (void)initialize { @@ -148,43 +173,43 @@ YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(lowercased_name, capitalized_name, YGEdgeAll, ) YGNodeStyleSetPositionType(self.node, position); } -YG_STYLE_PROPERTY_IMPL(YGDirection, direction, Direction) -YG_STYLE_PROPERTY_IMPL(YGFlexDirection, flexDirection, FlexDirection) -YG_STYLE_PROPERTY_IMPL(YGJustify, justifyContent, JustifyContent) -YG_STYLE_PROPERTY_IMPL(YGAlign, alignContent, AlignContent) -YG_STYLE_PROPERTY_IMPL(YGAlign, alignItems, AlignItems) -YG_STYLE_PROPERTY_IMPL(YGAlign, alignSelf, AlignSelf) -YG_STYLE_PROPERTY_IMPL(YGWrap, flexWrap, FlexWrap) -YG_STYLE_PROPERTY_IMPL(YGOverflow, overflow, Overflow) +YG_PROPERTY(YGDirection, direction, Direction) +YG_PROPERTY(YGFlexDirection, flexDirection, FlexDirection) +YG_PROPERTY(YGJustify, justifyContent, JustifyContent) +YG_PROPERTY(YGAlign, alignContent, AlignContent) +YG_PROPERTY(YGAlign, alignItems, AlignItems) +YG_PROPERTY(YGAlign, alignSelf, AlignSelf) +YG_PROPERTY(YGWrap, flexWrap, FlexWrap) +YG_PROPERTY(YGOverflow, overflow, Overflow) -YG_STYLE_PROPERTY_IMPL(CGFloat, flexGrow, FlexGrow) -YG_STYLE_PROPERTY_IMPL(CGFloat, flexShrink, FlexShrink) -YG_STYLE_VALUE_PROPERTY_IMPL(flexBasis, FlexBasis) +YG_PROPERTY(CGFloat, flexGrow, FlexGrow) +YG_PROPERTY(CGFloat, flexShrink, FlexShrink) +YG_VALUE_PROPERTY(flexBasis, FlexBasis) -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeLeft, Left) -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeTop, Top) -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeRight, Right) -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeBottom, Bottom) -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeStart, Start) -YG_STYLE_EDGE_PROPERTY_UNIT_IMPL(position, Position, YGEdgeEnd, End) -YG_STYLE_ALL_EDGE_PROPERTY_UNIT_IMPL(margin, Margin) -YG_STYLE_ALL_EDGE_PROPERTY_UNIT_IMPL(padding, Padding) +YG_VALUE_EDGE_PROPERTY(left, Left, Position, YGEdgeLeft) +YG_VALUE_EDGE_PROPERTY(top, Top, Position, YGEdgeTop) +YG_VALUE_EDGE_PROPERTY(right, Right, Position, YGEdgeRight) +YG_VALUE_EDGE_PROPERTY(bottom, Bottom, Position, YGEdgeBottom) +YG_VALUE_EDGE_PROPERTY(start, Start, Position, YGEdgeStart) +YG_VALUE_EDGE_PROPERTY(end, End, Position, YGEdgeEnd) +YG_VALUE_EDGES_PROPERTIES(margin, Margin) +YG_VALUE_EDGES_PROPERTIES(padding, Padding) -YG_STYLE_EDGE_PROPERTY_IMPL(borderLeftWidth, BorderLeftWidth, Border, YGEdgeLeft) -YG_STYLE_EDGE_PROPERTY_IMPL(borderTopWidth, BorderTopWidth, Border, YGEdgeTop) -YG_STYLE_EDGE_PROPERTY_IMPL(borderRightWidth, BorderRightWidth, Border, YGEdgeRight) -YG_STYLE_EDGE_PROPERTY_IMPL(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom) -YG_STYLE_EDGE_PROPERTY_IMPL(borderStartWidth, BorderStartWidth, Border, YGEdgeStart) -YG_STYLE_EDGE_PROPERTY_IMPL(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd) -YG_STYLE_EDGE_PROPERTY_IMPL(borderWidth, BorderWidth, Border, YGEdgeAll) +YG_EDGE_PROPERTY(borderLeftWidth, BorderLeftWidth, Border, YGEdgeLeft) +YG_EDGE_PROPERTY(borderTopWidth, BorderTopWidth, Border, YGEdgeTop) +YG_EDGE_PROPERTY(borderRightWidth, BorderRightWidth, Border, YGEdgeRight) +YG_EDGE_PROPERTY(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom) +YG_EDGE_PROPERTY(borderStartWidth, BorderStartWidth, Border, YGEdgeStart) +YG_EDGE_PROPERTY(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd) +YG_SHORTHAND_EDGE_PROPERTY(borderWidth, BorderWidth, Border, YGEdgeAll) -YG_STYLE_VALUE_PROPERTY_IMPL(width, Width) -YG_STYLE_VALUE_PROPERTY_IMPL(height, Height) -YG_STYLE_VALUE_PROPERTY_IMPL(minWidth, MinWidth) -YG_STYLE_VALUE_PROPERTY_IMPL(minHeight, MinHeight) -YG_STYLE_VALUE_PROPERTY_IMPL(maxWidth, MaxWidth) -YG_STYLE_VALUE_PROPERTY_IMPL(maxHeight, MaxHeight) -YG_STYLE_PROPERTY_IMPL(CGFloat, aspectRatio, AspectRatio) +YG_VALUE_PROPERTY(width, Width) +YG_VALUE_PROPERTY(height, Height) +YG_VALUE_PROPERTY(minWidth, MinWidth) +YG_VALUE_PROPERTY(minHeight, MinHeight) +YG_VALUE_PROPERTY(maxWidth, MaxWidth) +YG_VALUE_PROPERTY(maxHeight, MaxHeight) +YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) #pragma mark - Layout and Sizing diff --git a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj index eed408a6..11afe6ff 100644 --- a/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj +++ b/YogaKit/YogaKitSample/YogaKitSample.xcodeproj/project.pbxproj @@ -21,10 +21,20 @@ 13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D841DF87D1E00E7C260 /* UIKit.framework */; }; 13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D861DF87D2400E7C260 /* Foundation.framework */; }; 638A94431E1EF5D000A726AD /* YGLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 638A94411E1EF5D000A726AD /* YGLayout.m */; }; - 638A94451E1EF8A900A726AD /* YGValue.h in yoga */ = {isa = PBXBuildFile; fileRef = 638A94441E1EF89C00A726AD /* YGValue.h */; }; 638A94481E1F06D100A726AD /* SwiftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638A94471E1F06D100A726AD /* SwiftViewController.swift */; }; + 638A945A1E215CD400A726AD /* YogaKitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 638A94591E215CD400A726AD /* YogaKitTests.m */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 638A94541E215CC800A726AD /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 13687D3B1DF8748300E7C260 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 13687D421DF8748300E7C260; + remoteInfo = YogaKitSample; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXCopyFilesBuildPhase section */ 13687D771DF878A000E7C260 /* yoga */ = { isa = PBXCopyFilesBuildPhase; @@ -32,7 +42,6 @@ dstPath = include/yoga; dstSubfolderSpec = 16; files = ( - 638A94451E1EF8A900A726AD /* YGValue.h in yoga */, 13687D781DF878C600E7C260 /* YGEnums.h in yoga */, 13687D791DF878C600E7C260 /* YGMacros.h in yoga */, 13687D7A1DF878C600E7C260 /* Yoga.h in yoga */, @@ -75,9 +84,11 @@ 638A94401E1EF5D000A726AD /* YGLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGLayout.h; sourceTree = ""; }; 638A94411E1EF5D000A726AD /* YGLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YGLayout.m; sourceTree = ""; }; 638A94421E1EF5D000A726AD /* YGLayout+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YGLayout+Private.h"; sourceTree = ""; }; - 638A94441E1EF89C00A726AD /* YGValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YGValue.h; sourceTree = ""; }; 638A94461E1F06D100A726AD /* YogaKitSample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "YogaKitSample-Bridging-Header.h"; sourceTree = ""; }; 638A94471E1F06D100A726AD /* SwiftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftViewController.swift; sourceTree = ""; }; + 638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YogaKitSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 638A94531E215CC800A726AD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 638A94591E215CD400A726AD /* YogaKitTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = YogaKitTests.m; path = ../../Tests/YogaKitTests.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -90,6 +101,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 638A944C1E215CC800A726AD /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -99,6 +117,7 @@ 13687D5D1DF8778F00E7C260 /* yoga */, 13687D641DF8778F00E7C260 /* YogaKit */, 13687D451DF8748400E7C260 /* YogaKitSample */, + 638A94501E215CC800A726AD /* YogaKitSampleTests */, 13687D441DF8748400E7C260 /* Products */, 13687D831DF87D1E00E7C260 /* Frameworks */, ); @@ -108,6 +127,7 @@ isa = PBXGroup; children = ( 13687D431DF8748400E7C260 /* YogaKitSample.app */, + 638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */, ); name = Products; sourceTree = ""; @@ -139,7 +159,6 @@ 13687D5D1DF8778F00E7C260 /* yoga */ = { isa = PBXGroup; children = ( - 638A94441E1EF89C00A726AD /* YGValue.h */, 13687D5E1DF8778F00E7C260 /* YGEnums.h */, 13687D5F1DF8778F00E7C260 /* YGMacros.h */, 13687D601DF8778F00E7C260 /* YGNodeList.c */, @@ -173,6 +192,15 @@ name = Frameworks; sourceTree = ""; }; + 638A94501E215CC800A726AD /* YogaKitSampleTests */ = { + isa = PBXGroup; + children = ( + 638A94591E215CD400A726AD /* YogaKitTests.m */, + 638A94531E215CC800A726AD /* Info.plist */, + ); + path = YogaKitSampleTests; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -195,6 +223,24 @@ productReference = 13687D431DF8748400E7C260 /* YogaKitSample.app */; productType = "com.apple.product-type.application"; }; + 638A944E1E215CC800A726AD /* YogaKitSampleTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 638A94561E215CC800A726AD /* Build configuration list for PBXNativeTarget "YogaKitSampleTests" */; + buildPhases = ( + 638A944B1E215CC800A726AD /* Sources */, + 638A944C1E215CC800A726AD /* Frameworks */, + 638A944D1E215CC800A726AD /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 638A94551E215CC800A726AD /* PBXTargetDependency */, + ); + name = YogaKitSampleTests; + productName = YogaKitSampleTests; + productReference = 638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -209,6 +255,11 @@ LastSwiftMigration = 0820; ProvisioningStyle = Automatic; }; + 638A944E1E215CC800A726AD = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + TestTargetID = 13687D421DF8748300E7C260; + }; }; }; buildConfigurationList = 13687D3E1DF8748300E7C260 /* Build configuration list for PBXProject "YogaKitSample" */; @@ -225,6 +276,7 @@ projectRoot = ""; targets = ( 13687D421DF8748300E7C260 /* YogaKitSample */, + 638A944E1E215CC800A726AD /* YogaKitSampleTests */, ); }; /* End PBXProject section */ @@ -238,6 +290,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 638A944D1E215CC800A726AD /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -256,8 +315,24 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 638A944B1E215CC800A726AD /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 638A945A1E215CD400A726AD /* YogaKitTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 638A94551E215CC800A726AD /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 13687D421DF8748300E7C260 /* YogaKitSample */; + targetProxy = 638A94541E215CC800A726AD /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin XCBuildConfiguration section */ 13687D581DF8748400E7C260 /* Debug */ = { isa = XCBuildConfiguration; @@ -378,6 +453,34 @@ }; name = Release; }; + 638A94571E215CC800A726AD /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + INFOPLIST_FILE = YogaKitSampleTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSampleTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YogaKitSample.app/YogaKitSample"; + }; + name = Debug; + }; + 638A94581E215CC800A726AD /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + INFOPLIST_FILE = YogaKitSampleTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSampleTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YogaKitSample.app/YogaKitSample"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -399,6 +502,14 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 638A94561E215CC800A726AD /* Build configuration list for PBXNativeTarget "YogaKitSampleTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 638A94571E215CC800A726AD /* Debug */, + 638A94581E215CC800A726AD /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = 13687D3B1DF8748300E7C260 /* Project object */;