[yoga] Support SPM (Swift Package Manager) #1096

Closed
cntrump wants to merge 6 commits from pr_swift_package_manager_support into main
28 changed files with 89 additions and 237 deletions
Showing only changes of commit 02a002f594 - Show all commits

48
Package.swift Normal file
View File

@@ -0,0 +1,48 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "yoga",
platforms: [
.macOS(.v10_10), .iOS(.v9), .tvOS(.v9)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "YogaKit",
targets: ["YogaKit"]),
.library(
name: "Yoga",
targets: ["Yoga"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "YogaKit",
dependencies: ["Yoga"],
path: ".",
exclude: ["YogaKit/Source/YGLayoutExtensions.swift"],
sources: ["YogaKit/Source"],
publicHeadersPath: "YogaKit/Source",
cSettings: [
.headerSearchPath(".")
]),
.target(
name: "Yoga",
path: ".",
sources: ["yoga"],
publicHeadersPath: "yoga/include",
cSettings: [
.headerSearchPath(".")
])
],
cLanguageStandard: .gnu11,
cxxLanguageStandard: .gnucxx14
)

View File

@@ -5,7 +5,15 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#define UIView NSView
#else
#import <UIKit/UIKit.h>
#endif
#import "YGLayout.h"
NS_ASSUME_NONNULL_BEGIN

View File

@@ -5,7 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#import <TargetConditionals.h>
#if TARGET_OS_OSX
#import <AppKit/AppKit.h>
#else
#import <UIKit/UIKit.h>
#endif
#import <yoga/YGEnums.h>
#import <yoga/YGMacros.h>
#import <yoga/Yoga.h>

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;