Add extended configuration method with self as argument #934
@@ -10,6 +10,7 @@
|
|||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
|
typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
|
||||||
|
typedef void (^YGLayoutContainerConfigurationBlock)(YGLayout *layout, UIView *container);
|
||||||
|
|
||||||
@interface UIView (Yoga)
|
@interface UIView (Yoga)
|
||||||
|
|
||||||
@@ -30,6 +31,14 @@ typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
|
|||||||
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
|
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
|
||||||
NS_SWIFT_NAME(configureLayout(block:));
|
NS_SWIFT_NAME(configureLayout(block:));
|
||||||
|
|
||||||
|
/**
|
||||||
|
In ObjC land, every time you access `view.yoga.*` you are adding another `objc_msgSend`
|
||||||
|
to your code. If you plan on making multiple changes to YGLayout, it's more performant
|
||||||
|
to use this method, which uses a single objc_msgSend call.
|
||||||
|
*/
|
||||||
|
- (void)configureLayoutWithContainerBlock:(YGLayoutContainerConfigurationBlock)block
|
||||||
|
NS_SWIFT_NAME(configureLayout(containerBlock:));
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@@ -35,4 +35,11 @@ static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)configureLayoutWithContainerBlock:(YGLayoutContainerConfigurationBlock)block
|
||||||
|
{
|
||||||
|
if (block != nil) {
|
||||||
|
block(self.yoga, self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@@ -22,6 +22,13 @@
|
|||||||
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
|
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testConfigureContainerLayoutIsNoOpWithNilBlock
|
||||||
|
{
|
||||||
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
id block = nil;
|
||||||
|
XCTAssertNoThrow([view configureLayoutWithContainerBlock:block]);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)testConfigureLayoutBlockWorksWithValidBlock
|
- (void)testConfigureLayoutBlockWorksWithValidBlock
|
||||||
{
|
{
|
||||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
@@ -35,6 +42,20 @@
|
|||||||
XCTAssertEqual(view.yoga.width.value, 25);
|
XCTAssertEqual(view.yoga.width.value, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testConfigureContainerLayoutBlockWorksWithValidBlock
|
||||||
|
{
|
||||||
|
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||||
|
[view configureLayoutWithContainerBlock:^(YGLayout *layout, UIView *container){
|
||||||
|
XCTAssertNotNil(layout);
|
||||||
|
XCTAssertTrue(view == container);
|
||||||
|
layout.isEnabled = YES;
|
||||||
|
layout.width = YGPointValue(25);
|
||||||
|
}];
|
||||||
|
|
||||||
|
XCTAssertTrue(view.yoga.isEnabled);
|
||||||
|
XCTAssertEqual(view.yoga.width.value, 25);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)testNodesAreDeallocedWithSingleView
|
- (void)testNodesAreDeallocedWithSingleView
|
||||||
{
|
{
|
||||||
__weak YGLayout *layoutRef = nil;
|
__weak YGLayout *layoutRef = nil;
|
||||||
|
Reference in New Issue
Block a user