[YogaKit] support macOS, tvOS, Carthage; auto apply layout like AutoLayout. #1026
@@ -156,7 +156,27 @@ YGValue YGPercentValue(CGFloat value) {
|
|||||||
return (YGValue){.value = value, .unit = YGUnitPercent};
|
return (YGValue){.value = value, .unit = YGUnitPercent};
|
||||||
}
|
}
|
||||||
|
|
||||||
static YGConfigRef globalConfig;
|
static CGFloat YGScaleFactor() {
|
||||||
|
static CGFloat scale;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^() {
|
||||||
|
scale = [UIScreen mainScreen].scale;
|
||||||
|
});
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
static YGConfigRef YGGlobalConfig() {
|
||||||
|
static YGConfigRef globalConfig;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^() {
|
||||||
|
globalConfig = YGConfigNew();
|
||||||
|
YGConfigSetExperimentalFeatureEnabled(globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
||||||
|
YGConfigSetPointScaleFactor(globalConfig, YGScaleFactor());
|
||||||
|
});
|
||||||
|
|
||||||
|
return globalConfig;
|
||||||
|
}
|
||||||
|
|
||||||
@interface YGLayout ()
|
@interface YGLayout ()
|
||||||
|
|
||||||
@@ -172,17 +192,10 @@ static YGConfigRef globalConfig;
|
|||||||
@synthesize isIncludedInLayout = _isIncludedInLayout;
|
@synthesize isIncludedInLayout = _isIncludedInLayout;
|
||||||
@synthesize node = _node;
|
@synthesize node = _node;
|
||||||
|
|
||||||
+ (void)initialize {
|
|
||||||
globalConfig = YGConfigNew();
|
|
||||||
YGConfigSetExperimentalFeatureEnabled(
|
|
||||||
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
|
||||||
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithView:(UIView*)view {
|
- (instancetype)initWithView:(UIView*)view {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_view = view;
|
_view = view;
|
||||||
_node = YGNodeNewWithConfig(globalConfig);
|
_node = YGNodeNewWithConfig(YGGlobalConfig());
|
||||||
YGNodeSetContext(_node, (__bridge void*)view);
|
YGNodeSetContext(_node, (__bridge void*)view);
|
||||||
_isEnabled = NO;
|
_isEnabled = NO;
|
||||||
_isIncludedInLayout = YES;
|
_isIncludedInLayout = YES;
|
||||||
@@ -462,11 +475,7 @@ static void YGRemoveAllChildren(const YGNodeRef node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CGFloat YGRoundPixelValue(CGFloat value) {
|
static CGFloat YGRoundPixelValue(CGFloat value) {
|
||||||
static CGFloat scale;
|
CGFloat scale = YGScaleFactor();
|
||||||
static dispatch_once_t onceToken;
|
|
||||||
dispatch_once(&onceToken, ^() {
|
|
||||||
scale = [UIScreen mainScreen].scale;
|
|
||||||
});
|
|
||||||
|
|
||||||
return ceil(value * scale) / scale; // Pixel-align
|
return ceil(value * scale) / scale; // Pixel-align
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user