Add extended configuration method with self as argument.
This commit is contained in:
@@ -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
|
||||
|
@@ -35,4 +35,11 @@ static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)configureLayoutWithContainerBlock:(YGLayoutContainerConfigurationBlock)block
|
||||
{
|
||||
if (block != nil) {
|
||||
block(self.yoga, self);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user