[yoga] Support SPM (Swift Package Manager)

This commit is contained in:
Lvv.me
2021-07-05 21:27:24 +08:00
parent 578d197dd6
commit 02a002f594
4 changed files with 78 additions and 2 deletions

View File

@@ -157,6 +157,11 @@ YGValue YGPercentValue(CGFloat value) {
}
static YGConfigRef globalConfig;
#if TARGET_OS_OSX
NS_INLINE CGFloat scaleFactor() { return [NSScreen mainScreen].backingScaleFactor; }
#else
NS_INLINE CGFloat scaleFactor() { return [UIScreen mainScreen].scale; }
#endif
@interface YGLayout ()
@@ -175,7 +180,7 @@ static YGConfigRef globalConfig;
globalConfig = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
YGConfigSetPointScaleFactor(globalConfig, scaleFactor());
}
- (instancetype)initWithView:(UIView*)view {
@@ -362,10 +367,18 @@ static YGSize YGMeasureView(
//
// See https://github.com/facebook/yoga/issues/606 for more information.
if (!view.yoga.isUIView || [view.subviews count] > 0) {
#if TARGET_OS_OSX
CGSize fittingSize = view.fittingSize;
sizeThatFits = (CGSize){
.width = fmin(constrainedWidth, fittingSize.width),
.height = fmin(constrainedHeight, fittingSize.height)
};
#else
sizeThatFits = [view sizeThatFits:(CGSize){
.width = constrainedWidth,
.height = constrainedHeight,
}];
#endif
}
return (YGSize){
@@ -452,7 +465,7 @@ static CGFloat YGRoundPixelValue(CGFloat value) {
static CGFloat scale;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^() {
scale = [UIScreen mainScreen].scale;
scale = scaleFactor();
});
return roundf(value * scale) / scale;