Add extended configuration method with self as argument.

This commit is contained in:
Anton Sergeev
2019-10-10 10:01:07 +03:00
parent 293b657aef
commit d34631e508
3 changed files with 37 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
NS_ASSUME_NONNULL_BEGIN
typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
typedef void (^YGLayoutContainerConfigurationBlock)(YGLayout *layout, UIView *container);
@interface UIView (Yoga)
@@ -30,6 +31,14 @@ typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)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
NS_ASSUME_NONNULL_END

View File

@@ -35,4 +35,11 @@ static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
}
}
- (void)configureLayoutWithContainerBlock:(YGLayoutContainerConfigurationBlock)block
{
if (block != nil) {
block(self.yoga, self);
}
}
@end