fix lint errors
Summary: Changelog: [Internal][Yoga] Fixed lint errors ```arc lint --apply-patches --take CLANGFORMAT --paths-cmd 'hg files xplat/yoga' ``` Added .clang-tidy file Reviewed By: zertosh Differential Revision: D19948702 fbshipit-source-id: f77a16d6f2c532267597a84a9caded0aae68c3aa
This commit is contained in:
committed by
Facebook Github Bot
parent
a1278cee05
commit
bfc3b2f86f
@@ -5,28 +5,29 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "YGLayout.h"
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "YGLayout.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
|
typedef void (^YGLayoutConfigurationBlock)(YGLayout* layout);
|
||||||
|
|
||||||
@interface UIView (Yoga)
|
@interface UIView (Yoga)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The YGLayout that is attached to this view. It is lazily created.
|
The YGLayout that is attached to this view. It is lazily created.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, strong) YGLayout *yoga;
|
@property(nonatomic, readonly, strong) YGLayout* yoga;
|
||||||
/**
|
/**
|
||||||
Indicates whether or not Yoga is enabled
|
Indicates whether or not Yoga is enabled
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) BOOL isYogaEnabled;
|
@property(nonatomic, readonly, assign) BOOL isYogaEnabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
In ObjC land, every time you access `view.yoga.*` you are adding another `objc_msgSend`
|
In ObjC land, every time you access `view.yoga.*` you are adding another
|
||||||
to your code. If you plan on making multiple changes to YGLayout, it's more performant
|
`objc_msgSend` to your code. If you plan on making multiple changes to
|
||||||
to use this method, which uses a single objc_msgSend call.
|
YGLayout, it's more performant to use this method, which uses a single
|
||||||
|
objc_msgSend call.
|
||||||
*/
|
*/
|
||||||
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
|
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
|
||||||
NS_SWIFT_NAME(configureLayout(block:));
|
NS_SWIFT_NAME(configureLayout(block:));
|
||||||
|
@@ -5,32 +5,30 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#import <objc/runtime.h>
|
||||||
#import "UIView+Yoga.h"
|
#import "UIView+Yoga.h"
|
||||||
#import "YGLayout+Private.h"
|
#import "YGLayout+Private.h"
|
||||||
#import <objc/runtime.h>
|
|
||||||
|
|
||||||
static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
|
static const void* kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
|
||||||
|
|
||||||
@implementation UIView (YogaKit)
|
@implementation UIView (YogaKit)
|
||||||
|
|
||||||
- (YGLayout *)yoga
|
- (YGLayout*)yoga {
|
||||||
{
|
YGLayout* yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
|
||||||
YGLayout *yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
|
|
||||||
if (!yoga) {
|
if (!yoga) {
|
||||||
yoga = [[YGLayout alloc] initWithView:self];
|
yoga = [[YGLayout alloc] initWithView:self];
|
||||||
objc_setAssociatedObject(self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
objc_setAssociatedObject(
|
||||||
|
self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
return yoga;
|
return yoga;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isYogaEnabled
|
- (BOOL)isYogaEnabled {
|
||||||
{
|
|
||||||
return objc_getAssociatedObject(self, kYGYogaAssociatedKey) != nil;
|
return objc_getAssociatedObject(self, kYGYogaAssociatedKey) != nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
|
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block {
|
||||||
{
|
|
||||||
if (block != nil) {
|
if (block != nil) {
|
||||||
block(self.yoga);
|
block(self.yoga);
|
||||||
}
|
}
|
||||||
|
@@ -5,13 +5,13 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "YGLayout.h"
|
|
||||||
#import <yoga/Yoga.h>
|
#import <yoga/Yoga.h>
|
||||||
|
#import "YGLayout.h"
|
||||||
|
|
||||||
@interface YGLayout ()
|
@interface YGLayout ()
|
||||||
|
|
||||||
@property (nonatomic, assign, readonly) YGNodeRef node;
|
@property(nonatomic, assign, readonly) YGNodeRef node;
|
||||||
|
|
||||||
- (instancetype)initWithView:(UIView *)view;
|
- (instancetype)initWithView:(UIView*)view;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -7,15 +7,15 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <yoga/YGEnums.h>
|
#import <yoga/YGEnums.h>
|
||||||
#import <yoga/Yoga.h>
|
|
||||||
#import <yoga/YGMacros.h>
|
#import <yoga/YGMacros.h>
|
||||||
|
#import <yoga/Yoga.h>
|
||||||
|
|
||||||
YG_EXTERN_C_BEGIN
|
YG_EXTERN_C_BEGIN
|
||||||
|
|
||||||
extern YGValue YGPointValue(CGFloat value)
|
extern YGValue YGPointValue(CGFloat value) NS_SWIFT_UNAVAILABLE(
|
||||||
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
"Use the swift Int and FloatingPoint extensions instead");
|
||||||
extern YGValue YGPercentValue(CGFloat value)
|
extern YGValue YGPercentValue(CGFloat value) NS_SWIFT_UNAVAILABLE(
|
||||||
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
"Use the swift Int and FloatingPoint extensions instead");
|
||||||
|
|
||||||
YG_EXTERN_C_END
|
YG_EXTERN_C_END
|
||||||
|
|
||||||
@@ -44,103 +44,107 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
|
|||||||
The property that decides if we should include this view when calculating
|
The property that decides if we should include this view when calculating
|
||||||
layout. Defaults to YES.
|
layout. Defaults to YES.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readwrite, assign, setter=setIncludedInLayout:) BOOL isIncludedInLayout;
|
@property(nonatomic, readwrite, assign, setter=setIncludedInLayout:)
|
||||||
|
BOOL isIncludedInLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The property that decides during layout/sizing whether or not styling properties should be applied.
|
The property that decides during layout/sizing whether or not styling
|
||||||
Defaults to NO.
|
properties should be applied. Defaults to NO.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled;
|
@property(nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) YGDirection direction;
|
@property(nonatomic, readwrite, assign) YGDirection direction;
|
||||||
@property (nonatomic, readwrite, assign) YGFlexDirection flexDirection;
|
@property(nonatomic, readwrite, assign) YGFlexDirection flexDirection;
|
||||||
@property (nonatomic, readwrite, assign) YGJustify justifyContent;
|
@property(nonatomic, readwrite, assign) YGJustify justifyContent;
|
||||||
@property (nonatomic, readwrite, assign) YGAlign alignContent;
|
@property(nonatomic, readwrite, assign) YGAlign alignContent;
|
||||||
@property (nonatomic, readwrite, assign) YGAlign alignItems;
|
@property(nonatomic, readwrite, assign) YGAlign alignItems;
|
||||||
@property (nonatomic, readwrite, assign) YGAlign alignSelf;
|
@property(nonatomic, readwrite, assign) YGAlign alignSelf;
|
||||||
@property (nonatomic, readwrite, assign) YGPositionType position;
|
@property(nonatomic, readwrite, assign) YGPositionType position;
|
||||||
@property (nonatomic, readwrite, assign) YGWrap flexWrap;
|
@property(nonatomic, readwrite, assign) YGWrap flexWrap;
|
||||||
@property (nonatomic, readwrite, assign) YGOverflow overflow;
|
@property(nonatomic, readwrite, assign) YGOverflow overflow;
|
||||||
@property (nonatomic, readwrite, assign) YGDisplay display;
|
@property(nonatomic, readwrite, assign) YGDisplay display;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) CGFloat flex;
|
@property(nonatomic, readwrite, assign) CGFloat flex;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat flexGrow;
|
@property(nonatomic, readwrite, assign) CGFloat flexGrow;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat flexShrink;
|
@property(nonatomic, readwrite, assign) CGFloat flexShrink;
|
||||||
@property (nonatomic, readwrite, assign) YGValue flexBasis;
|
@property(nonatomic, readwrite, assign) YGValue flexBasis;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) YGValue left;
|
@property(nonatomic, readwrite, assign) YGValue left;
|
||||||
@property (nonatomic, readwrite, assign) YGValue top;
|
@property(nonatomic, readwrite, assign) YGValue top;
|
||||||
@property (nonatomic, readwrite, assign) YGValue right;
|
@property(nonatomic, readwrite, assign) YGValue right;
|
||||||
@property (nonatomic, readwrite, assign) YGValue bottom;
|
@property(nonatomic, readwrite, assign) YGValue bottom;
|
||||||
@property (nonatomic, readwrite, assign) YGValue start;
|
@property(nonatomic, readwrite, assign) YGValue start;
|
||||||
@property (nonatomic, readwrite, assign) YGValue end;
|
@property(nonatomic, readwrite, assign) YGValue end;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginLeft;
|
@property(nonatomic, readwrite, assign) YGValue marginLeft;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginTop;
|
@property(nonatomic, readwrite, assign) YGValue marginTop;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginRight;
|
@property(nonatomic, readwrite, assign) YGValue marginRight;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginBottom;
|
@property(nonatomic, readwrite, assign) YGValue marginBottom;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginStart;
|
@property(nonatomic, readwrite, assign) YGValue marginStart;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginEnd;
|
@property(nonatomic, readwrite, assign) YGValue marginEnd;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginHorizontal;
|
@property(nonatomic, readwrite, assign) YGValue marginHorizontal;
|
||||||
@property (nonatomic, readwrite, assign) YGValue marginVertical;
|
@property(nonatomic, readwrite, assign) YGValue marginVertical;
|
||||||
@property (nonatomic, readwrite, assign) YGValue margin;
|
@property(nonatomic, readwrite, assign) YGValue margin;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingLeft;
|
@property(nonatomic, readwrite, assign) YGValue paddingLeft;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingTop;
|
@property(nonatomic, readwrite, assign) YGValue paddingTop;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingRight;
|
@property(nonatomic, readwrite, assign) YGValue paddingRight;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingBottom;
|
@property(nonatomic, readwrite, assign) YGValue paddingBottom;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingStart;
|
@property(nonatomic, readwrite, assign) YGValue paddingStart;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingEnd;
|
@property(nonatomic, readwrite, assign) YGValue paddingEnd;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingHorizontal;
|
@property(nonatomic, readwrite, assign) YGValue paddingHorizontal;
|
||||||
@property (nonatomic, readwrite, assign) YGValue paddingVertical;
|
@property(nonatomic, readwrite, assign) YGValue paddingVertical;
|
||||||
@property (nonatomic, readwrite, assign) YGValue padding;
|
@property(nonatomic, readwrite, assign) YGValue padding;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderLeftWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderLeftWidth;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderTopWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderTopWidth;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderRightWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderRightWidth;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderBottomWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderBottomWidth;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderStartWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderStartWidth;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderEndWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderEndWidth;
|
||||||
@property (nonatomic, readwrite, assign) CGFloat borderWidth;
|
@property(nonatomic, readwrite, assign) CGFloat borderWidth;
|
||||||
|
|
||||||
@property (nonatomic, readwrite, assign) YGValue width;
|
@property(nonatomic, readwrite, assign) YGValue width;
|
||||||
@property (nonatomic, readwrite, assign) YGValue height;
|
@property(nonatomic, readwrite, assign) YGValue height;
|
||||||
@property (nonatomic, readwrite, assign) YGValue minWidth;
|
@property(nonatomic, readwrite, assign) YGValue minWidth;
|
||||||
@property (nonatomic, readwrite, assign) YGValue minHeight;
|
@property(nonatomic, readwrite, assign) YGValue minHeight;
|
||||||
@property (nonatomic, readwrite, assign) YGValue maxWidth;
|
@property(nonatomic, readwrite, assign) YGValue maxWidth;
|
||||||
@property (nonatomic, readwrite, assign) YGValue maxHeight;
|
@property(nonatomic, readwrite, assign) YGValue maxHeight;
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
@property (nonatomic, readwrite, assign) CGFloat aspectRatio;
|
@property(nonatomic, readwrite, assign) CGFloat aspectRatio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Get the resolved direction of this node. This won't be YGDirectionInherit
|
Get the resolved direction of this node. This won't be YGDirectionInherit
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) YGDirection resolvedDirection;
|
@property(nonatomic, readonly, assign) YGDirection resolvedDirection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
|
Perform a layout calculation and update the frames of the views in the
|
||||||
If the origin is not preserved, the root view's layout results will applied from {0,0}.
|
hierarchy with the results. If the origin is not preserved, the root view's
|
||||||
|
layout results will applied from {0,0}.
|
||||||
*/
|
*/
|
||||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
||||||
NS_SWIFT_NAME(applyLayout(preservingOrigin:));
|
NS_SWIFT_NAME(applyLayout(preservingOrigin:));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
|
Perform a layout calculation and update the frames of the views in the
|
||||||
If the origin is not preserved, the root view's layout results will applied from {0,0}.
|
hierarchy with the results. If the origin is not preserved, the root view's
|
||||||
|
layout results will applied from {0,0}.
|
||||||
*/
|
*/
|
||||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
||||||
dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
|
dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
|
||||||
NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:));
|
NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the size of the view if no constraints were given. This could equivalent to calling [self
|
Returns the size of the view if no constraints were given. This could
|
||||||
sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) CGSize intrinsicSize;
|
@property(nonatomic, readonly, assign) CGSize intrinsicSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the size of the view based on provided constraints. Pass NaN for an unconstrained dimension.
|
Returns the size of the view based on provided constraints. Pass NaN for an
|
||||||
|
unconstrained dimension.
|
||||||
*/
|
*/
|
||||||
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
||||||
NS_SWIFT_NAME(calculateLayout(with:));
|
NS_SWIFT_NAME(calculateLayout(with:));
|
||||||
@@ -148,19 +152,19 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
|
|||||||
/**
|
/**
|
||||||
Returns the number of children that are using Flexbox.
|
Returns the number of children that are using Flexbox.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) NSUInteger numberOfChildren;
|
@property(nonatomic, readonly, assign) NSUInteger numberOfChildren;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return a BOOL indiciating whether or not we this node contains any subviews that are included in
|
Return a BOOL indiciating whether or not we this node contains any subviews
|
||||||
Yoga's layout.
|
that are included in Yoga's layout.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) BOOL isLeaf;
|
@property(nonatomic, readonly, assign) BOOL isLeaf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Return's a BOOL indicating if a view is dirty. When a node is dirty
|
Return's a BOOL indicating if a view is dirty. When a node is dirty
|
||||||
it usually indicates that it will be remeasured on the next layout pass.
|
it usually indicates that it will be remeasured on the next layout pass.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, assign) BOOL isDirty;
|
@property(nonatomic, readonly, assign) BOOL isDirty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Mark that a view's layout needs to be recalculated. Only works for leaf views.
|
Mark that a view's layout needs to be recalculated. Only works for leaf views.
|
||||||
|
@@ -5,28 +5,24 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "YGLayout+Private.h"
|
|
||||||
#import "UIView+Yoga.h"
|
#import "UIView+Yoga.h"
|
||||||
|
#import "YGLayout+Private.h"
|
||||||
|
|
||||||
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
|
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
|
||||||
- (type)lowercased_name \
|
-(type)lowercased_name { \
|
||||||
{ \
|
|
||||||
return YGNodeStyleGet##capitalized_name(self.node); \
|
return YGNodeStyleGet##capitalized_name(self.node); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
- (void)set##capitalized_name:(type)lowercased_name \
|
-(void)set##capitalized_name : (type)lowercased_name { \
|
||||||
{ \
|
|
||||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
|
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
|
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
|
||||||
- (YGValue)lowercased_name \
|
-(YGValue)lowercased_name { \
|
||||||
{ \
|
|
||||||
return YGNodeStyleGet##capitalized_name(self.node); \
|
return YGNodeStyleGet##capitalized_name(self.node); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
- (void)set##capitalized_name:(YGValue)lowercased_name \
|
-(void)set##capitalized_name : (YGValue)lowercased_name { \
|
||||||
{ \
|
|
||||||
switch (lowercased_name.unit) { \
|
switch (lowercased_name.unit) { \
|
||||||
case YGUnitUndefined: \
|
case YGUnitUndefined: \
|
||||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
||||||
@@ -35,27 +31,27 @@
|
|||||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
||||||
break; \
|
break; \
|
||||||
case YGUnitPercent: \
|
case YGUnitPercent: \
|
||||||
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
|
YGNodeStyleSet##capitalized_name##Percent( \
|
||||||
|
self.node, lowercased_name.value); \
|
||||||
break; \
|
break; \
|
||||||
default: \
|
default: \
|
||||||
NSAssert(NO, @"Not implemented"); \
|
NSAssert(NO, @"Not implemented"); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \
|
#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \
|
||||||
- (YGValue)lowercased_name \
|
-(YGValue)lowercased_name { \
|
||||||
{ \
|
|
||||||
return YGNodeStyleGet##capitalized_name(self.node); \
|
return YGNodeStyleGet##capitalized_name(self.node); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
- (void)set##capitalized_name:(YGValue)lowercased_name \
|
-(void)set##capitalized_name : (YGValue)lowercased_name { \
|
||||||
{ \
|
|
||||||
switch (lowercased_name.unit) { \
|
switch (lowercased_name.unit) { \
|
||||||
case YGUnitPoint: \
|
case YGUnitPoint: \
|
||||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
||||||
break; \
|
break; \
|
||||||
case YGUnitPercent: \
|
case YGUnitPercent: \
|
||||||
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
|
YGNodeStyleSet##capitalized_name##Percent( \
|
||||||
|
self.node, lowercased_name.value); \
|
||||||
break; \
|
break; \
|
||||||
case YGUnitAuto: \
|
case YGUnitAuto: \
|
||||||
YGNodeStyleSet##capitalized_name##Auto(self.node); \
|
YGNodeStyleSet##capitalized_name##Auto(self.node); \
|
||||||
@@ -63,27 +59,28 @@
|
|||||||
default: \
|
default: \
|
||||||
NSAssert(NO, @"Not implemented"); \
|
NSAssert(NO, @"Not implemented"); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_EDGE_PROPERTY_GETTER(type, lowercased_name, capitalized_name, property, edge) \
|
#define YG_EDGE_PROPERTY_GETTER( \
|
||||||
- (type)lowercased_name \
|
type, lowercased_name, capitalized_name, property, edge) \
|
||||||
{ \
|
-(type)lowercased_name { \
|
||||||
return YGNodeStyleGet##property(self.node, edge); \
|
return YGNodeStyleGet##property(self.node, edge); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \
|
#define YG_EDGE_PROPERTY_SETTER( \
|
||||||
- (void)set##capitalized_name:(CGFloat)lowercased_name \
|
lowercased_name, capitalized_name, property, edge) \
|
||||||
{ \
|
-(void)set##capitalized_name : (CGFloat)lowercased_name { \
|
||||||
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
|
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
||||||
YG_EDGE_PROPERTY_GETTER(CGFloat, lowercased_name, capitalized_name, property, edge) \
|
YG_EDGE_PROPERTY_GETTER( \
|
||||||
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
|
CGFloat, lowercased_name, capitalized_name, property, edge) \
|
||||||
|
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
|
||||||
|
|
||||||
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
|
#define YG_VALUE_EDGE_PROPERTY_SETTER( \
|
||||||
- (void)set##objc_capitalized_name:(YGValue)objc_lowercased_name \
|
objc_lowercased_name, objc_capitalized_name, c_name, edge) \
|
||||||
{ \
|
-(void)set##objc_capitalized_name : (YGValue)objc_lowercased_name { \
|
||||||
switch (objc_lowercased_name.unit) { \
|
switch (objc_lowercased_name.unit) { \
|
||||||
case YGUnitUndefined: \
|
case YGUnitUndefined: \
|
||||||
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
|
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
|
||||||
@@ -92,66 +89,100 @@ YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
|
|||||||
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
|
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
|
||||||
break; \
|
break; \
|
||||||
case YGUnitPercent: \
|
case YGUnitPercent: \
|
||||||
YGNodeStyleSet##c_name##Percent(self.node, edge, objc_lowercased_name.value); \
|
YGNodeStyleSet##c_name##Percent( \
|
||||||
|
self.node, edge, objc_lowercased_name.value); \
|
||||||
break; \
|
break; \
|
||||||
default: \
|
default: \
|
||||||
NSAssert(NO, @"Not implemented"); \
|
NSAssert(NO, @"Not implemented"); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
#define YG_VALUE_EDGE_PROPERTY( \
|
||||||
YG_EDGE_PROPERTY_GETTER(YGValue, lowercased_name, capitalized_name, property, edge) \
|
lowercased_name, capitalized_name, property, edge) \
|
||||||
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
|
YG_EDGE_PROPERTY_GETTER( \
|
||||||
|
YGValue, lowercased_name, capitalized_name, property, edge) \
|
||||||
|
YG_VALUE_EDGE_PROPERTY_SETTER( \
|
||||||
|
lowercased_name, capitalized_name, property, edge)
|
||||||
|
|
||||||
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
|
#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( \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
|
lowercased_name##Left, \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
|
capitalized_name##Left, \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
|
capitalized_name, \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
|
YGEdgeLeft) \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
|
YG_VALUE_EDGE_PROPERTY( \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \
|
lowercased_name##Top, \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \
|
capitalized_name##Top, \
|
||||||
YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
|
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_EDGE_PROPERTY( \
|
||||||
|
lowercased_name##Horizontal, \
|
||||||
|
capitalized_name##Horizontal, \
|
||||||
|
capitalized_name, \
|
||||||
|
YGEdgeHorizontal) \
|
||||||
|
YG_VALUE_EDGE_PROPERTY( \
|
||||||
|
lowercased_name##Vertical, \
|
||||||
|
capitalized_name##Vertical, \
|
||||||
|
capitalized_name, \
|
||||||
|
YGEdgeVertical) \
|
||||||
|
YG_VALUE_EDGE_PROPERTY( \
|
||||||
|
lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
|
||||||
|
|
||||||
YGValue YGPointValue(CGFloat value)
|
YGValue YGPointValue(CGFloat value) {
|
||||||
{
|
return (YGValue){.value = value, .unit = YGUnitPoint};
|
||||||
return (YGValue) { .value = value, .unit = YGUnitPoint };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YGValue YGPercentValue(CGFloat value)
|
YGValue YGPercentValue(CGFloat value) {
|
||||||
{
|
return (YGValue){.value = value, .unit = YGUnitPercent};
|
||||||
return (YGValue) { .value = value, .unit = YGUnitPercent };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGConfigRef globalConfig;
|
static YGConfigRef globalConfig;
|
||||||
|
|
||||||
@interface YGLayout ()
|
@interface YGLayout ()
|
||||||
|
|
||||||
@property (nonatomic, weak, readonly) UIView *view;
|
@property(nonatomic, weak, readonly) UIView* view;
|
||||||
@property(nonatomic, assign, readonly) BOOL isUIView;
|
@property(nonatomic, assign, readonly) BOOL isUIView;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation YGLayout
|
@implementation YGLayout
|
||||||
|
|
||||||
@synthesize isEnabled=_isEnabled;
|
@synthesize isEnabled = _isEnabled;
|
||||||
@synthesize isIncludedInLayout=_isIncludedInLayout;
|
@synthesize isIncludedInLayout = _isIncludedInLayout;
|
||||||
@synthesize node=_node;
|
@synthesize node = _node;
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize {
|
||||||
{
|
|
||||||
globalConfig = YGConfigNew();
|
globalConfig = YGConfigNew();
|
||||||
YGConfigSetExperimentalFeatureEnabled(globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
YGConfigSetExperimentalFeatureEnabled(
|
||||||
|
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
||||||
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
|
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithView:(UIView*)view
|
- (instancetype)initWithView:(UIView*)view {
|
||||||
{
|
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_view = view;
|
_view = view;
|
||||||
_node = YGNodeNewWithConfig(globalConfig);
|
_node = YGNodeNewWithConfig(globalConfig);
|
||||||
YGNodeSetContext(_node, (__bridge void *) view);
|
YGNodeSetContext(_node, (__bridge void*)view);
|
||||||
_isEnabled = NO;
|
_isEnabled = NO;
|
||||||
_isIncludedInLayout = YES;
|
_isIncludedInLayout = YES;
|
||||||
_isUIView = [view isMemberOfClass:[UIView class]];
|
_isUIView = [view isMemberOfClass:[UIView class]];
|
||||||
@@ -160,18 +191,15 @@ static YGConfigRef globalConfig;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
YGNodeFree(self.node);
|
YGNodeFree(self.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isDirty
|
- (BOOL)isDirty {
|
||||||
{
|
|
||||||
return YGNodeIsDirty(self.node);
|
return YGNodeIsDirty(self.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)markDirty
|
- (void)markDirty {
|
||||||
{
|
|
||||||
if (self.isDirty || !self.isLeaf) {
|
if (self.isDirty || !self.isLeaf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -187,17 +215,17 @@ static YGConfigRef globalConfig;
|
|||||||
YGNodeMarkDirty(node);
|
YGNodeMarkDirty(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger)numberOfChildren
|
- (NSUInteger)numberOfChildren {
|
||||||
{
|
|
||||||
return YGNodeGetChildCount(self.node);
|
return YGNodeGetChildCount(self.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)isLeaf
|
- (BOOL)isLeaf {
|
||||||
{
|
NSAssert(
|
||||||
NSAssert([NSThread isMainThread], @"This method must be called on the main thread.");
|
[NSThread isMainThread],
|
||||||
|
@"This method must be called on the main thread.");
|
||||||
if (self.isEnabled) {
|
if (self.isEnabled) {
|
||||||
for (UIView *subview in self.view.subviews) {
|
for (UIView* subview in self.view.subviews) {
|
||||||
YGLayout *const yoga = subview.yoga;
|
YGLayout* const yoga = subview.yoga;
|
||||||
if (yoga.isEnabled && yoga.isIncludedInLayout) {
|
if (yoga.isEnabled && yoga.isIncludedInLayout) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@@ -209,13 +237,11 @@ static YGConfigRef globalConfig;
|
|||||||
|
|
||||||
#pragma mark - Style
|
#pragma mark - Style
|
||||||
|
|
||||||
- (YGPositionType)position
|
- (YGPositionType)position {
|
||||||
{
|
|
||||||
return YGNodeStyleGetPositionType(self.node);
|
return YGNodeStyleGetPositionType(self.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPosition:(YGPositionType)position
|
- (void)setPosition:(YGPositionType)position {
|
||||||
{
|
|
||||||
YGNodeStyleSetPositionType(self.node, position);
|
YGNodeStyleSetPositionType(self.node, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,25 +287,23 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
|
|||||||
|
|
||||||
#pragma mark - Layout and Sizing
|
#pragma mark - Layout and Sizing
|
||||||
|
|
||||||
- (YGDirection)resolvedDirection
|
- (YGDirection)resolvedDirection {
|
||||||
{
|
|
||||||
return YGNodeLayoutGetDirection(self.node);
|
return YGNodeLayoutGetDirection(self.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applyLayout
|
- (void)applyLayout {
|
||||||
{
|
|
||||||
[self calculateLayoutWithSize:self.view.bounds.size];
|
[self calculateLayoutWithSize:self.view.bounds.size];
|
||||||
YGApplyLayoutToViewHierarchy(self.view, NO);
|
YGApplyLayoutToViewHierarchy(self.view, NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin {
|
||||||
{
|
|
||||||
[self calculateLayoutWithSize:self.view.bounds.size];
|
[self calculateLayoutWithSize:self.view.bounds.size];
|
||||||
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
|
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
|
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
||||||
{
|
dimensionFlexibility:
|
||||||
|
(YGDimensionFlexibility)dimensionFlexibility {
|
||||||
CGSize size = self.view.bounds.size;
|
CGSize size = self.view.bounds.size;
|
||||||
if (dimensionFlexibility & YGDimensionFlexibilityFlexibleWidth) {
|
if (dimensionFlexibility & YGDimensionFlexibilityFlexibleWidth) {
|
||||||
size.width = YGUndefined;
|
size.width = YGUndefined;
|
||||||
@@ -291,9 +315,7 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
|
|||||||
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
|
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (CGSize)intrinsicSize {
|
||||||
- (CGSize)intrinsicSize
|
|
||||||
{
|
|
||||||
const CGSize constrainedSize = {
|
const CGSize constrainedSize = {
|
||||||
.width = YGUndefined,
|
.width = YGUndefined,
|
||||||
.height = YGUndefined,
|
.height = YGUndefined,
|
||||||
@@ -301,8 +323,7 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
|
|||||||
return [self calculateLayoutWithSize:constrainedSize];
|
return [self calculateLayoutWithSize:constrainedSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
- (CGSize)calculateLayoutWithSize:(CGSize)size {
|
||||||
{
|
|
||||||
NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main.");
|
NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main.");
|
||||||
NSAssert(self.isEnabled, @"Yoga is not enabled for this view.");
|
NSAssert(self.isEnabled, @"Yoga is not enabled for this view.");
|
||||||
|
|
||||||
@@ -310,12 +331,9 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
|
|||||||
|
|
||||||
const YGNodeRef node = self.node;
|
const YGNodeRef node = self.node;
|
||||||
YGNodeCalculateLayout(
|
YGNodeCalculateLayout(
|
||||||
node,
|
node, size.width, size.height, YGNodeStyleGetDirection(node));
|
||||||
size.width,
|
|
||||||
size.height,
|
|
||||||
YGNodeStyleGetDirection(node));
|
|
||||||
|
|
||||||
return (CGSize) {
|
return (CGSize){
|
||||||
.width = YGNodeLayoutGetWidth(node),
|
.width = YGNodeLayoutGetWidth(node),
|
||||||
.height = YGNodeLayoutGetHeight(node),
|
.height = YGNodeLayoutGetHeight(node),
|
||||||
};
|
};
|
||||||
@@ -328,12 +346,13 @@ static YGSize YGMeasureView(
|
|||||||
float width,
|
float width,
|
||||||
YGMeasureMode widthMode,
|
YGMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
YGMeasureMode heightMode)
|
YGMeasureMode heightMode) {
|
||||||
{
|
const CGFloat constrainedWidth =
|
||||||
const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
|
(widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
|
||||||
const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height;
|
const CGFloat constrainedHeight =
|
||||||
|
(heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : height;
|
||||||
|
|
||||||
UIView *view = (__bridge UIView*) YGNodeGetContext(node);
|
UIView* view = (__bridge UIView*)YGNodeGetContext(node);
|
||||||
CGSize sizeThatFits = CGSizeZero;
|
CGSize sizeThatFits = CGSizeZero;
|
||||||
|
|
||||||
// The default implementation of sizeThatFits: returns the existing size of
|
// The default implementation of sizeThatFits: returns the existing size of
|
||||||
@@ -349,17 +368,18 @@ static YGSize YGMeasureView(
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
return (YGSize) {
|
return (YGSize){
|
||||||
.width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
|
.width = YGSanitizeMeasurement(
|
||||||
.height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
|
constrainedWidth, sizeThatFits.width, widthMode),
|
||||||
|
.height = YGSanitizeMeasurement(
|
||||||
|
constrainedHeight, sizeThatFits.height, heightMode),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat YGSanitizeMeasurement(
|
static CGFloat YGSanitizeMeasurement(
|
||||||
CGFloat constrainedSize,
|
CGFloat constrainedSize,
|
||||||
CGFloat measuredSize,
|
CGFloat measuredSize,
|
||||||
YGMeasureMode measureMode)
|
YGMeasureMode measureMode) {
|
||||||
{
|
|
||||||
CGFloat result;
|
CGFloat result;
|
||||||
if (measureMode == YGMeasureModeExactly) {
|
if (measureMode == YGMeasureModeExactly) {
|
||||||
result = constrainedSize;
|
result = constrainedSize;
|
||||||
@@ -372,13 +392,14 @@ static CGFloat YGSanitizeMeasurement(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *subviews)
|
static BOOL YGNodeHasExactSameChildren(
|
||||||
{
|
const YGNodeRef node,
|
||||||
|
NSArray<UIView*>* subviews) {
|
||||||
if (YGNodeGetChildCount(node) != subviews.count) {
|
if (YGNodeGetChildCount(node) != subviews.count) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<subviews.count; i++) {
|
for (int i = 0; i < subviews.count; i++) {
|
||||||
if (YGNodeGetChild(node, i) != subviews[i].yoga.node) {
|
if (YGNodeGetChild(node, i) != subviews[i].yoga.node) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
@@ -387,9 +408,8 @@ static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGAttachNodesFromViewHierachy(UIView *const view)
|
static void YGAttachNodesFromViewHierachy(UIView* const view) {
|
||||||
{
|
YGLayout* const yoga = view.yoga;
|
||||||
YGLayout *const yoga = view.yoga;
|
|
||||||
const YGNodeRef node = yoga.node;
|
const YGNodeRef node = yoga.node;
|
||||||
|
|
||||||
// Only leaf nodes should have a measure function
|
// Only leaf nodes should have a measure function
|
||||||
@@ -399,8 +419,9 @@ static void YGAttachNodesFromViewHierachy(UIView *const view)
|
|||||||
} else {
|
} else {
|
||||||
YGNodeSetMeasureFunc(node, NULL);
|
YGNodeSetMeasureFunc(node, NULL);
|
||||||
|
|
||||||
NSMutableArray<UIView *> *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count];
|
NSMutableArray<UIView*>* subviewsToInclude =
|
||||||
for (UIView *subview in view.subviews) {
|
[[NSMutableArray alloc] initWithCapacity:view.subviews.count];
|
||||||
|
for (UIView* subview in view.subviews) {
|
||||||
if (subview.yoga.isEnabled && subview.yoga.isIncludedInLayout) {
|
if (subview.yoga.isEnabled && subview.yoga.isIncludedInLayout) {
|
||||||
[subviewsToInclude addObject:subview];
|
[subviewsToInclude addObject:subview];
|
||||||
}
|
}
|
||||||
@@ -408,19 +429,18 @@ static void YGAttachNodesFromViewHierachy(UIView *const view)
|
|||||||
|
|
||||||
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
|
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
|
||||||
YGRemoveAllChildren(node);
|
YGRemoveAllChildren(node);
|
||||||
for (int i=0; i<subviewsToInclude.count; i++) {
|
for (int i = 0; i < subviewsToInclude.count; i++) {
|
||||||
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i);
|
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UIView *const subview in subviewsToInclude) {
|
for (UIView* const subview in subviewsToInclude) {
|
||||||
YGAttachNodesFromViewHierachy(subview);
|
YGAttachNodesFromViewHierachy(subview);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGRemoveAllChildren(const YGNodeRef node)
|
static void YGRemoveAllChildren(const YGNodeRef node) {
|
||||||
{
|
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -428,22 +448,22 @@ static void YGRemoveAllChildren(const YGNodeRef node)
|
|||||||
YGNodeRemoveAllChildren(node);
|
YGNodeRemoveAllChildren(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat YGRoundPixelValue(CGFloat value)
|
static CGFloat YGRoundPixelValue(CGFloat value) {
|
||||||
{
|
|
||||||
static CGFloat scale;
|
static CGFloat scale;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^(){
|
dispatch_once(&onceToken, ^() {
|
||||||
scale = [UIScreen mainScreen].scale;
|
scale = [UIScreen mainScreen].scale;
|
||||||
});
|
});
|
||||||
|
|
||||||
return roundf(value * scale) / scale;
|
return roundf(value * scale) / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)
|
static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
|
||||||
{
|
NSCAssert(
|
||||||
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
|
[NSThread isMainThread],
|
||||||
|
@"Framesetting should only be done on the main thread.");
|
||||||
|
|
||||||
const YGLayout *yoga = view.yoga;
|
const YGLayout* yoga = view.yoga;
|
||||||
|
|
||||||
if (!yoga.isIncludedInLayout) {
|
if (!yoga.isIncludedInLayout) {
|
||||||
return;
|
return;
|
||||||
@@ -461,19 +481,23 @@ static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
|
const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
|
||||||
view.frame = (CGRect) {
|
view.frame = (CGRect){
|
||||||
.origin = {
|
.origin =
|
||||||
|
{
|
||||||
.x = YGRoundPixelValue(topLeft.x + origin.x),
|
.x = YGRoundPixelValue(topLeft.x + origin.x),
|
||||||
.y = YGRoundPixelValue(topLeft.y + origin.y),
|
.y = YGRoundPixelValue(topLeft.y + origin.y),
|
||||||
},
|
},
|
||||||
.size = {
|
.size =
|
||||||
.width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x),
|
{
|
||||||
.height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y),
|
.width = YGRoundPixelValue(bottomRight.x) -
|
||||||
|
YGRoundPixelValue(topLeft.x),
|
||||||
|
.height = YGRoundPixelValue(bottomRight.y) -
|
||||||
|
YGRoundPixelValue(topLeft.y),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!yoga.isLeaf) {
|
if (!yoga.isLeaf) {
|
||||||
for (NSUInteger i=0; i<view.subviews.count; i++) {
|
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
||||||
YGApplyLayoutToViewHierarchy(view.subviews[i], NO);
|
YGApplyLayoutToViewHierarchy(view.subviews[i], NO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,17 +16,15 @@
|
|||||||
|
|
||||||
@implementation YogaKitTests
|
@implementation YogaKitTests
|
||||||
|
|
||||||
- (void)testConfigureLayoutIsNoOpWithNilBlock
|
- (void)testConfigureLayoutIsNoOpWithNilBlock {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
id block = nil;
|
id block = nil;
|
||||||
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
|
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testConfigureLayoutBlockWorksWithValidBlock
|
- (void)testConfigureLayoutBlockWorksWithValidBlock {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
[view configureLayoutWithBlock:^(YGLayout* layout) {
|
||||||
[view configureLayoutWithBlock:^(YGLayout *layout){
|
|
||||||
XCTAssertNotNil(layout);
|
XCTAssertNotNil(layout);
|
||||||
layout.isEnabled = YES;
|
layout.isEnabled = YES;
|
||||||
layout.width = YGPointValue(25);
|
layout.width = YGPointValue(25);
|
||||||
@@ -36,12 +34,11 @@
|
|||||||
XCTAssertEqual(view.yoga.width.value, 25);
|
XCTAssertEqual(view.yoga.width.value, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testNodesAreDeallocedWithSingleView
|
- (void)testNodesAreDeallocedWithSingleView {
|
||||||
{
|
__weak YGLayout* layoutRef = nil;
|
||||||
__weak YGLayout *layoutRef = nil;
|
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
view.yoga.flexBasis = YGPointValue(1);
|
view.yoga.flexBasis = YGPointValue(1);
|
||||||
|
|
||||||
layoutRef = view.yoga;
|
layoutRef = view.yoga;
|
||||||
@@ -53,17 +50,16 @@
|
|||||||
XCTAssertNil(layoutRef);
|
XCTAssertNil(layoutRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testNodesAreDeallocedCascade
|
- (void)testNodesAreDeallocedCascade {
|
||||||
{
|
__weak YGLayout* topLayout = nil;
|
||||||
__weak YGLayout *topLayout = nil;
|
__weak YGLayout* subviewLayout = nil;
|
||||||
__weak YGLayout *subviewLayout = nil;
|
|
||||||
|
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
topLayout = view.yoga;
|
topLayout = view.yoga;
|
||||||
topLayout.flexBasis = YGPointValue(1);
|
topLayout.flexBasis = YGPointValue(1);
|
||||||
|
|
||||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subviewLayout = subview.yoga;
|
subviewLayout = subview.yoga;
|
||||||
subviewLayout.flexBasis = YGPointValue(1);
|
subviewLayout.flexBasis = YGPointValue(1);
|
||||||
|
|
||||||
@@ -74,9 +70,8 @@
|
|||||||
XCTAssertNil(subviewLayout);
|
XCTAssertNil(subviewLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testIsEnabled
|
- (void)testIsEnabled {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
XCTAssertFalse(view.yoga.isEnabled);
|
XCTAssertFalse(view.yoga.isEnabled);
|
||||||
|
|
||||||
view.yoga.isEnabled = YES;
|
view.yoga.isEnabled = YES;
|
||||||
@@ -86,30 +81,31 @@
|
|||||||
XCTAssertFalse(view.yoga.isEnabled);
|
XCTAssertFalse(view.yoga.isEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSizeThatFitsAsserts
|
- (void)testSizeThatFitsAsserts {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
dispatch_sync(
|
||||||
dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){
|
dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL),
|
||||||
|
^(void) {
|
||||||
XCTAssertThrows(view.yoga.intrinsicSize);
|
XCTAssertThrows(view.yoga.intrinsicSize);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSizeThatFitsSmoke
|
- (void)testSizeThatFitsSmoke {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
container.yoga.alignItems = YGAlignFlexStart;
|
container.yoga.alignItems = YGAlignFlexStart;
|
||||||
|
|
||||||
UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
UILabel* longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||||
longTextLabel.text = @"This is a very very very very very very very very long piece of text.";
|
longTextLabel.text =
|
||||||
|
@"This is a very very very very very very very very long piece of text.";
|
||||||
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||||
longTextLabel.numberOfLines = 1;
|
longTextLabel.numberOfLines = 1;
|
||||||
longTextLabel.yoga.isEnabled = YES;
|
longTextLabel.yoga.isEnabled = YES;
|
||||||
longTextLabel.yoga.flexShrink = 1;
|
longTextLabel.yoga.flexShrink = 1;
|
||||||
[container addSubview:longTextLabel];
|
[container addSubview:longTextLabel];
|
||||||
|
|
||||||
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
textBadgeView.yoga.isEnabled = YES;
|
textBadgeView.yoga.isEnabled = YES;
|
||||||
textBadgeView.yoga.margin = YGPointValue(0);
|
textBadgeView.yoga.margin = YGPointValue(0);
|
||||||
textBadgeView.yoga.width = YGPointValue(10);
|
textBadgeView.yoga.width = YGPointValue(10);
|
||||||
@@ -124,7 +120,9 @@
|
|||||||
const CGSize longTextLabelSize = longTextLabel.yoga.intrinsicSize;
|
const CGSize longTextLabelSize = longTextLabel.yoga.intrinsicSize;
|
||||||
|
|
||||||
XCTAssertEqual(longTextLabelSize.height, containerSize.height);
|
XCTAssertEqual(longTextLabelSize.height, containerSize.height);
|
||||||
XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width);
|
XCTAssertEqual(
|
||||||
|
longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width,
|
||||||
|
containerSize.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSizeThatFitsEmptyView {
|
- (void)testSizeThatFitsEmptyView {
|
||||||
@@ -136,18 +134,17 @@
|
|||||||
XCTAssertEqual(viewSize.width, 0);
|
XCTAssertEqual(viewSize.width, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testPreservingOrigin
|
- (void)testPreservingOrigin {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 75)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
|
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
view.yoga.isEnabled = YES;
|
view.yoga.isEnabled = YES;
|
||||||
view.yoga.flexBasis = YGPointValue(0);
|
view.yoga.flexBasis = YGPointValue(0);
|
||||||
view.yoga.flexGrow = 1;
|
view.yoga.flexGrow = 1;
|
||||||
[container addSubview:view];
|
[container addSubview:view];
|
||||||
|
|
||||||
UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* view2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
view2.yoga.isEnabled = YES;
|
view2.yoga.isEnabled = YES;
|
||||||
view2.yoga.marginTop = YGPointValue(25);
|
view2.yoga.marginTop = YGPointValue(25);
|
||||||
view2.yoga.flexBasis = YGPointValue(0);
|
view2.yoga.flexBasis = YGPointValue(0);
|
||||||
@@ -161,28 +158,28 @@
|
|||||||
XCTAssertEqual(25, view2.frame.origin.y);
|
XCTAssertEqual(25, view2.frame.origin.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testContainerWithFlexibleWidthGetsCorrectlySized
|
- (void)testContainerWithFlexibleWidthGetsCorrectlySized {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
|
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||||
view.yoga.isEnabled = YES;
|
view.yoga.isEnabled = YES;
|
||||||
view.yoga.width = YGPointValue(100);
|
view.yoga.width = YGPointValue(100);
|
||||||
view.yoga.height = YGPointValue(100);
|
view.yoga.height = YGPointValue(100);
|
||||||
[container addSubview:view];
|
[container addSubview:view];
|
||||||
|
|
||||||
[container.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleWidth];
|
[container.yoga
|
||||||
|
applyLayoutPreservingOrigin:YES
|
||||||
|
dimensionFlexibility:YGDimensionFlexibilityFlexibleWidth];
|
||||||
XCTAssertEqual(100, container.frame.size.width);
|
XCTAssertEqual(100, container.frame.size.width);
|
||||||
XCTAssertEqual(200, container.frame.size.height);
|
XCTAssertEqual(200, container.frame.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testContainerWithFlexibleHeightGetsCorrectlySized
|
- (void)testContainerWithFlexibleHeightGetsCorrectlySized {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
|
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||||
view.yoga.isEnabled = YES;
|
view.yoga.isEnabled = YES;
|
||||||
view.yoga.width = YGPointValue(100);
|
view.yoga.width = YGPointValue(100);
|
||||||
view.yoga.height = YGPointValue(100);
|
view.yoga.height = YGPointValue(100);
|
||||||
@@ -195,12 +192,11 @@
|
|||||||
XCTAssertEqual(100, container.frame.size.height);
|
XCTAssertEqual(100, container.frame.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testContainerWithFlexibleWidthAndHeightGetsCorrectlySized
|
- (void)testContainerWithFlexibleWidthAndHeightGetsCorrectlySized {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
|
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||||
view.yoga.isEnabled = YES;
|
view.yoga.isEnabled = YES;
|
||||||
view.yoga.width = YGPointValue(100);
|
view.yoga.width = YGPointValue(100);
|
||||||
view.yoga.height = YGPointValue(100);
|
view.yoga.height = YGPointValue(100);
|
||||||
@@ -214,12 +210,11 @@
|
|||||||
XCTAssertEqual(100, container.frame.size.height);
|
XCTAssertEqual(100, container.frame.size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testMarkingDirtyOnlyWorksOnLeafNodes
|
- (void)testMarkingDirtyOnlyWorksOnLeafNodes {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
|
|
||||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview.yoga.isEnabled = YES;
|
subview.yoga.isEnabled = YES;
|
||||||
[container addSubview:subview];
|
[container addSubview:subview];
|
||||||
|
|
||||||
@@ -232,14 +227,13 @@
|
|||||||
XCTAssertTrue(subview.yoga.isDirty);
|
XCTAssertTrue(subview.yoga.isDirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation
|
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
container.yoga.alignItems = YGAlignFlexStart;
|
container.yoga.alignItems = YGAlignFlexStart;
|
||||||
|
|
||||||
UILabel *view = [[UILabel alloc] initWithFrame:CGRectZero];
|
UILabel* view = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||||
view.text = @"This is a short text.";
|
view.text = @"This is a short text.";
|
||||||
view.numberOfLines = 1;
|
view.numberOfLines = 1;
|
||||||
view.yoga.isEnabled = YES;
|
view.yoga.isEnabled = YES;
|
||||||
@@ -257,61 +251,70 @@
|
|||||||
XCTAssertFalse(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass));
|
XCTAssertFalse(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testFrameAndOriginPlacement
|
- (void)testFrameAndOriginPlacement {
|
||||||
{
|
|
||||||
const CGSize containerSize = CGSizeMake(320, 50);
|
const CGSize containerSize = CGSizeMake(320, 50);
|
||||||
|
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
|
UIView* container = [[UIView alloc]
|
||||||
|
initWithFrame:CGRectMake(
|
||||||
|
0, 0, containerSize.width, containerSize.height)];
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
subview1.yoga.flexGrow = 1;
|
subview1.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
subview2.yoga.flexGrow = 1;
|
subview2.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview3.yoga.isEnabled = YES;
|
subview3.yoga.isEnabled = YES;
|
||||||
subview3.yoga.flexGrow = 1;
|
subview3.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
|
|
||||||
[container.yoga applyLayoutPreservingOrigin:YES];
|
[container.yoga applyLayoutPreservingOrigin:YES];
|
||||||
|
|
||||||
XCTAssertEqualWithAccuracy(subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
|
XCTAssertEqualWithAccuracy(
|
||||||
XCTAssertEqualWithAccuracy(subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
|
subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
|
||||||
|
XCTAssertEqualWithAccuracy(
|
||||||
|
subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
|
||||||
|
|
||||||
CGFloat totalWidth = 0;
|
CGFloat totalWidth = 0;
|
||||||
for (UIView *view in container.subviews) {
|
for (UIView* view in container.subviews) {
|
||||||
totalWidth += view.bounds.size.width;
|
totalWidth += view.bounds.size.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth);
|
XCTAssertEqual(
|
||||||
|
containerSize.width,
|
||||||
|
totalWidth,
|
||||||
|
@"The container's width is %.6f, the subviews take up %.6f",
|
||||||
|
containerSize.width,
|
||||||
|
totalWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder
|
- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder {
|
||||||
{
|
|
||||||
const CGSize containerSize = CGSizeMake(300, 50);
|
const CGSize containerSize = CGSizeMake(300, 50);
|
||||||
|
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
|
UIView* container = [[UIView alloc]
|
||||||
|
initWithFrame:CGRectMake(
|
||||||
|
0, 0, containerSize.width, containerSize.height)];
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
subview1.yoga.flexGrow = 1;
|
subview1.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
subview2.yoga.flexGrow = 1;
|
subview2.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview3.yoga.isEnabled = YES;
|
subview3.yoga.isEnabled = YES;
|
||||||
subview3.yoga.flexGrow = 1;
|
subview3.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
@@ -333,32 +336,33 @@
|
|||||||
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
|
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatWeRespectIncludeInLayoutFlag
|
- (void)testThatWeRespectIncludeInLayoutFlag {
|
||||||
{
|
|
||||||
const CGSize containerSize = CGSizeMake(300, 50);
|
const CGSize containerSize = CGSizeMake(300, 50);
|
||||||
|
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
|
UIView* container = [[UIView alloc]
|
||||||
|
initWithFrame:CGRectMake(
|
||||||
|
0, 0, containerSize.width, containerSize.height)];
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
subview1.yoga.flexGrow = 1;
|
subview1.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
subview2.yoga.flexGrow = 1;
|
subview2.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview3.yoga.isEnabled = YES;
|
subview3.yoga.isEnabled = YES;
|
||||||
subview3.yoga.flexGrow = 1;
|
subview3.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
|
|
||||||
[container.yoga applyLayoutPreservingOrigin:YES];
|
[container.yoga applyLayoutPreservingOrigin:YES];
|
||||||
|
|
||||||
for (UIView *subview in container.subviews) {
|
for (UIView* subview in container.subviews) {
|
||||||
XCTAssertEqual(subview.bounds.size.width, 100);
|
XCTAssertEqual(subview.bounds.size.width, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,27 +372,27 @@
|
|||||||
XCTAssertEqual(subview1.bounds.size.width, 150);
|
XCTAssertEqual(subview1.bounds.size.width, 150);
|
||||||
XCTAssertEqual(subview2.bounds.size.width, 150);
|
XCTAssertEqual(subview2.bounds.size.width, 150);
|
||||||
|
|
||||||
// We don't set the frame to zero, so, it should be set to what it was previously at.
|
// We don't set the frame to zero, so, it should be set to what it was
|
||||||
|
// previously at.
|
||||||
XCTAssertEqual(subview3.bounds.size.width, 100);
|
XCTAssertEqual(subview3.bounds.size.width, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
|
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
subview1.yoga.isIncludedInLayout = NO;
|
subview1.yoga.isIncludedInLayout = NO;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
subview2.yoga.isIncludedInLayout = NO;
|
subview2.yoga.isIncludedInLayout = NO;
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview3.yoga.isEnabled = YES;
|
subview3.yoga.isEnabled = YES;
|
||||||
subview3.yoga.isIncludedInLayout = YES;
|
subview3.yoga.isIncludedInLayout = YES;
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
@@ -401,23 +405,22 @@
|
|||||||
XCTAssertEqual(container.yoga.numberOfChildren, 2);
|
XCTAssertEqual(container.yoga.numberOfChildren, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
|
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionRow;
|
container.yoga.flexDirection = YGFlexDirectionRow;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
subview1.yoga.flexGrow = 1;
|
subview1.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
subview2.yoga.flexGrow = 1;
|
subview2.yoga.flexGrow = 1;
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview3.yoga.isEnabled = YES;
|
subview3.yoga.isEnabled = YES;
|
||||||
subview3.yoga.flexGrow = 1;
|
subview3.yoga.flexGrow = 1;
|
||||||
subview3.yoga.isIncludedInLayout = NO;
|
subview3.yoga.isIncludedInLayout = NO;
|
||||||
@@ -437,13 +440,12 @@
|
|||||||
XCTAssertEqual(subview3.bounds.size.width, 100);
|
XCTAssertEqual(subview3.bounds.size.width, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testIsLeafFlag
|
- (void)testIsLeafFlag {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
XCTAssertTrue(view.yoga.isLeaf);
|
XCTAssertTrue(view.yoga.isLeaf);
|
||||||
|
|
||||||
for (int i=0; i<10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[view addSubview:subview];
|
[view addSubview:subview];
|
||||||
}
|
}
|
||||||
XCTAssertTrue(view.yoga.isLeaf);
|
XCTAssertTrue(view.yoga.isLeaf);
|
||||||
@@ -452,34 +454,33 @@
|
|||||||
view.yoga.width = YGPointValue(50);
|
view.yoga.width = YGPointValue(50);
|
||||||
XCTAssertTrue(view.yoga.isLeaf);
|
XCTAssertTrue(view.yoga.isLeaf);
|
||||||
|
|
||||||
UIView *const subview = view.subviews[0];
|
UIView* const subview = view.subviews[0];
|
||||||
subview.yoga.isEnabled = YES;
|
subview.yoga.isEnabled = YES;
|
||||||
subview.yoga.width = YGPointValue(50);
|
subview.yoga.width = YGPointValue(50);
|
||||||
XCTAssertFalse(view.yoga.isLeaf);
|
XCTAssertFalse(view.yoga.isLeaf);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatWeCorrectlyAttachNestedViews
|
- (void)testThatWeCorrectlyAttachNestedViews {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
container.yoga.flexDirection = YGFlexDirectionColumn;
|
container.yoga.flexDirection = YGFlexDirectionColumn;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
subview1.yoga.width = YGPointValue(100);
|
subview1.yoga.width = YGPointValue(100);
|
||||||
subview1.yoga.flexGrow = 1;
|
subview1.yoga.flexGrow = 1;
|
||||||
subview1.yoga.flexDirection = YGFlexDirectionColumn;
|
subview1.yoga.flexDirection = YGFlexDirectionColumn;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
subview2.yoga.width = YGPointValue(150);
|
subview2.yoga.width = YGPointValue(150);
|
||||||
subview2.yoga.flexGrow = 1;
|
subview2.yoga.flexGrow = 1;
|
||||||
subview2.yoga.flexDirection = YGFlexDirectionColumn;
|
subview2.yoga.flexDirection = YGFlexDirectionColumn;
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
for (UIView *view in @[subview1, subview2]) {
|
for (UIView* view in @[ subview1, subview2 ]) {
|
||||||
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* someView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
someView.yoga.isEnabled = YES;
|
someView.yoga.isEnabled = YES;
|
||||||
someView.yoga.flexGrow = 1;
|
someView.yoga.flexGrow = 1;
|
||||||
[view addSubview:someView];
|
[view addSubview:someView];
|
||||||
@@ -487,8 +488,8 @@
|
|||||||
[container.yoga applyLayoutPreservingOrigin:YES];
|
[container.yoga applyLayoutPreservingOrigin:YES];
|
||||||
|
|
||||||
// Add the same amount of new views, reapply layout.
|
// Add the same amount of new views, reapply layout.
|
||||||
for (UIView *view in @[subview1, subview2]) {
|
for (UIView* view in @[ subview1, subview2 ]) {
|
||||||
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* someView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
someView.yoga.isEnabled = YES;
|
someView.yoga.isEnabled = YES;
|
||||||
someView.yoga.flexGrow = 1;
|
someView.yoga.flexGrow = 1;
|
||||||
[view addSubview:someView];
|
[view addSubview:someView];
|
||||||
@@ -497,7 +498,7 @@
|
|||||||
|
|
||||||
XCTAssertEqual(subview1.bounds.size.width, 100);
|
XCTAssertEqual(subview1.bounds.size.width, 100);
|
||||||
XCTAssertEqual(subview1.bounds.size.height, 25);
|
XCTAssertEqual(subview1.bounds.size.height, 25);
|
||||||
for (UIView *subview in subview1.subviews) {
|
for (UIView* subview in subview1.subviews) {
|
||||||
const CGSize subviewSize = subview.bounds.size;
|
const CGSize subviewSize = subview.bounds.size;
|
||||||
XCTAssertNotEqual(subviewSize.width, 0);
|
XCTAssertNotEqual(subviewSize.width, 0);
|
||||||
XCTAssertNotEqual(subviewSize.height, 0);
|
XCTAssertNotEqual(subviewSize.height, 0);
|
||||||
@@ -507,7 +508,7 @@
|
|||||||
|
|
||||||
XCTAssertEqual(subview2.bounds.size.width, 150);
|
XCTAssertEqual(subview2.bounds.size.width, 150);
|
||||||
XCTAssertEqual(subview2.bounds.size.height, 25);
|
XCTAssertEqual(subview2.bounds.size.height, 25);
|
||||||
for (UIView *subview in subview2.subviews) {
|
for (UIView* subview in subview2.subviews) {
|
||||||
const CGSize subviewSize = subview.bounds.size;
|
const CGSize subviewSize = subview.bounds.size;
|
||||||
XCTAssertNotEqual(subviewSize.width, 0);
|
XCTAssertNotEqual(subviewSize.width, 0);
|
||||||
XCTAssertNotEqual(subviewSize.height, 0);
|
XCTAssertNotEqual(subviewSize.height, 0);
|
||||||
@@ -516,16 +517,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testThatANonLeafNodeCanBecomeALeafNode
|
- (void)testThatANonLeafNodeCanBecomeALeafNode {
|
||||||
{
|
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
|
|
||||||
container.yoga.isEnabled = YES;
|
container.yoga.isEnabled = YES;
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview1.yoga.isEnabled = YES;
|
subview1.yoga.isEnabled = YES;
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
subview2.yoga.isEnabled = YES;
|
subview2.yoga.isEnabled = YES;
|
||||||
[subview1 addSubview:subview2];
|
[subview1 addSubview:subview2];
|
||||||
|
|
||||||
@@ -534,17 +534,15 @@
|
|||||||
[container.yoga applyLayoutPreservingOrigin:YES];
|
[container.yoga applyLayoutPreservingOrigin:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testPointPercent
|
- (void)testPointPercent {
|
||||||
{
|
|
||||||
XCTAssertEqual(YGPointValue(1).value, 1);
|
XCTAssertEqual(YGPointValue(1).value, 1);
|
||||||
XCTAssertEqual(YGPointValue(1).unit, YGUnitPoint);
|
XCTAssertEqual(YGPointValue(1).unit, YGUnitPoint);
|
||||||
XCTAssertEqual(YGPercentValue(2).value, 2);
|
XCTAssertEqual(YGPercentValue(2).value, 2);
|
||||||
XCTAssertEqual(YGPercentValue(2).unit, YGUnitPercent);
|
XCTAssertEqual(YGPercentValue(2).unit, YGUnitPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testPositionalPropertiesWork
|
- (void)testPositionalPropertiesWork {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
|
|
||||||
view.yoga.left = YGPointValue(1);
|
view.yoga.left = YGPointValue(1);
|
||||||
XCTAssertEqual(view.yoga.left.value, 1);
|
XCTAssertEqual(view.yoga.left.value, 1);
|
||||||
@@ -589,9 +587,8 @@
|
|||||||
XCTAssertEqual(view.yoga.end.unit, YGUnitPercent);
|
XCTAssertEqual(view.yoga.end.unit, YGUnitPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testMarginPropertiesWork
|
- (void)testMarginPropertiesWork {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
|
|
||||||
view.yoga.margin = YGPointValue(1);
|
view.yoga.margin = YGPointValue(1);
|
||||||
XCTAssertEqual(view.yoga.margin.value, 1);
|
XCTAssertEqual(view.yoga.margin.value, 1);
|
||||||
@@ -657,9 +654,8 @@
|
|||||||
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPercent);
|
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testPaddingPropertiesWork
|
- (void)testPaddingPropertiesWork {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
|
|
||||||
view.yoga.padding = YGPointValue(1);
|
view.yoga.padding = YGPointValue(1);
|
||||||
XCTAssertEqual(view.yoga.padding.value, 1);
|
XCTAssertEqual(view.yoga.padding.value, 1);
|
||||||
@@ -725,9 +721,8 @@
|
|||||||
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPercent);
|
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testBorderWidthPropertiesWork
|
- (void)testBorderWidthPropertiesWork {
|
||||||
{
|
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
|
||||||
|
|
||||||
view.yoga.borderWidth = 1;
|
view.yoga.borderWidth = 1;
|
||||||
XCTAssertEqual(view.yoga.borderWidth, 1);
|
XCTAssertEqual(view.yoga.borderWidth, 1);
|
||||||
|
@@ -11,9 +11,8 @@
|
|||||||
|
|
||||||
@implementation ViewController
|
@implementation ViewController
|
||||||
|
|
||||||
- (void)viewDidLoad
|
- (void)viewDidLoad {
|
||||||
{
|
UIView* root = self.view;
|
||||||
UIView *root = self.view;
|
|
||||||
root.backgroundColor = [UIColor redColor];
|
root.backgroundColor = [UIColor redColor];
|
||||||
root.yoga.isEnabled = YES;
|
root.yoga.isEnabled = YES;
|
||||||
root.yoga.width = YGPointValue(self.view.bounds.size.width);
|
root.yoga.width = YGPointValue(self.view.bounds.size.width);
|
||||||
@@ -21,29 +20,25 @@
|
|||||||
root.yoga.alignItems = YGAlignCenter;
|
root.yoga.alignItems = YGAlignCenter;
|
||||||
root.yoga.justifyContent = YGJustifyCenter;
|
root.yoga.justifyContent = YGJustifyCenter;
|
||||||
|
|
||||||
UIView *child1 = [UIView new];
|
UIView* child1 = [UIView new];
|
||||||
child1.backgroundColor = [UIColor blueColor];
|
child1.backgroundColor = [UIColor blueColor];
|
||||||
child1.yoga.isEnabled = YES;
|
child1.yoga.isEnabled = YES;
|
||||||
child1.yoga.width = YGPointValue(100);
|
child1.yoga.width = YGPointValue(100);
|
||||||
child1.yoga.height = YGPointValue(100);
|
child1.yoga.height = YGPointValue(100);
|
||||||
|
|
||||||
UIView *child2 = [UIView new];
|
UIView* child2 = [UIView new];
|
||||||
child2.backgroundColor = [UIColor greenColor];
|
child2.backgroundColor = [UIColor greenColor];
|
||||||
child2.frame = (CGRect) {
|
child2.frame = (CGRect){.size = {
|
||||||
.size = {
|
|
||||||
.width = 200,
|
.width = 200,
|
||||||
.height = 100,
|
.height = 100,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
UIView *child3 = [UIView new];
|
UIView* child3 = [UIView new];
|
||||||
child3.backgroundColor = [UIColor yellowColor];
|
child3.backgroundColor = [UIColor yellowColor];
|
||||||
child3.frame = (CGRect) {
|
child3.frame = (CGRect){.size = {
|
||||||
.size = {
|
|
||||||
.width = 100,
|
.width = 100,
|
||||||
.height = 100,
|
.height = 100,
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
[child2 addSubview:child3];
|
[child2 addSubview:child3];
|
||||||
[root addSubview:child1];
|
[root addSubview:child1];
|
||||||
@@ -51,5 +46,4 @@
|
|||||||
[root.yoga applyLayoutPreservingOrigin:NO];
|
[root.yoga applyLayoutPreservingOrigin:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -9,10 +9,11 @@
|
|||||||
|
|
||||||
static YGInteropLogger gManagedLogger;
|
static YGInteropLogger gManagedLogger;
|
||||||
|
|
||||||
static int unmanagedLogger(const YGConfigRef config,
|
static int unmanagedLogger(
|
||||||
|
const YGConfigRef config,
|
||||||
const YGNodeRef node,
|
const YGNodeRef node,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char *format,
|
const char* format,
|
||||||
va_list args) {
|
va_list args) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (gManagedLogger) {
|
if (gManagedLogger) {
|
||||||
|
@@ -11,10 +11,11 @@
|
|||||||
|
|
||||||
YG_EXTERN_C_BEGIN
|
YG_EXTERN_C_BEGIN
|
||||||
|
|
||||||
typedef int (*YGInteropLogger)(const void *unmanagedConfigPtr,
|
typedef int (*YGInteropLogger)(
|
||||||
const void *unmanagedNodePtr,
|
const void* unmanagedConfigPtr,
|
||||||
|
const void* unmanagedNodePtr,
|
||||||
YGLogLevel level,
|
YGLogLevel level,
|
||||||
const char *message);
|
const char* message);
|
||||||
|
|
||||||
WIN_EXPORT YGConfigRef YGConfigGetDefault();
|
WIN_EXPORT YGConfigRef YGConfigGetDefault();
|
||||||
|
|
||||||
|
@@ -8,7 +8,8 @@
|
|||||||
// dllmain.cpp : Defines the entry point for the DLL application.
|
// dllmain.cpp : Defines the entry point for the DLL application.
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
BOOL APIENTRY
|
||||||
|
DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
||||||
switch (ul_reason_for_call) {
|
switch (ul_reason_for_call) {
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
case DLL_THREAD_ATTACH:
|
case DLL_THREAD_ATTACH:
|
||||||
|
@@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
// Including SDKDDKVer.h defines the highest available Windows platform.
|
// Including SDKDDKVer.h defines the highest available Windows platform.
|
||||||
|
|
||||||
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
|
// If you wish to build your application for a previous Windows platform,
|
||||||
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
|
// include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you wish
|
||||||
|
// to support before including SDKDDKVer.h.
|
||||||
|
|
||||||
#include <SDKDDKVer.h>
|
#include <SDKDDKVer.h>
|
||||||
|
@@ -84,9 +84,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScopedGlobalRef() {
|
~ScopedGlobalRef() { reset(); }
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the currently held reference and reassigns a new one to the
|
* Deletes the currently held reference and reassigns a new one to the
|
||||||
@@ -120,9 +118,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Returns true if the underlying JNI reference is not NULL.
|
* Returns true if the underlying JNI reference is not NULL.
|
||||||
*/
|
*/
|
||||||
operator bool() const {
|
operator bool() const { return mGlobalRef != NULL; }
|
||||||
return mGlobalRef != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedGlobalRef(const ScopedGlobalRef& ref) = delete;
|
ScopedGlobalRef(const ScopedGlobalRef& ref) = delete;
|
||||||
ScopedGlobalRef& operator=(const ScopedGlobalRef& other) = delete;
|
ScopedGlobalRef& operator=(const ScopedGlobalRef& other) = delete;
|
||||||
|
@@ -83,9 +83,7 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~ScopedLocalRef() {
|
~ScopedLocalRef() { reset(); }
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the currently held reference and reassigns a new one to the
|
* Deletes the currently held reference and reassigns a new one to the
|
||||||
@@ -119,9 +117,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Returns true if the underlying JNI reference is not NULL.
|
* Returns true if the underlying JNI reference is not NULL.
|
||||||
*/
|
*/
|
||||||
operator bool() const {
|
operator bool() const { return mLocalRef != NULL; }
|
||||||
return mLocalRef != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedLocalRef(const ScopedLocalRef& ref) = delete;
|
ScopedLocalRef(const ScopedLocalRef& ref) = delete;
|
||||||
ScopedLocalRef& operator=(const ScopedLocalRef& other) = delete;
|
ScopedLocalRef& operator=(const ScopedLocalRef& other) = delete;
|
||||||
|
@@ -77,8 +77,11 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void) {
|
|||||||
assertNoPendingJniException(env);
|
assertNoPendingJniException(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedLocalRef<jobject>
|
ScopedLocalRef<jobject> callStaticObjectMethod(
|
||||||
callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...) {
|
JNIEnv* env,
|
||||||
|
jclass clazz,
|
||||||
|
jmethodID methodId,
|
||||||
|
...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, methodId);
|
va_start(args, methodId);
|
||||||
jobject result = env->CallStaticObjectMethodV(clazz, methodId, args);
|
jobject result = env->CallStaticObjectMethodV(clazz, methodId, args);
|
||||||
|
@@ -61,8 +61,11 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void);
|
|||||||
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jlong, Long);
|
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jlong, Long);
|
||||||
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jfloat, Float);
|
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jfloat, Float);
|
||||||
|
|
||||||
ScopedLocalRef<jobject>
|
ScopedLocalRef<jobject> callStaticObjectMethod(
|
||||||
callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...);
|
JNIEnv* env,
|
||||||
|
jclass clazz,
|
||||||
|
jmethodID methodId,
|
||||||
|
...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a local or a global reference, this method creates a new global
|
* Given a local or a global reference, this method creates a new global
|
||||||
|
@@ -18,7 +18,5 @@ struct Size {
|
|||||||
|
|
||||||
Size(double width, double height) : width(width), height(height) {}
|
Size(double width, double height) : width(width), height(height) {}
|
||||||
|
|
||||||
void toJS(nbind::cbOutput expose) const {
|
void toJS(nbind::cbOutput expose) const { expose(width, height); }
|
||||||
expose(width, height);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
@@ -21,7 +21,5 @@ struct Value {
|
|||||||
|
|
||||||
Value(int unit, double value) : unit(unit), value(value) {}
|
Value(int unit, double value) : unit(unit), value(value) {}
|
||||||
|
|
||||||
void toJS(nbind::cbOutput expose) const {
|
void toJS(nbind::cbOutput expose) const { expose(unit, value); }
|
||||||
expose(unit, value);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user