Summary: Currently, our configuration of Views looks like this: ```objc UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.yoga.isEnabled = YES; view.yoga.height = 50; view.yoga.width = 50; ``` Every time that we access `view.yoga` we have to access the associated object on `UIView` to get the `YGLayout`. This adds an extra `objc_msgSend` which increases binary size, and is slight perf impact. This diff creates a way to modify the `YGLayout` with only a single `objc_msgSend`. Here's the new syntax: ```objc UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; [view configureLayoutWithBlock:^void(YGLayout *layout){ layout.isEnabled = YES layout.height = 50; layout.width = 50; }]; ``` Here's the Swift version: ```swift let view = UIView(frame: .zero) view.configureLayout { (layout) in layout.isEnabled = true layout.height = 50 layout.width = 50 } ``` Closes https://github.com/facebook/yoga/pull/393 Reviewed By: emilsjolander Differential Revision: D4550382 Pulled By: dshahidehpour fbshipit-source-id: 76d797d1e0de8e5dc767e02180a7fc440a70212e
34 lines
977 B
Objective-C
34 lines
977 B
Objective-C
/**
|
|
* 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 "YGLayout.h"
|
|
#import <UIKit/UIKit.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
typedef void (^YGLayoutConfigurationBlock)(YGLayout *);
|
|
|
|
@interface UIView (Yoga)
|
|
|
|
/**
|
|
The YGLayout that is attached to this view. It is lazily created.
|
|
*/
|
|
@property (nonatomic, readonly, strong) YGLayout *yoga;
|
|
|
|
/**
|
|
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)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block NS_SWIFT_NAME(configureLayout(block:));
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|