Rename CSSLayoutKit
Summary: new name Reviewed By: dshahidehpour Differential Revision: D4245987 fbshipit-source-id: 880f558c694bd041abbedadeb91225a3ca6c14f9
This commit is contained in:
committed by
Facebook Github Bot
parent
b9feb10420
commit
4bbf35832e
@@ -23,7 +23,7 @@ before_install:
|
|||||||
script:
|
script:
|
||||||
- buck test //:CSSLayout
|
- buck test //:CSSLayout
|
||||||
- buck test //java:java
|
- buck test //java:java
|
||||||
- buck test //CSSLayoutKit:CSSLayoutKit --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI
|
- buck test //YogaKit:YogaKit --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI
|
||||||
- sh csharp/tests/Facebook.CSSLayout/test_macos.sh
|
- sh csharp/tests/Facebook.CSSLayout/test_macos.sh
|
||||||
- buck run //benchmark:benchmark
|
- buck run //benchmark:benchmark
|
||||||
- git checkout HEAD^
|
- git checkout HEAD^
|
||||||
|
@@ -1,72 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) 2014-present, Facebook, Inc.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the BSD-style license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import <CSSLayout/CSSLayout.h>
|
|
||||||
|
|
||||||
@interface UIView (CSSLayout)
|
|
||||||
|
|
||||||
/**
|
|
||||||
The property that decides if we should include this view when calculating layout. Defaults to YES.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readwrite, assign, setter=css_setIncludeInLayout:) BOOL css_includeInLayout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
The property that decides during layout/sizing whether or not css_* properties should be applied. Defaults to NO.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readwrite, assign, setter=css_setUsesFlexbox:) BOOL css_usesFlexbox;
|
|
||||||
|
|
||||||
- (void)css_setDirection:(YGDirection)direction;
|
|
||||||
- (void)css_setFlexDirection:(YGFlexDirection)flexDirection;
|
|
||||||
- (void)css_setJustifyContent:(YGJustify)justifyContent;
|
|
||||||
- (void)css_setAlignContent:(YGAlign)alignContent;
|
|
||||||
- (void)css_setAlignItems:(YGAlign)alignItems;
|
|
||||||
- (void)css_setAlignSelf:(YGAlign)alignSelf;
|
|
||||||
- (void)css_setPositionType:(YGPositionType)positionType;
|
|
||||||
- (void)css_setFlexWrap:(YGWrap)flexWrap;
|
|
||||||
|
|
||||||
- (void)css_setFlexGrow:(CGFloat)flexGrow;
|
|
||||||
- (void)css_setFlexShrink:(CGFloat)flexShrink;
|
|
||||||
- (void)css_setFlexBasis:(CGFloat)flexBasis;
|
|
||||||
|
|
||||||
- (void)css_setPosition:(CGFloat)position forEdge:(YGEdge)edge;
|
|
||||||
- (void)css_setMargin:(CGFloat)margin forEdge:(YGEdge)edge;
|
|
||||||
- (void)css_setPadding:(CGFloat)padding forEdge:(YGEdge)edge;
|
|
||||||
|
|
||||||
- (void)css_setWidth:(CGFloat)width;
|
|
||||||
- (void)css_setHeight:(CGFloat)height;
|
|
||||||
- (void)css_setMinWidth:(CGFloat)minWidth;
|
|
||||||
- (void)css_setMinHeight:(CGFloat)minHeight;
|
|
||||||
- (void)css_setMaxWidth:(CGFloat)maxWidth;
|
|
||||||
- (void)css_setMaxHeight:(CGFloat)maxHeight;
|
|
||||||
|
|
||||||
// Yoga specific properties, not compatible with flexbox specification
|
|
||||||
- (void)css_setAspectRatio:(CGFloat)aspectRatio;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Get the resolved direction of this node. This won't be YGDirectionInherit
|
|
||||||
*/
|
|
||||||
- (YGDirection)css_resolvedDirection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Perform a layout calculation and update the frames of the views in the hierarchy with th results
|
|
||||||
*/
|
|
||||||
- (void)css_applyLayout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
|
||||||
*/
|
|
||||||
- (CGSize)css_intrinsicSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Returns the number of children that are using Flexbox.
|
|
||||||
*/
|
|
||||||
- (NSUInteger)css_numberOfChildren;
|
|
||||||
|
|
||||||
@end
|
|
14
README.md
14
README.md
@@ -94,23 +94,23 @@ root.getLayoutHeight();
|
|||||||
```
|
```
|
||||||
|
|
||||||
### UIKit
|
### UIKit
|
||||||
The full API can be found in `CSSLayoutKit/UIView+CSSLayout.h`.
|
The full API can be found in `YogaKit/UIView+Yoga.h`.
|
||||||
|
|
||||||
```objective-c
|
```objective-c
|
||||||
UIView *root = [UIView new];
|
UIView *root = [UIView new];
|
||||||
[root css_setUsesFlexbox:YES];
|
[root yg_setUsesYoga:YES];
|
||||||
[root css_setWidth:100];
|
[root yg_setWidth:100];
|
||||||
[root css_setHeight:100];
|
[root yg_setHeight:100];
|
||||||
|
|
||||||
for (NSUInteger i = 0; i < 10; i++) {
|
for (NSUInteger i = 0; i < 10; i++) {
|
||||||
UIView *child = [UIView new];
|
UIView *child = [UIView new];
|
||||||
[child css_setUsesFlexbox:YES];
|
[child yg_setUsesYoga:YES];
|
||||||
[child css_setHeight:10];
|
[child yg_setHeight:10];
|
||||||
[root addSubview:child];
|
[root addSubview:child];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resulting layout will be set on the UIView hierarchy frames.
|
// Resulting layout will be set on the UIView hierarchy frames.
|
||||||
[root css_applyLayout];
|
[root yg_applyLayout];
|
||||||
```
|
```
|
||||||
|
|
||||||
### .NET
|
### .NET
|
||||||
|
@@ -28,9 +28,9 @@ UIKIT_CSSLAYOUT_COMPILER_FLAGS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
apple_library(
|
apple_library(
|
||||||
name = 'CSSLayoutKit',
|
name = 'YogaKit',
|
||||||
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
||||||
tests = [':CSSLayoutKitTests'],
|
tests = [':YogaKitTests'],
|
||||||
srcs = glob(['*.m']),
|
srcs = glob(['*.m']),
|
||||||
exported_headers = glob(['*.h']),
|
exported_headers = glob(['*.h']),
|
||||||
frameworks = [
|
frameworks = [
|
||||||
@@ -44,7 +44,7 @@ apple_library(
|
|||||||
)
|
)
|
||||||
|
|
||||||
apple_test(
|
apple_test(
|
||||||
name = 'CSSLayoutKitTests',
|
name = 'YogaKitTests',
|
||||||
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
|
||||||
info_plist = 'Tests/Info.plist',
|
info_plist = 'Tests/Info.plist',
|
||||||
srcs = glob(['Tests/**/*.m']),
|
srcs = glob(['Tests/**/*.m']),
|
||||||
@@ -53,7 +53,7 @@ apple_test(
|
|||||||
'$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
|
'$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
':CSSLayoutKit',
|
':YogaKit',
|
||||||
],
|
],
|
||||||
visibility = ['PUBLIC'],
|
visibility = ['PUBLIC'],
|
||||||
)
|
)
|
@@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
#import <XCTest/XCTest.h>
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
#import "UIView+CSSLayout.h"
|
#import "UIView+Yoga.h"
|
||||||
|
|
||||||
@interface CSSLayoutKitTests : XCTestCase
|
@interface YogaKitTests : XCTestCase
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CSSLayoutKitTests
|
@implementation YogaKitTests
|
||||||
|
|
||||||
#ifndef TRAVIS_CI
|
#ifndef TRAVIS_CI
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
||||||
|
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[view css_setFlexBasis:1];
|
[view yg_setFlexBasis:1];
|
||||||
XCTAssertEqual(1, CSSNodeGetInstanceCount());
|
XCTAssertEqual(1, CSSNodeGetInstanceCount());
|
||||||
view = nil;
|
view = nil;
|
||||||
|
|
||||||
@@ -35,11 +35,11 @@
|
|||||||
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
XCTAssertEqual(0, CSSNodeGetInstanceCount());
|
||||||
|
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[view css_setFlexBasis:1];
|
[view yg_setFlexBasis:1];
|
||||||
|
|
||||||
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];
|
||||||
[subview css_setFlexBasis:1];
|
[subview yg_setFlexBasis:1];
|
||||||
[view addSubview:subview];
|
[view addSubview:subview];
|
||||||
}
|
}
|
||||||
XCTAssertEqual(11, CSSNodeGetInstanceCount());
|
XCTAssertEqual(11, CSSNodeGetInstanceCount());
|
||||||
@@ -50,49 +50,49 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
- (void)testUsesFlexbox
|
- (void)testUsesYoga
|
||||||
{
|
{
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
XCTAssertFalse([view css_usesFlexbox]);
|
XCTAssertFalse([view yg_usesYoga]);
|
||||||
|
|
||||||
[view css_setUsesFlexbox:YES];
|
[view yg_setUsesYoga:YES];
|
||||||
XCTAssertTrue([view css_usesFlexbox]);
|
XCTAssertTrue([view yg_usesYoga]);
|
||||||
|
|
||||||
[view css_setUsesFlexbox:NO];
|
[view yg_setUsesYoga:NO];
|
||||||
XCTAssertFalse([view css_usesFlexbox]);
|
XCTAssertFalse([view yg_usesYoga]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSizeThatFitsAsserts
|
- (void)testSizeThatFitsAsserts
|
||||||
{
|
{
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
dispatch_sync(dispatch_queue_create("com.facebook.CSSLayout.testing", DISPATCH_QUEUE_SERIAL), ^(void){
|
dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){
|
||||||
XCTAssertThrows([view css_intrinsicSize]);
|
XCTAssertThrows([view yg_intrinsicSize]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSizeThatFitsSmoke
|
- (void)testSizeThatFitsSmoke
|
||||||
{
|
{
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[container css_setUsesFlexbox:YES];
|
[container yg_setUsesYoga:YES];
|
||||||
[container css_setFlexDirection:YGFlexDirectionRow];
|
[container yg_setFlexDirection:YGFlexDirectionRow];
|
||||||
[container css_setAlignItems:YGAlignFlexStart];
|
[container yg_setAlignItems: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 css_setUsesFlexbox:YES];
|
[longTextLabel yg_setUsesYoga:YES];
|
||||||
[longTextLabel css_setFlexShrink:1];
|
[longTextLabel yg_setFlexShrink:1];
|
||||||
[container addSubview:longTextLabel];
|
[container addSubview:longTextLabel];
|
||||||
|
|
||||||
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[textBadgeView css_setUsesFlexbox:YES];
|
[textBadgeView yg_setUsesYoga:YES];
|
||||||
[textBadgeView css_setMargin:3.0 forEdge:YGEdgeLeft];
|
[textBadgeView yg_setMargin:3.0 forEdge:YGEdgeLeft];
|
||||||
[textBadgeView css_setWidth:10];
|
[textBadgeView yg_setWidth:10];
|
||||||
[textBadgeView css_setHeight:10];
|
[textBadgeView yg_setHeight:10];
|
||||||
[container addSubview:textBadgeView];
|
[container addSubview:textBadgeView];
|
||||||
|
|
||||||
const CGSize containerSize = [container css_intrinsicSize];
|
const CGSize containerSize = [container yg_intrinsicSize];
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(514,21), containerSize), @"Size is actually %@", NSStringFromCGSize(containerSize));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(514,21), containerSize), @"Size is actually %@", NSStringFromCGSize(containerSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,17 +101,17 @@
|
|||||||
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 css_setUsesFlexbox:YES];
|
[container yg_setUsesYoga:YES];
|
||||||
[container css_setFlexDirection:YGFlexDirectionRow];
|
[container yg_setFlexDirection:YGFlexDirectionRow];
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview css_setUsesFlexbox:YES];
|
[subview yg_setUsesYoga:YES];
|
||||||
[subview css_setFlexGrow:1];
|
[subview yg_setFlexGrow:1];
|
||||||
|
|
||||||
[container addSubview:subview];
|
[container addSubview:subview];
|
||||||
}
|
}
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
|
|
||||||
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:1].frame));
|
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:1].frame));
|
||||||
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:1].frame, [container.subviews objectAtIndex:2].frame));
|
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:1].frame, [container.subviews objectAtIndex:2].frame));
|
||||||
@@ -130,33 +130,33 @@
|
|||||||
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 css_setUsesFlexbox:YES];
|
[container yg_setUsesYoga:YES];
|
||||||
[container css_setFlexDirection:YGFlexDirectionRow];
|
[container yg_setFlexDirection:YGFlexDirectionRow];
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview1 css_setUsesFlexbox:YES];
|
[subview1 yg_setUsesYoga:YES];
|
||||||
[subview1 css_setFlexGrow:1];
|
[subview1 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview2 css_setUsesFlexbox:YES];
|
[subview2 yg_setUsesYoga:YES];
|
||||||
[subview2 css_setFlexGrow:1];
|
[subview2 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview3 css_setUsesFlexbox:YES];
|
[subview3 yg_setUsesYoga:YES];
|
||||||
[subview3 css_setFlexGrow:1];
|
[subview3 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
|
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
|
|
||||||
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50)));
|
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50)));
|
||||||
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)), @"It's actually %@", NSStringFromCGRect(subview2.frame));
|
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)), @"It's actually %@", NSStringFromCGRect(subview2.frame));
|
||||||
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(200, 0, 100, 50)));
|
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(200, 0, 100, 50)));
|
||||||
|
|
||||||
[container exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
|
[container exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
|
||||||
[subview2 css_setIncludeInLayout:NO];
|
[subview2 yg_setIncludeInLayout:NO];
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
|
|
||||||
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(0, 0, 150, 50)));
|
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(0, 0, 150, 50)));
|
||||||
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(150, 0, 150, 50)));
|
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(150, 0, 150, 50)));
|
||||||
@@ -170,32 +170,32 @@
|
|||||||
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 css_setUsesFlexbox:YES];
|
[container yg_setUsesYoga:YES];
|
||||||
[container css_setFlexDirection:YGFlexDirectionRow];
|
[container yg_setFlexDirection:YGFlexDirectionRow];
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview1 css_setUsesFlexbox:YES];
|
[subview1 yg_setUsesYoga:YES];
|
||||||
[subview1 css_setFlexGrow:1];
|
[subview1 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview2 css_setUsesFlexbox:YES];
|
[subview2 yg_setUsesYoga:YES];
|
||||||
[subview2 css_setFlexGrow:1];
|
[subview2 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview3 css_setUsesFlexbox:YES];
|
[subview3 yg_setUsesYoga:YES];
|
||||||
[subview3 css_setFlexGrow:1];
|
[subview3 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
|
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
|
|
||||||
for (UIView *view in container.subviews) {
|
for (UIView *view in container.subviews) {
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
|
||||||
}
|
}
|
||||||
|
|
||||||
[subview3 css_setIncludeInLayout:NO];
|
[subview3 yg_setIncludeInLayout:NO];
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
|
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
||||||
@@ -207,62 +207,62 @@
|
|||||||
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
|
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
|
||||||
{
|
{
|
||||||
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[container css_setUsesFlexbox:YES];
|
[container yg_setUsesYoga:YES];
|
||||||
[container css_setFlexDirection:YGFlexDirectionRow];
|
[container yg_setFlexDirection:YGFlexDirectionRow];
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview1 css_setUsesFlexbox:YES];
|
[subview1 yg_setUsesYoga:YES];
|
||||||
[subview1 css_setIncludeInLayout:NO];
|
[subview1 yg_setIncludeInLayout:NO];
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview2 css_setUsesFlexbox:YES];
|
[subview2 yg_setUsesYoga:YES];
|
||||||
[subview2 css_setIncludeInLayout:NO];
|
[subview2 yg_setIncludeInLayout:NO];
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview3 css_setUsesFlexbox:YES];
|
[subview3 yg_setUsesYoga:YES];
|
||||||
[subview3 css_setIncludeInLayout:YES];
|
[subview3 yg_setIncludeInLayout:YES];
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
|
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
XCTAssertEqual(1, [container css_numberOfChildren]);
|
XCTAssertEqual(1, [container yg_numberOfChildren]);
|
||||||
|
|
||||||
[subview2 css_setIncludeInLayout:YES];
|
[subview2 yg_setIncludeInLayout:YES];
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
XCTAssertEqual(2, [container css_numberOfChildren]);
|
XCTAssertEqual(2, [container yg_numberOfChildren]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (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 css_setUsesFlexbox:YES];
|
[container yg_setUsesYoga:YES];
|
||||||
[container css_setFlexDirection:YGFlexDirectionRow];
|
[container yg_setFlexDirection:YGFlexDirectionRow];
|
||||||
|
|
||||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview1 css_setUsesFlexbox:YES];
|
[subview1 yg_setUsesYoga:YES];
|
||||||
[subview1 css_setFlexGrow:1];
|
[subview1 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview1];
|
[container addSubview:subview1];
|
||||||
|
|
||||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview2 css_setUsesFlexbox:YES];
|
[subview2 yg_setUsesYoga:YES];
|
||||||
[subview2 css_setFlexGrow:1];
|
[subview2 yg_setFlexGrow:1];
|
||||||
[container addSubview:subview2];
|
[container addSubview:subview2];
|
||||||
|
|
||||||
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
[subview3 css_setUsesFlexbox:YES];
|
[subview3 yg_setUsesYoga:YES];
|
||||||
[subview3 css_setFlexGrow:1];
|
[subview3 yg_setFlexGrow:1];
|
||||||
[subview3 css_setIncludeInLayout:NO];
|
[subview3 yg_setIncludeInLayout:NO];
|
||||||
[container addSubview:subview3];
|
[container addSubview:subview3];
|
||||||
|
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
|
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeZero, subview3.bounds.size), @"Actual size %@", NSStringFromCGSize(subview3.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeZero, subview3.bounds.size), @"Actual size %@", NSStringFromCGSize(subview3.bounds.size));
|
||||||
|
|
||||||
[subview3 css_setIncludeInLayout:YES];
|
[subview3 yg_setIncludeInLayout:YES];
|
||||||
[container css_applyLayout];
|
[container yg_applyLayout];
|
||||||
for (UIView *view in container.subviews) {
|
for (UIView *view in container.subviews) {
|
||||||
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
|
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
|
||||||
}
|
}
|
72
YogaKit/UIView+Yoga.h
Normal file
72
YogaKit/UIView+Yoga.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <CSSLayout/CSSLayout.h>
|
||||||
|
|
||||||
|
@interface UIView (CSSLayout)
|
||||||
|
|
||||||
|
/**
|
||||||
|
The property that decides if we should include this view when calculating layout. Defaults to YES.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readwrite, assign, setter=yg_setIncludeInLayout:) BOOL yg_includeInLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The property that decides during layout/sizing whether or not yg_* properties should be applied. Defaults to NO.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readwrite, assign, setter=yg_setUsesYoga:) BOOL yg_usesYoga;
|
||||||
|
|
||||||
|
- (void)yg_setDirection:(YGDirection)direction;
|
||||||
|
- (void)yg_setFlexDirection:(YGFlexDirection)flexDirection;
|
||||||
|
- (void)yg_setJustifyContent:(YGJustify)justifyContent;
|
||||||
|
- (void)yg_setAlignContent:(YGAlign)alignContent;
|
||||||
|
- (void)yg_setAlignItems:(YGAlign)alignItems;
|
||||||
|
- (void)yg_setAlignSelf:(YGAlign)alignSelf;
|
||||||
|
- (void)yg_setPositionType:(YGPositionType)positionType;
|
||||||
|
- (void)yg_setFlexWrap:(YGWrap)flexWrap;
|
||||||
|
|
||||||
|
- (void)yg_setFlexGrow:(CGFloat)flexGrow;
|
||||||
|
- (void)yg_setFlexShrink:(CGFloat)flexShrink;
|
||||||
|
- (void)yg_setFlexBasis:(CGFloat)flexBasis;
|
||||||
|
|
||||||
|
- (void)yg_setPosition:(CGFloat)position forEdge:(YGEdge)edge;
|
||||||
|
- (void)yg_setMargin:(CGFloat)margin forEdge:(YGEdge)edge;
|
||||||
|
- (void)yg_setPadding:(CGFloat)padding forEdge:(YGEdge)edge;
|
||||||
|
|
||||||
|
- (void)yg_setWidth:(CGFloat)width;
|
||||||
|
- (void)yg_setHeight:(CGFloat)height;
|
||||||
|
- (void)yg_setMinWidth:(CGFloat)minWidth;
|
||||||
|
- (void)yg_setMinHeight:(CGFloat)minHeight;
|
||||||
|
- (void)yg_setMaxWidth:(CGFloat)maxWidth;
|
||||||
|
- (void)yg_setMaxHeight:(CGFloat)maxHeight;
|
||||||
|
|
||||||
|
// Yoga specific properties, not compatible with flexbox specification
|
||||||
|
- (void)yg_setAspectRatio:(CGFloat)aspectRatio;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the resolved direction of this node. This won't be YGDirectionInherit
|
||||||
|
*/
|
||||||
|
- (YGDirection)yg_resolvedDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Perform a layout calculation and update the frames of the views in the hierarchy with th results
|
||||||
|
*/
|
||||||
|
- (void)yg_applyLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||||
|
*/
|
||||||
|
- (CGSize)yg_intrinsicSize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the number of children that are using Flexbox.
|
||||||
|
*/
|
||||||
|
- (NSUInteger)yg_numberOfChildren;
|
||||||
|
|
||||||
|
@end
|
@@ -7,7 +7,7 @@
|
|||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "UIView+CSSLayout.h"
|
#import "UIView+Yoga.h"
|
||||||
|
|
||||||
#import <objc/runtime.h>
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
@@ -39,162 +39,162 @@
|
|||||||
|
|
||||||
@implementation UIView (CSSLayout)
|
@implementation UIView (CSSLayout)
|
||||||
|
|
||||||
- (BOOL)css_usesFlexbox
|
- (BOOL)yg_usesYoga
|
||||||
{
|
{
|
||||||
NSNumber *usesFlexbox = objc_getAssociatedObject(self, @selector(css_usesFlexbox));
|
NSNumber *usesYoga = objc_getAssociatedObject(self, @selector(yg_usesYoga));
|
||||||
return [usesFlexbox boolValue];
|
return [usesYoga boolValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)css_includeInLayout
|
- (BOOL)yg_includeInLayout
|
||||||
{
|
{
|
||||||
NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(css_includeInLayout));
|
NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(yg_includeInLayout));
|
||||||
return (includeInLayout != nil) ? [includeInLayout boolValue] : YES;
|
return (includeInLayout != nil) ? [includeInLayout boolValue] : YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSUInteger)css_numberOfChildren
|
- (NSUInteger)yg_numberOfChildren
|
||||||
{
|
{
|
||||||
return CSSNodeChildCount([self cssNode]);
|
return CSSNodeChildCount([self cssNode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Setters
|
#pragma mark - Setters
|
||||||
|
|
||||||
- (void)css_setIncludeInLayout:(BOOL)includeInLayout
|
- (void)yg_setIncludeInLayout:(BOOL)includeInLayout
|
||||||
{
|
{
|
||||||
objc_setAssociatedObject(
|
objc_setAssociatedObject(
|
||||||
self,
|
self,
|
||||||
@selector(css_includeInLayout),
|
@selector(yg_includeInLayout),
|
||||||
@(includeInLayout),
|
@(includeInLayout),
|
||||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setUsesFlexbox:(BOOL)enabled
|
- (void)yg_setUsesYoga:(BOOL)enabled
|
||||||
{
|
{
|
||||||
objc_setAssociatedObject(
|
objc_setAssociatedObject(
|
||||||
self,
|
self,
|
||||||
@selector(css_usesFlexbox),
|
@selector(yg_usesYoga),
|
||||||
@(enabled),
|
@(enabled),
|
||||||
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setDirection:(YGDirection)direction
|
- (void)yg_setDirection:(YGDirection)direction
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetDirection([self cssNode], direction);
|
CSSNodeStyleSetDirection([self cssNode], direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setFlexDirection:(YGFlexDirection)flexDirection
|
- (void)yg_setFlexDirection:(YGFlexDirection)flexDirection
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetFlexDirection([self cssNode], flexDirection);
|
CSSNodeStyleSetFlexDirection([self cssNode], flexDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setJustifyContent:(YGJustify)justifyContent
|
- (void)yg_setJustifyContent:(YGJustify)justifyContent
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetJustifyContent([self cssNode], justifyContent);
|
CSSNodeStyleSetJustifyContent([self cssNode], justifyContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setAlignContent:(YGAlign)alignContent
|
- (void)yg_setAlignContent:(YGAlign)alignContent
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetAlignContent([self cssNode], alignContent);
|
CSSNodeStyleSetAlignContent([self cssNode], alignContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setAlignItems:(YGAlign)alignItems
|
- (void)yg_setAlignItems:(YGAlign)alignItems
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetAlignItems([self cssNode], alignItems);
|
CSSNodeStyleSetAlignItems([self cssNode], alignItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setAlignSelf:(YGAlign)alignSelf
|
- (void)yg_setAlignSelf:(YGAlign)alignSelf
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetAlignSelf([self cssNode], alignSelf);
|
CSSNodeStyleSetAlignSelf([self cssNode], alignSelf);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setPositionType:(YGPositionType)positionType
|
- (void)yg_setPositionType:(YGPositionType)positionType
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetPositionType([self cssNode], positionType);
|
CSSNodeStyleSetPositionType([self cssNode], positionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setFlexWrap:(YGWrap)flexWrap
|
- (void)yg_setFlexWrap:(YGWrap)flexWrap
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetFlexWrap([self cssNode], flexWrap);
|
CSSNodeStyleSetFlexWrap([self cssNode], flexWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setFlexGrow:(CGFloat)flexGrow
|
- (void)yg_setFlexGrow:(CGFloat)flexGrow
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetFlexGrow([self cssNode], flexGrow);
|
CSSNodeStyleSetFlexGrow([self cssNode], flexGrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setFlexShrink:(CGFloat)flexShrink
|
- (void)yg_setFlexShrink:(CGFloat)flexShrink
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetFlexShrink([self cssNode], flexShrink);
|
CSSNodeStyleSetFlexShrink([self cssNode], flexShrink);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setFlexBasis:(CGFloat)flexBasis
|
- (void)yg_setFlexBasis:(CGFloat)flexBasis
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetFlexBasis([self cssNode], flexBasis);
|
CSSNodeStyleSetFlexBasis([self cssNode], flexBasis);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setPosition:(CGFloat)position forEdge:(YGEdge)edge
|
- (void)yg_setPosition:(CGFloat)position forEdge:(YGEdge)edge
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetPosition([self cssNode], edge, position);
|
CSSNodeStyleSetPosition([self cssNode], edge, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setMargin:(CGFloat)margin forEdge:(YGEdge)edge
|
- (void)yg_setMargin:(CGFloat)margin forEdge:(YGEdge)edge
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetMargin([self cssNode], edge, margin);
|
CSSNodeStyleSetMargin([self cssNode], edge, margin);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setPadding:(CGFloat)padding forEdge:(YGEdge)edge
|
- (void)yg_setPadding:(CGFloat)padding forEdge:(YGEdge)edge
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetPadding([self cssNode], edge, padding);
|
CSSNodeStyleSetPadding([self cssNode], edge, padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setWidth:(CGFloat)width
|
- (void)yg_setWidth:(CGFloat)width
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetWidth([self cssNode], width);
|
CSSNodeStyleSetWidth([self cssNode], width);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setHeight:(CGFloat)height
|
- (void)yg_setHeight:(CGFloat)height
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetHeight([self cssNode], height);
|
CSSNodeStyleSetHeight([self cssNode], height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setMinWidth:(CGFloat)minWidth
|
- (void)yg_setMinWidth:(CGFloat)minWidth
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetMinWidth([self cssNode], minWidth);
|
CSSNodeStyleSetMinWidth([self cssNode], minWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setMinHeight:(CGFloat)minHeight
|
- (void)yg_setMinHeight:(CGFloat)minHeight
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetMinHeight([self cssNode], minHeight);
|
CSSNodeStyleSetMinHeight([self cssNode], minHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setMaxWidth:(CGFloat)maxWidth
|
- (void)yg_setMaxWidth:(CGFloat)maxWidth
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetMaxWidth([self cssNode], maxWidth);
|
CSSNodeStyleSetMaxWidth([self cssNode], maxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setMaxHeight:(CGFloat)maxHeight
|
- (void)yg_setMaxHeight:(CGFloat)maxHeight
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetMaxHeight([self cssNode], maxHeight);
|
CSSNodeStyleSetMaxHeight([self cssNode], maxHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_setAspectRatio:(CGFloat)aspectRatio
|
- (void)yg_setAspectRatio:(CGFloat)aspectRatio
|
||||||
{
|
{
|
||||||
CSSNodeStyleSetAspectRatio([self cssNode], aspectRatio);
|
CSSNodeStyleSetAspectRatio([self cssNode], aspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Layout and Sizing
|
#pragma mark - Layout and Sizing
|
||||||
|
|
||||||
- (YGDirection)css_resolvedDirection
|
- (YGDirection)yg_resolvedDirection
|
||||||
{
|
{
|
||||||
return CSSNodeLayoutGetDirection([self cssNode]);
|
return CSSNodeLayoutGetDirection([self cssNode]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)css_applyLayout
|
- (void)yg_applyLayout
|
||||||
{
|
{
|
||||||
[self calculateLayoutWithSize:self.bounds.size];
|
[self calculateLayoutWithSize:self.bounds.size];
|
||||||
CSSApplyLayoutToViewHierarchy(self);
|
CSSApplyLayoutToViewHierarchy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGSize)css_intrinsicSize
|
- (CGSize)yg_intrinsicSize
|
||||||
{
|
{
|
||||||
const CGSize constrainedSize = {
|
const CGSize constrainedSize = {
|
||||||
.width = YGUndefined,
|
.width = YGUndefined,
|
||||||
@@ -220,7 +220,7 @@
|
|||||||
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
||||||
{
|
{
|
||||||
NSAssert([NSThread isMainThread], @"CSS Layout calculation must be done on main.");
|
NSAssert([NSThread isMainThread], @"CSS Layout calculation must be done on main.");
|
||||||
NSAssert([self css_usesFlexbox], @"CSS Layout is not enabled for this view.");
|
NSAssert([self yg_usesYoga], @"CSS Layout is not enabled for this view.");
|
||||||
|
|
||||||
CSSAttachNodesFromViewHierachy(self);
|
CSSAttachNodesFromViewHierachy(self);
|
||||||
|
|
||||||
@@ -280,7 +280,7 @@ static void CSSAttachNodesFromViewHierachy(UIView *view) {
|
|||||||
CSSNodeRef node = [view cssNode];
|
CSSNodeRef node = [view cssNode];
|
||||||
|
|
||||||
// Only leaf nodes should have a measure function
|
// Only leaf nodes should have a measure function
|
||||||
if (![view css_usesFlexbox] || view.subviews.count == 0) {
|
if (![view yg_usesYoga] || view.subviews.count == 0) {
|
||||||
CSSNodeSetMeasureFunc(node, CSSMeasureView);
|
CSSNodeSetMeasureFunc(node, CSSMeasureView);
|
||||||
CSSRemoveAllChildren(node);
|
CSSRemoveAllChildren(node);
|
||||||
} else {
|
} else {
|
||||||
@@ -289,7 +289,7 @@ static void CSSAttachNodesFromViewHierachy(UIView *view) {
|
|||||||
// Create a list of all the subviews that we are going to use for layout.
|
// Create a list of all the subviews that we are going to use for layout.
|
||||||
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 css_includeInLayout]) {
|
if ([subview yg_includeInLayout]) {
|
||||||
[subviewsToInclude addObject:subview];
|
[subviewsToInclude addObject:subview];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,7 @@ static CGFloat CSSRoundPixelValue(CGFloat value)
|
|||||||
|
|
||||||
static void CSSApplyLayoutToViewHierarchy(UIView *view) {
|
static void CSSApplyLayoutToViewHierarchy(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 css_includeInLayout]) {
|
if (![view yg_includeInLayout]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +368,7 @@ static void CSSApplyLayoutToViewHierarchy(UIView *view) {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const BOOL isLeaf = ![view css_usesFlexbox] || view.subviews.count == 0;
|
const BOOL isLeaf = ![view yg_usesYoga] || view.subviews.count == 0;
|
||||||
if (!isLeaf) {
|
if (!isLeaf) {
|
||||||
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
for (NSUInteger i = 0; i < view.subviews.count; i++) {
|
||||||
CSSApplyLayoutToViewHierarchy(view.subviews[i]);
|
CSSApplyLayoutToViewHierarchy(view.subviews[i]);
|
Reference in New Issue
Block a user