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:
Sidharth Guglani
2020-02-18 08:09:53 -08:00
committed by Facebook Github Bot
parent a1278cee05
commit bfc3b2f86f
17 changed files with 568 additions and 554 deletions

View File

@@ -5,8 +5,8 @@
* 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
@@ -24,9 +24,10 @@ typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
@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:));

View File

@@ -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);
} }

View File

@@ -5,8 +5,8 @@
* 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 ()

View File

@@ -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,11 +44,12 @@ 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;
@@ -119,28 +120,31 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
@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:));
@@ -151,8 +155,8 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
@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;

View File

@@ -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,7 +31,8 @@
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"); \
@@ -43,19 +40,18 @@
} }
#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); \
@@ -65,25 +61,26 @@
} \ } \
} }
#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( \
CGFloat, lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_SETTER(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,35 +89,70 @@ 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};
} }
@@ -139,15 +171,14 @@ static YGConfigRef globalConfig;
@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);
@@ -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,14 +215,14 @@ 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;
@@ -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,10 +331,7 @@ 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),
@@ -328,10 +346,11 @@ 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;
@@ -350,16 +369,17 @@ 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,8 +392,9 @@ 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;
} }
@@ -387,8 +408,7 @@ 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;
@@ -399,7 +419,8 @@ 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 =
[[NSMutableArray alloc] initWithCapacity:view.subviews.count];
for (UIView* subview in view.subviews) { 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];
@@ -419,8 +440,7 @@ static void YGAttachNodesFromViewHierachy(UIView *const view)
} }
} }
static void YGRemoveAllChildren(const YGNodeRef node) static void YGRemoveAllChildren(const YGNodeRef node) {
{
if (node == NULL) { if (node == NULL) {
return; return;
} }
@@ -428,8 +448,7 @@ 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, ^() {
@@ -439,9 +458,10 @@ static CGFloat YGRoundPixelValue(CGFloat value)
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;
@@ -462,13 +482,17 @@ 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),
}, },
}; };

View File

@@ -16,15 +16,13 @@
@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);
@@ -36,8 +34,7 @@
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 {
@@ -53,8 +50,7 @@
XCTAssertNil(layoutRef); XCTAssertNil(layoutRef);
} }
- (void)testNodesAreDeallocedCascade - (void)testNodesAreDeallocedCascade {
{
__weak YGLayout* topLayout = nil; __weak YGLayout* topLayout = nil;
__weak YGLayout* subviewLayout = nil; __weak YGLayout* subviewLayout = nil;
@@ -74,8 +70,7 @@
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);
@@ -86,23 +81,24 @@
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_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){ dispatch_sync(
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;
@@ -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,8 +134,7 @@
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;
@@ -161,8 +158,7 @@
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;
@@ -172,13 +168,14 @@
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;
@@ -195,8 +192,7 @@
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;
@@ -214,8 +210,7 @@
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;
@@ -232,8 +227,7 @@
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;
@@ -257,11 +251,12 @@
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;
@@ -282,22 +277,30 @@
[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;
@@ -333,11 +336,12 @@
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;
@@ -368,12 +372,12 @@
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;
@@ -401,8 +405,7 @@
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;
@@ -437,8 +440,7 @@
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);
@@ -458,8 +460,7 @@
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;
@@ -516,8 +517,7 @@
} }
} }
- (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;
@@ -534,16 +534,14 @@
[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);
@@ -589,8 +587,7 @@
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);
@@ -657,8 +654,7 @@
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);
@@ -725,8 +721,7 @@
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;

View File

@@ -11,8 +11,7 @@
@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;
@@ -29,21 +28,17 @@
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

View File

@@ -9,7 +9,8 @@
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,

View File

@@ -11,7 +11,8 @@
YG_EXTERN_C_BEGIN YG_EXTERN_C_BEGIN
typedef int (*YGInteropLogger)(const void *unmanagedConfigPtr, typedef int (*YGInteropLogger)(
const void* unmanagedConfigPtr,
const void* unmanagedNodePtr, const void* unmanagedNodePtr,
YGLogLevel level, YGLogLevel level,
const char* message); const char* message);

View File

@@ -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:

View File

@@ -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>

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -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

View File

@@ -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);
}
}; };

View File

@@ -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);
}
}; };