Merge branch 'master' of https://github.com/pre10der89/css-layout into csharp_wrapper
This commit is contained in:
@@ -268,4 +268,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testyg_isLeafFlag
|
||||||
|
{
|
||||||
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
XCTAssertTrue(view.yg_isLeaf);
|
||||||
|
|
||||||
|
for (int i=0; i<10; i++) {
|
||||||
|
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
[view addSubview:subview];
|
||||||
|
}
|
||||||
|
XCTAssertTrue(view.yg_isLeaf);
|
||||||
|
|
||||||
|
[view yg_setUsesYoga:YES];
|
||||||
|
[view yg_setWidth:50.0];
|
||||||
|
XCTAssertTrue(view.yg_isLeaf);
|
||||||
|
|
||||||
|
UIView *const subview = view.subviews[0];
|
||||||
|
[subview yg_setUsesYoga:YES];
|
||||||
|
[subview yg_setWidth:50.0];
|
||||||
|
XCTAssertFalse(view.yg_isLeaf);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -69,4 +69,9 @@
|
|||||||
*/
|
*/
|
||||||
- (NSUInteger)yg_numberOfChildren;
|
- (NSUInteger)yg_numberOfChildren;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return a BOOL indiciating whether or not we this node contains any subviews that are included in Yoga's layout.
|
||||||
|
*/
|
||||||
|
- (BOOL)yg_isLeaf;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -56,6 +56,20 @@
|
|||||||
return YGNodeGetChildCount([self ygNode]);
|
return YGNodeGetChildCount([self ygNode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)yg_isLeaf
|
||||||
|
{
|
||||||
|
NSAssert([NSThread isMainThread], @"This method must be called on the main thread.");
|
||||||
|
if ([self yg_usesYoga]) {
|
||||||
|
for (UIView *subview in self.subviews) {
|
||||||
|
if ([subview yg_usesYoga] && [subview yg_includeInLayout]) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Setters
|
#pragma mark - Setters
|
||||||
|
|
||||||
- (void)yg_setIncludeInLayout:(BOOL)includeInLayout
|
- (void)yg_setIncludeInLayout:(BOOL)includeInLayout
|
||||||
@@ -276,11 +290,12 @@ static CGFloat YGSanitizeMeasurement(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGAttachNodesFromViewHierachy(UIView *view) {
|
static void YGAttachNodesFromViewHierachy(UIView *view)
|
||||||
|
{
|
||||||
YGNodeRef node = [view ygNode];
|
YGNodeRef node = [view ygNode];
|
||||||
|
|
||||||
// Only leaf nodes should have a measure function
|
// Only leaf nodes should have a measure function
|
||||||
if (![view yg_usesYoga] || view.subviews.count == 0) {
|
if (view.yg_isLeaf) {
|
||||||
YGNodeSetMeasureFunc(node, YGMeasureView);
|
YGNodeSetMeasureFunc(node, YGMeasureView);
|
||||||
YGRemoveAllChildren(node);
|
YGRemoveAllChildren(node);
|
||||||
} else {
|
} else {
|
||||||
@@ -340,7 +355,8 @@ static CGFloat YGRoundPixelValue(CGFloat value)
|
|||||||
return round(value * scale) / scale;
|
return round(value * scale) / scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void YGApplyLayoutToViewHierarchy(UIView *view) {
|
static void YGApplyLayoutToViewHierarchy(UIView *view)
|
||||||
|
{
|
||||||
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
|
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
|
||||||
if (![view yg_includeInLayout]) {
|
if (![view yg_includeInLayout]) {
|
||||||
return;
|
return;
|
||||||
@@ -368,8 +384,7 @@ static void YGApplyLayoutToViewHierarchy(UIView *view) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const BOOL isLeaf = ![view yg_usesYoga] || view.subviews.count == 0;
|
if (!view.yg_isLeaf) {
|
||||||
if (!isLeaf) {
|
|
||||||
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
||||||
YGApplyLayoutToViewHierarchy(view.subviews[i]);
|
YGApplyLayoutToViewHierarchy(view.subviews[i]);
|
||||||
}
|
}
|
||||||
|
@@ -197,6 +197,7 @@ static void YGNodeInit(const YGNodeRef node) {
|
|||||||
node->style.flexBasis = YGUndefined;
|
node->style.flexBasis = YGUndefined;
|
||||||
|
|
||||||
node->style.alignItems = YGAlignStretch;
|
node->style.alignItems = YGAlignStretch;
|
||||||
|
node->style.justifyContent = YGJustifyFlexStart;
|
||||||
node->style.alignContent = YGAlignFlexStart;
|
node->style.alignContent = YGAlignFlexStart;
|
||||||
|
|
||||||
node->style.direction = YGDirectionInherit;
|
node->style.direction = YGDirectionInherit;
|
||||||
|
Reference in New Issue
Block a user