diff --git a/YogaKit/UIView+Yoga.h b/YogaKit/UIView+Yoga.h deleted file mode 100644 index 386416b2..00000000 --- a/YogaKit/UIView+Yoga.h +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - -#import -#import - -@interface UIView (Yoga) - -/** - The property that decides if we should include this view when calculating layout. Defaults to YES. - */ -@property (nonatomic, readwrite, assign, setter=yg_setIncludeInLayout:) BOOL yg_includeInLayout; - -/** - The property that decides during layout/sizing whether or not yg_* properties should be applied. Defaults to NO. - */ -@property (nonatomic, readwrite, assign, setter=yg_setUsesYoga:) BOOL yg_usesYoga; - -- (void)yg_setDirection:(YGDirection)direction; -- (void)yg_setFlexDirection:(YGFlexDirection)flexDirection; -- (void)yg_setJustifyContent:(YGJustify)justifyContent; -- (void)yg_setAlignContent:(YGAlign)alignContent; -- (void)yg_setAlignItems:(YGAlign)alignItems; -- (void)yg_setAlignSelf:(YGAlign)alignSelf; -- (void)yg_setPositionType:(YGPositionType)positionType; -- (void)yg_setFlexWrap:(YGWrap)flexWrap; - -- (void)yg_setFlexGrow:(CGFloat)flexGrow; -- (void)yg_setFlexShrink:(CGFloat)flexShrink; -- (void)yg_setFlexBasis:(CGFloat)flexBasis; - -- (void)yg_setPosition:(CGFloat)position forEdge:(YGEdge)edge; -- (void)yg_setMargin:(CGFloat)margin forEdge:(YGEdge)edge; -- (void)yg_setPadding:(CGFloat)padding forEdge:(YGEdge)edge; - -- (void)yg_setWidth:(CGFloat)width; -- (void)yg_setHeight:(CGFloat)height; -- (void)yg_setMinWidth:(CGFloat)minWidth; -- (void)yg_setMinHeight:(CGFloat)minHeight; -- (void)yg_setMaxWidth:(CGFloat)maxWidth; -- (void)yg_setMaxHeight:(CGFloat)maxHeight; - -// Yoga specific properties, not compatible with flexbox specification -- (void)yg_setAspectRatio:(CGFloat)aspectRatio; - -/** - Get the resolved direction of this node. This won't be YGDirectionInherit - */ -- (YGDirection)yg_resolvedDirection; - -/** - Perform a layout calculation and update the frames of the views in the hierarchy with the results - */ -- (void)yg_applyLayout; - -/** - Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; - */ -- (CGSize)yg_intrinsicSize; - -/** - Returns the number of children that are using Flexbox. - */ -- (NSUInteger)yg_numberOfChildren; - -@end diff --git a/YogaKit/UIView+YogaKit.h b/YogaKit/UIView+YogaKit.h new file mode 100644 index 00000000..08fc4bd0 --- /dev/null +++ b/YogaKit/UIView+YogaKit.h @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import +#import "YKEnums.h" + +@interface UIView (YogaKit) + +/** + The property that decides if we should include this view when calculating layout. Defaults to YES. + */ +@property (nonatomic, readwrite, assign, setter=yk_setIncludeInLayout:) BOOL yk_includeInLayout; + +/** + The property that decides during layout/sizing whether or not yk_* properties should be applied. Defaults to NO. + */ +@property (nonatomic, readwrite, assign, setter=yk_setUsesYoga:) BOOL yk_usesYoga; + +- (void)yk_setDirection:(YKDirection)direction; +- (void)yk_setFlexDirection:(YKFlexDirection)flexDirection; +- (void)yk_setJustifyContent:(YKJustify)justifyContent; +- (void)yk_setAlignContent:(YKAlign)alignContent; +- (void)yk_setAlignItems:(YKAlign)alignItems; +- (void)yk_setAlignSelf:(YKAlign)alignSelf; +- (void)yk_setPositionType:(YKPositionType)positionType; +- (void)yk_setFlexWrap:(YKWrap)flexWrap; + +- (void)yk_setFlexGrow:(CGFloat)flexGrow; +- (void)yk_setFlexShrink:(CGFloat)flexShrink; +- (void)yk_setFlexBasis:(CGFloat)flexBasis; + +- (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge; +- (void)yk_setMargin:(CGFloat)margin forEdge:(YKEdge)edge; +- (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge; + +- (void)yk_setWidth:(CGFloat)width; +- (void)yk_setHeight:(CGFloat)height; +- (void)yk_setMinWidth:(CGFloat)minWidth; +- (void)yk_setMinHeight:(CGFloat)minHeight; +- (void)yk_setMaxWidth:(CGFloat)maxWidth; +- (void)yk_setMaxHeight:(CGFloat)maxHeight; + +// Yoga specific properties, not compatible with flexbox specification +- (void)yk_setAspectRatio:(CGFloat)aspectRatio; + +/** + Get the resolved direction of this node. This won't be YGDirectionInherit + */ +- (YKDirection)yk_resolvedDirection; + +/** + Perform a layout calculation and update the frames of the views in the hierarchy with the results + */ +- (void)yk_applyLayout; + +/** + Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; + */ +- (CGSize)yk_intrinsicSize; + +/** + Returns the number of children that are using Flexbox. + */ +- (NSUInteger)yk_numberOfChildren; + +@end diff --git a/YogaKit/UIView+Yoga.m b/YogaKit/UIView+YogaKit.m similarity index 62% rename from YogaKit/UIView+Yoga.m rename to YogaKit/UIView+YogaKit.m index 241ad33e..46239f8f 100644 --- a/YogaKit/UIView+Yoga.m +++ b/YogaKit/UIView+YogaKit.m @@ -7,8 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import "UIView+Yoga.h" - +#import +#import #import @interface YGNodeBridge : NSObject @@ -37,164 +37,164 @@ } @end -@implementation UIView (Yoga) +@implementation UIView (YogaKit) -- (BOOL)yg_usesYoga +- (BOOL)yk_usesYoga { - NSNumber *usesYoga = objc_getAssociatedObject(self, @selector(yg_usesYoga)); + NSNumber *usesYoga = objc_getAssociatedObject(self, @selector(yk_usesYoga)); return [usesYoga boolValue]; } -- (BOOL)yg_includeInLayout +- (BOOL)yk_includeInLayout { - NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(yg_includeInLayout)); + NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(yk_includeInLayout)); return (includeInLayout != nil) ? [includeInLayout boolValue] : YES; } -- (NSUInteger)yg_numberOfChildren +- (NSUInteger)yk_numberOfChildren { return YGNodeGetChildCount([self ygNode]); } #pragma mark - Setters -- (void)yg_setIncludeInLayout:(BOOL)includeInLayout +- (void)yk_setIncludeInLayout:(BOOL)includeInLayout { objc_setAssociatedObject( self, - @selector(yg_includeInLayout), + @selector(yk_includeInLayout), @(includeInLayout), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (void)yg_setUsesYoga:(BOOL)enabled +- (void)yk_setUsesYoga:(BOOL)enabled { objc_setAssociatedObject( self, - @selector(yg_usesYoga), + @selector(yk_usesYoga), @(enabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC); } -- (void)yg_setDirection:(YGDirection)direction +- (void)yk_setDirection:(YKDirection)direction { - YGNodeStyleSetDirection([self ygNode], direction); + YGNodeStyleSetDirection([self ygNode], (YGDirection)direction); } -- (void)yg_setFlexDirection:(YGFlexDirection)flexDirection +- (void)yk_setFlexDirection:(YKFlexDirection)flexDirection { - YGNodeStyleSetFlexDirection([self ygNode], flexDirection); + YGNodeStyleSetFlexDirection([self ygNode], (YGFlexDirection)flexDirection); } -- (void)yg_setJustifyContent:(YGJustify)justifyContent +- (void)yk_setJustifyContent:(YKJustify)justifyContent { - YGNodeStyleSetJustifyContent([self ygNode], justifyContent); + YGNodeStyleSetJustifyContent([self ygNode], (YGJustify)justifyContent); } -- (void)yg_setAlignContent:(YGAlign)alignContent +- (void)yk_setAlignContent:(YKAlign)alignContent { - YGNodeStyleSetAlignContent([self ygNode], alignContent); + YGNodeStyleSetAlignContent([self ygNode], (YGAlign)alignContent); } -- (void)yg_setAlignItems:(YGAlign)alignItems +- (void)yk_setAlignItems:(YKAlign)alignItems { - YGNodeStyleSetAlignItems([self ygNode], alignItems); + YGNodeStyleSetAlignItems([self ygNode], (YGAlign)alignItems); } -- (void)yg_setAlignSelf:(YGAlign)alignSelf +- (void)yk_setAlignSelf:(YKAlign)alignSelf { - YGNodeStyleSetAlignSelf([self ygNode], alignSelf); + YGNodeStyleSetAlignSelf([self ygNode], (YGAlign)alignSelf); } -- (void)yg_setPositionType:(YGPositionType)positionType +- (void)yk_setPositionType:(YKPositionType)positionType { - YGNodeStyleSetPositionType([self ygNode], positionType); + YGNodeStyleSetPositionType([self ygNode], (YGPositionType)positionType); } -- (void)yg_setFlexWrap:(YGWrap)flexWrap +- (void)yk_setFlexWrap:(YKWrap)flexWrap { - YGNodeStyleSetFlexWrap([self ygNode], flexWrap); + YGNodeStyleSetFlexWrap([self ygNode], (YGWrap)flexWrap); } -- (void)yg_setFlexGrow:(CGFloat)flexGrow +- (void)yk_setFlexGrow:(CGFloat)flexGrow { YGNodeStyleSetFlexGrow([self ygNode], flexGrow); } -- (void)yg_setFlexShrink:(CGFloat)flexShrink +- (void)yk_setFlexShrink:(CGFloat)flexShrink { YGNodeStyleSetFlexShrink([self ygNode], flexShrink); } -- (void)yg_setFlexBasis:(CGFloat)flexBasis +- (void)yk_setFlexBasis:(CGFloat)flexBasis { YGNodeStyleSetFlexBasis([self ygNode], flexBasis); } -- (void)yg_setPosition:(CGFloat)position forEdge:(YGEdge)edge +- (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge { - YGNodeStyleSetPosition([self ygNode], edge, position); + YGNodeStyleSetPosition([self ygNode], (YGEdge)edge, position); } -- (void)yg_setMargin:(CGFloat)margin forEdge:(YGEdge)edge +- (void)yk_setMargin:(CGFloat)margin forEdge:(YKEdge)edge { - YGNodeStyleSetMargin([self ygNode], edge, margin); + YGNodeStyleSetMargin([self ygNode], (YGEdge)edge, margin); } -- (void)yg_setPadding:(CGFloat)padding forEdge:(YGEdge)edge +- (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge { - YGNodeStyleSetPadding([self ygNode], edge, padding); + YGNodeStyleSetPadding([self ygNode], (YGEdge)edge, padding); } -- (void)yg_setWidth:(CGFloat)width +- (void)yk_setWidth:(CGFloat)width { YGNodeStyleSetWidth([self ygNode], width); } -- (void)yg_setHeight:(CGFloat)height +- (void)yk_setHeight:(CGFloat)height { YGNodeStyleSetHeight([self ygNode], height); } -- (void)yg_setMinWidth:(CGFloat)minWidth +- (void)yk_setMinWidth:(CGFloat)minWidth { YGNodeStyleSetMinWidth([self ygNode], minWidth); } -- (void)yg_setMinHeight:(CGFloat)minHeight +- (void)yk_setMinHeight:(CGFloat)minHeight { YGNodeStyleSetMinHeight([self ygNode], minHeight); } -- (void)yg_setMaxWidth:(CGFloat)maxWidth +- (void)yk_setMaxWidth:(CGFloat)maxWidth { YGNodeStyleSetMaxWidth([self ygNode], maxWidth); } -- (void)yg_setMaxHeight:(CGFloat)maxHeight +- (void)yk_setMaxHeight:(CGFloat)maxHeight { YGNodeStyleSetMaxHeight([self ygNode], maxHeight); } -- (void)yg_setAspectRatio:(CGFloat)aspectRatio +- (void)yk_setAspectRatio:(CGFloat)aspectRatio { YGNodeStyleSetAspectRatio([self ygNode], aspectRatio); } #pragma mark - Layout and Sizing -- (YGDirection)yg_resolvedDirection +- (YKDirection)yk_resolvedDirection { - return YGNodeLayoutGetDirection([self ygNode]); + return (YKDirection)YGNodeLayoutGetDirection([self ygNode]); } -- (void)yg_applyLayout +- (void)yk_applyLayout { [self calculateLayoutWithSize:self.bounds.size]; - YGApplyLayoutToViewHierarchy(self); + YKApplyLayoutToViewHierarchy(self); } -- (CGSize)yg_intrinsicSize +- (CGSize)yk_intrinsicSize { const CGSize constrainedSize = { .width = YGUndefined, @@ -220,9 +220,9 @@ - (CGSize)calculateLayoutWithSize:(CGSize)size { NSAssert([NSThread isMainThread], @"YG Layout calculation must be done on main."); - NSAssert([self yg_usesYoga], @"YG Layout is not enabled for this view."); + NSAssert([self yk_usesYoga], @"YG Layout is not enabled for this view."); - YGAttachNodesFromViewHierachy(self); + YKAttachNodesFromViewHierachy(self); const YGNodeRef node = [self ygNode]; YGNodeCalculateLayout( @@ -237,7 +237,7 @@ }; } -static YGSize YGMeasureView( +static YGSize YKMeasureView( YGNodeRef node, float width, YGMeasureMode widthMode, @@ -254,12 +254,12 @@ static YGSize YGMeasureView( }]; return (YGSize) { - .width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode), - .height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode), + .width = YKSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode), + .height = YKSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode), }; } -static CGFloat YGSanitizeMeasurement( +static CGFloat YKSanitizeMeasurement( CGFloat constrainedSize, CGFloat measuredSize, YGMeasureMode measureMode) @@ -276,20 +276,20 @@ static CGFloat YGSanitizeMeasurement( return result; } -static void YGAttachNodesFromViewHierachy(UIView *view) { +static void YKAttachNodesFromViewHierachy(UIView *view) { YGNodeRef node = [view ygNode]; // Only leaf nodes should have a measure function - if (![view yg_usesYoga] || view.subviews.count == 0) { - YGNodeSetMeasureFunc(node, YGMeasureView); - YGRemoveAllChildren(node); + if (![view yk_usesYoga] || view.subviews.count == 0) { + YGNodeSetMeasureFunc(node, YKMeasureView); + YKRemoveAllChildren(node); } else { YGNodeSetMeasureFunc(node, NULL); // Create a list of all the subviews that we are going to use for layout. NSMutableArray *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count]; for (UIView *subview in view.subviews) { - if ([subview yg_includeInLayout]) { + if ([subview yk_includeInLayout]) { [subviewsToInclude addObject:subview]; } } @@ -307,18 +307,18 @@ static void YGAttachNodesFromViewHierachy(UIView *view) { } if (shouldReconstructChildList) { - YGRemoveAllChildren(node); + YKRemoveAllChildren(node); for (int i = 0 ; i < subviewsToInclude.count; i++) { UIView *const subview = subviewsToInclude[i]; YGNodeInsertChild(node, [subview ygNode], i); - YGAttachNodesFromViewHierachy(subview); + YKAttachNodesFromViewHierachy(subview); } } } } -static void YGRemoveAllChildren(const YGNodeRef node) +static void YKRemoveAllChildren(const YGNodeRef node) { if (node == NULL) { return; @@ -329,7 +329,7 @@ static void YGRemoveAllChildren(const YGNodeRef node) } } -static CGFloat YGRoundPixelValue(CGFloat value) +static CGFloat YKRoundPixelValue(CGFloat value) { static CGFloat scale; static dispatch_once_t onceToken; @@ -340,9 +340,9 @@ static CGFloat YGRoundPixelValue(CGFloat value) return round(value * scale) / scale; } -static void YGApplyLayoutToViewHierarchy(UIView *view) { +static void YKApplyLayoutToViewHierarchy(UIView *view) { NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread."); - if (![view yg_includeInLayout]) { + if (![view yk_includeInLayout]) { return; } @@ -359,19 +359,19 @@ static void YGApplyLayoutToViewHierarchy(UIView *view) { view.frame = (CGRect) { .origin = { - .x = YGRoundPixelValue(topLeft.x), - .y = YGRoundPixelValue(topLeft.y), + .x = YKRoundPixelValue(topLeft.x), + .y = YKRoundPixelValue(topLeft.y), }, .size = { - .width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x), - .height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y), + .width = YKRoundPixelValue(bottomRight.x) - YKRoundPixelValue(topLeft.x), + .height = YKRoundPixelValue(bottomRight.y) - YKRoundPixelValue(topLeft.y), }, }; - const BOOL isLeaf = ![view yg_usesYoga] || view.subviews.count == 0; + const BOOL isLeaf = ![view yk_usesYoga] || view.subviews.count == 0; if (!isLeaf) { for (NSUInteger i = 0; i < view.subviews.count; i++) { - YGApplyLayoutToViewHierarchy(view.subviews[i]); + YKApplyLayoutToViewHierarchy(view.subviews[i]); } } } diff --git a/YogaKit/YKEnums.h b/YogaKit/YKEnums.h new file mode 100644 index 00000000..cc148d2b --- /dev/null +++ b/YogaKit/YKEnums.h @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +typedef NS_ENUM(NSInteger, YKFlexDirection) { + YKFlexDirectionColumn, + YKFlexDirectionColumnReverse, + YKFlexDirectionRow, + YKFlexDirectionRowReverse, +}; + +typedef NS_ENUM(NSInteger, YKMeasureMode) { + YKMeasureModeUndefined, + YKMeasureModeExactly, + YKMeasureModeAtMost, +}; + +typedef NS_ENUM(NSInteger, YKPrintOptions) { + YKPrintOptionsLayout = 1, + YKPrintOptionsStyle = 2, + YKPrintOptionsChildren = 4, +}; + +typedef NS_ENUM(NSInteger, YKEdge) { + YKEdgeLeft, + YKEdgeTop, + YKEdgeRight, + YKEdgeBottom, + YKEdgeStart, + YKEdgeEnd, + YKEdgeHorizontal, + YKEdgeVertical, + YKEdgeAll, +}; + +typedef NS_ENUM(NSInteger, YKPositionType) { + YKPositionTypeRelative, + YKPositionTypeAbsolute, +}; + +typedef NS_ENUM(NSInteger, YKDimension) { + YKDimensionWidth, + YKDimensionHeight, +}; + +typedef NS_ENUM(NSInteger, YKJustify) { + YKJustifyFlexStart, + YKJustifyCenter, + YKJustifyFlexEnd, + YKJustifySpaceBetween, + YKJustifySpaceAround, +}; + +typedef NS_ENUM(NSInteger, YKDirection) { + YKDirectionInherit, + YKDirectionLeftToRight, + YKDirectionRightToLeft, +}; + +typedef NS_ENUM(NSInteger, YKLogLevel) { + YKLogLevelError, + YKLogLevelWarn, + YKLogLevelInfo, + YKLogLevelDebug, + YKLogLevelVerbose, +}; + +typedef NS_ENUM(NSInteger, YKWrap) { + YKWrapNoWrap, + YKWrapWrap, +}; + +typedef NS_ENUM(NSInteger, YKOverflow) { + YKOverflowVisible, + YKOverflowHidden, + YKOverflowScroll, +}; + +typedef NS_ENUM(NSInteger, YKExperimentalFeature) { + YKExperimentalFeatureRounding, + YKExperimentalFeatureWebFlexBasis, +}; + +typedef NS_ENUM(NSInteger, YKAlign) { + YKAlignAuto, + YKAlignFlexStart, + YKAlignCenter, + YKAlignFlexEnd, + YKAlignStretch, +}; + diff --git a/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj b/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj index f45f99ff..011a3824 100644 --- a/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj +++ b/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj @@ -11,13 +11,6 @@ 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4A1DF8748400E7C260 /* AppDelegate.m */; }; 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4D1DF8748400E7C260 /* ViewController.m */; }; 13687D531DF8748400E7C260 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13687D521DF8748400E7C260 /* Assets.xcassets */; }; - 13687D781DF878C600E7C260 /* YGEnums.h in yoga */ = {isa = PBXBuildFile; fileRef = 13687D5E1DF8778F00E7C260 /* YGEnums.h */; }; - 13687D791DF878C600E7C260 /* YGMacros.h in yoga */ = {isa = PBXBuildFile; fileRef = 13687D5F1DF8778F00E7C260 /* YGMacros.h */; }; - 13687D7A1DF878C600E7C260 /* Yoga.h in yoga */ = {isa = PBXBuildFile; fileRef = 13687D631DF8778F00E7C260 /* Yoga.h */; }; - 13687D7C1DF878DD00E7C260 /* UIView+Yoga.h in YogaKit */ = {isa = PBXBuildFile; fileRef = 13687D691DF8778F00E7C260 /* UIView+Yoga.h */; }; - 13687D801DF87CEC00E7C260 /* UIView+Yoga.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */; }; - 13687D811DF87CF200E7C260 /* YGNodeList.c in Sources */ = {isa = PBXBuildFile; fileRef = 13687D601DF8778F00E7C260 /* YGNodeList.c */; }; - 13687D821DF87CF200E7C260 /* Yoga.c in Sources */ = {isa = PBXBuildFile; fileRef = 13687D621DF8778F00E7C260 /* Yoga.c */; }; 13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D841DF87D1E00E7C260 /* UIKit.framework */; }; 13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D861DF87D2400E7C260 /* Foundation.framework */; }; 63EE08411E06ED3D00EE5F9A /* YogaKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 63EE083F1E06ED3D00EE5F9A /* YogaKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -25,12 +18,12 @@ 63EE08451E06ED3D00EE5F9A /* YogaKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 63EE083D1E06ED3D00EE5F9A /* YogaKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 63EE084A1E06EEB700EE5F9A /* YGNodeList.c in Sources */ = {isa = PBXBuildFile; fileRef = 13687D601DF8778F00E7C260 /* YGNodeList.c */; }; 63EE084B1E06EEB700EE5F9A /* Yoga.c in Sources */ = {isa = PBXBuildFile; fileRef = 13687D621DF8778F00E7C260 /* Yoga.c */; }; - 63EE084C1E06EEB700EE5F9A /* UIView+Yoga.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */; }; - 63EE084D1E06EECB00EE5F9A /* YGEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D5E1DF8778F00E7C260 /* YGEnums.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 63EE084E1E06EECB00EE5F9A /* YGMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D5F1DF8778F00E7C260 /* YGMacros.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 63EE084F1E06EECB00EE5F9A /* YGNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D611DF8778F00E7C260 /* YGNodeList.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 63EE08501E06EECB00EE5F9A /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D631DF8778F00E7C260 /* Yoga.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 63EE08511E06EECB00EE5F9A /* UIView+Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D691DF8778F00E7C260 /* UIView+Yoga.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 63EE084C1E06EEB700EE5F9A /* UIView+YogaKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D6A1DF8778F00E7C260 /* UIView+YogaKit.m */; }; + 63EE084E1E06EECB00EE5F9A /* YGMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D5F1DF8778F00E7C260 /* YGMacros.h */; }; + 63EE084F1E06EECB00EE5F9A /* YGNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D611DF8778F00E7C260 /* YGNodeList.h */; }; + 63EE08501E06EECB00EE5F9A /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D631DF8778F00E7C260 /* Yoga.h */; }; + 63EE08511E06EECB00EE5F9A /* UIView+YogaKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D691DF8778F00E7C260 /* UIView+YogaKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 63EE08531E06F3D100EE5F9A /* YKEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 63EE08521E06F3D100EE5F9A /* YKEnums.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -44,30 +37,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ - 13687D771DF878A000E7C260 /* yoga */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = include/yoga; - dstSubfolderSpec = 16; - files = ( - 13687D781DF878C600E7C260 /* YGEnums.h in yoga */, - 13687D791DF878C600E7C260 /* YGMacros.h in yoga */, - 13687D7A1DF878C600E7C260 /* Yoga.h in yoga */, - ); - name = yoga; - runOnlyForDeploymentPostprocessing = 0; - }; - 13687D7B1DF878CE00E7C260 /* YogaKit */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = include/YogaKit; - dstSubfolderSpec = 16; - files = ( - 13687D7C1DF878DD00E7C260 /* UIView+Yoga.h in YogaKit */, - ); - name = YogaKit; - runOnlyForDeploymentPostprocessing = 0; - }; 63EE08491E06ED3D00EE5F9A /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -90,19 +59,19 @@ 13687D4D1DF8748400E7C260 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 13687D521DF8748400E7C260 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 13687D571DF8748400E7C260 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 13687D5E1DF8778F00E7C260 /* YGEnums.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YGEnums.h; sourceTree = ""; }; 13687D5F1DF8778F00E7C260 /* YGMacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YGMacros.h; sourceTree = ""; }; 13687D601DF8778F00E7C260 /* YGNodeList.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = YGNodeList.c; sourceTree = ""; }; 13687D611DF8778F00E7C260 /* YGNodeList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YGNodeList.h; sourceTree = ""; }; 13687D621DF8778F00E7C260 /* Yoga.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = Yoga.c; sourceTree = ""; }; 13687D631DF8778F00E7C260 /* Yoga.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Yoga.h; sourceTree = ""; }; - 13687D691DF8778F00E7C260 /* UIView+Yoga.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIView+Yoga.h"; path = "../../UIView+Yoga.h"; sourceTree = ""; }; - 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UIView+Yoga.m"; path = "../../UIView+Yoga.m"; sourceTree = ""; }; + 13687D691DF8778F00E7C260 /* UIView+YogaKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "UIView+YogaKit.h"; path = "../../UIView+YogaKit.h"; sourceTree = ""; }; + 13687D6A1DF8778F00E7C260 /* UIView+YogaKit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "UIView+YogaKit.m"; path = "../../UIView+YogaKit.m"; sourceTree = ""; }; 13687D841DF87D1E00E7C260 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 13687D861DF87D2400E7C260 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 63EE083D1E06ED3D00EE5F9A /* YogaKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YogaKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 63EE083F1E06ED3D00EE5F9A /* YogaKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YogaKit.h; sourceTree = ""; }; 63EE08401E06ED3D00EE5F9A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 63EE08521E06F3D100EE5F9A /* YKEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = YKEnums.h; path = ../../YKEnums.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -170,7 +139,6 @@ 13687D5D1DF8778F00E7C260 /* yoga */ = { isa = PBXGroup; children = ( - 13687D5E1DF8778F00E7C260 /* YGEnums.h */, 13687D5F1DF8778F00E7C260 /* YGMacros.h */, 13687D601DF8778F00E7C260 /* YGNodeList.c */, 13687D611DF8778F00E7C260 /* YGNodeList.h */, @@ -195,8 +163,9 @@ children = ( 13687D5D1DF8778F00E7C260 /* yoga */, 63EE083F1E06ED3D00EE5F9A /* YogaKit.h */, - 13687D691DF8778F00E7C260 /* UIView+Yoga.h */, - 13687D6A1DF8778F00E7C260 /* UIView+Yoga.m */, + 63EE08521E06F3D100EE5F9A /* YKEnums.h */, + 13687D691DF8778F00E7C260 /* UIView+YogaKit.h */, + 13687D6A1DF8778F00E7C260 /* UIView+YogaKit.m */, 63EE08401E06ED3D00EE5F9A /* Info.plist */, ); path = YogaKit; @@ -210,8 +179,8 @@ buildActionMask = 2147483647; files = ( 63EE08411E06ED3D00EE5F9A /* YogaKit.h in Headers */, - 63EE08511E06EECB00EE5F9A /* UIView+Yoga.h in Headers */, - 63EE084D1E06EECB00EE5F9A /* YGEnums.h in Headers */, + 63EE08531E06F3D100EE5F9A /* YKEnums.h in Headers */, + 63EE08511E06EECB00EE5F9A /* UIView+YogaKit.h in Headers */, 63EE084E1E06EECB00EE5F9A /* YGMacros.h in Headers */, 63EE084F1E06EECB00EE5F9A /* YGNodeList.h in Headers */, 63EE08501E06EECB00EE5F9A /* Yoga.h in Headers */, @@ -225,8 +194,6 @@ isa = PBXNativeTarget; buildConfigurationList = 13687D5A1DF8748400E7C260 /* Build configuration list for PBXNativeTarget "YogaKitSample" */; buildPhases = ( - 13687D771DF878A000E7C260 /* yoga */, - 13687D7B1DF878CE00E7C260 /* YogaKit */, 13687D3F1DF8748300E7C260 /* Sources */, 13687D401DF8748300E7C260 /* Frameworks */, 13687D411DF8748300E7C260 /* Resources */, @@ -266,7 +233,7 @@ 13687D3B1DF8748300E7C260 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0810; + LastUpgradeCheck = 0820; ORGANIZATIONNAME = facebook; TargetAttributes = { 13687D421DF8748300E7C260 = { @@ -321,11 +288,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 13687D801DF87CEC00E7C260 /* UIView+Yoga.m in Sources */, 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */, 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */, - 13687D821DF87CF200E7C260 /* Yoga.c in Sources */, - 13687D811DF87CF200E7C260 /* YGNodeList.c in Sources */, 13687D481DF8748400E7C260 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -336,7 +300,7 @@ files = ( 63EE084A1E06EEB700EE5F9A /* YGNodeList.c in Sources */, 63EE084B1E06EEB700EE5F9A /* Yoga.c in Sources */, - 63EE084C1E06EEB700EE5F9A /* UIView+Yoga.m in Sources */, + 63EE084C1E06EEB700EE5F9A /* UIView+YogaKit.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -369,6 +333,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -416,6 +381,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_SUSPICIOUS_MOVES = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate b/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate index 0dc901d6..33536713 100644 Binary files a/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate and b/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/YogaKit/YogaKit/YogaKit/YogaKit.h b/YogaKit/YogaKit/YogaKit/YogaKit.h index 37dff23a..c059a0de 100644 --- a/YogaKit/YogaKit/YogaKit/YogaKit.h +++ b/YogaKit/YogaKit/YogaKit/YogaKit.h @@ -14,6 +14,4 @@ FOUNDATION_EXPORT double YogaKitVersionNumber; //! Project version string for YogaKit. FOUNDATION_EXPORT const unsigned char YogaKitVersionString[]; -// In this header, you should import all the public headers of your framework using statements like #import - - +#import diff --git a/YogaKit/YogaKit/YogaKitSample/ViewController.m b/YogaKit/YogaKit/YogaKitSample/ViewController.m index a13dae6f..40ab77b0 100644 --- a/YogaKit/YogaKit/YogaKitSample/ViewController.m +++ b/YogaKit/YogaKit/YogaKitSample/ViewController.m @@ -7,8 +7,7 @@ */ #import "ViewController.h" - -#import +#import @interface ViewController () @@ -20,17 +19,17 @@ { UIView *root = self.view; root.backgroundColor = [UIColor redColor]; - [root yg_setUsesYoga:YES]; - [root yg_setWidth:self.view.bounds.size.width]; - [root yg_setHeight:self.view.bounds.size.height]; - [root yg_setAlignItems:YGAlignCenter]; - [root yg_setJustifyContent:YGJustifyCenter]; + [root yk_setUsesYoga:YES]; + [root yk_setWidth:self.view.bounds.size.width]; + [root yk_setHeight:self.view.bounds.size.height]; + [root yk_setAlignItems:YKAlignCenter]; + [root yk_setJustifyContent:YKJustifyCenter]; UIView *child1 = [UIView new]; child1.backgroundColor = [UIColor blueColor]; - [child1 yg_setUsesYoga:YES]; - [child1 yg_setWidth:100]; - [child1 yg_setHeight:100]; + [child1 yk_setUsesYoga:YES]; + [child1 yk_setWidth:100]; + [child1 yk_setHeight:100]; UIView *child2 = [UIView new]; child2.backgroundColor = [UIColor greenColor]; @@ -53,7 +52,7 @@ [child2 addSubview:child3]; [root addSubview:child1]; [root addSubview:child2]; - [root yg_applyLayout]; + [root yk_applyLayout]; } diff --git a/enums.py b/enums.py index d2fc6dc0..b12203f0 100644 --- a/enums.py +++ b/enums.py @@ -89,6 +89,14 @@ ENUMS = { ], } +OBJC_ENUMS = { + 'Direction': [ + 'Inherit', + 'LeftToRight', + 'RightToLeft', + ] +} + LICENSE = """/** * Copyright (c) 2014-present, Facebook, Inc. * All rights reserved. @@ -111,7 +119,7 @@ def to_java_upper(symbol): return out -root = os.path.dirname(__file__) +root = os.path.dirname(os.path.abspath(__file__)) # write out C header with open(root + '/yoga/YGEnums.h', 'w') as f: @@ -187,3 +195,18 @@ for name, values in ENUMS.items(): f.write(' %s,\n' % value) f.write(' }\n') f.write('}\n') + +# write out objc files +with open(root + '/YogaKit/YKEnums.h', 'w') as f: + objc_enums = ENUMS + objc_enums.update(OBJC_ENUMS) + f.write(LICENSE) + for name, values in objc_enums.items(): + f.write('typedef NS_ENUM(NSInteger, YK%s) {\n' % name) + for value in values: + if isinstance(value, tuple): + f.write(' YK%s%s = %d,\n' % (name, value[0], value[1])) + else: + f.write(' YK%s%s,\n' % (name, value)) + f.write('};\n') + f.write('\n')