2019-09-30 15:04:19 -07:00
|
|
|
/*
|
2022-10-04 13:59:32 -07:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2016-10-12 09:32:40 -07:00
|
|
|
*
|
2019-10-15 10:30:08 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-10-12 09:32:40 -07:00
|
|
|
*/
|
2019-10-15 10:30:08 -07:00
|
|
|
|
2020-02-18 08:09:53 -08:00
|
|
|
#import <objc/runtime.h>
|
2016-12-02 11:18:15 -08:00
|
|
|
#import "UIView+Yoga.h"
|
2017-01-08 11:42:43 -08:00
|
|
|
#import "YGLayout+Private.h"
|
2016-10-12 09:32:40 -07:00
|
|
|
|
2020-02-18 08:09:53 -08:00
|
|
|
static const void* kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
|
2016-11-21 10:12:26 -08:00
|
|
|
|
2017-01-08 11:42:43 -08:00
|
|
|
@implementation UIView (YogaKit)
|
2016-11-11 16:38:13 -08:00
|
|
|
|
2020-02-18 08:09:53 -08:00
|
|
|
- (YGLayout*)yoga {
|
|
|
|
YGLayout* yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
|
2017-01-08 11:42:43 -08:00
|
|
|
if (!yoga) {
|
|
|
|
yoga = [[YGLayout alloc] initWithView:self];
|
2020-02-18 08:09:53 -08:00
|
|
|
objc_setAssociatedObject(
|
|
|
|
self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
2016-11-11 16:38:13 -08:00
|
|
|
}
|
2016-11-17 07:29:33 -08:00
|
|
|
|
2017-01-08 11:42:43 -08:00
|
|
|
return yoga;
|
2016-11-17 07:29:33 -08:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:09:53 -08:00
|
|
|
- (BOOL)isYogaEnabled {
|
2017-09-21 09:58:08 -07:00
|
|
|
return objc_getAssociatedObject(self, kYGYogaAssociatedKey) != nil;
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:09:53 -08:00
|
|
|
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block {
|
2017-02-13 09:16:22 -08:00
|
|
|
if (block != nil) {
|
|
|
|
block(self.yoga);
|
|
|
|
}
|
|
|
|
}
|
2016-10-27 12:45:07 -07:00
|
|
|
|
|
|
|
@end
|