[yoga] Support SPM (Swift Package Manager)
This commit is contained in:
48
Package.swift
Normal file
48
Package.swift
Normal 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
|
||||||
|
)
|
@@ -5,7 +5,15 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* 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>
|
#import <UIKit/UIKit.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#import "YGLayout.h"
|
#import "YGLayout.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
@@ -5,7 +5,14 @@
|
|||||||
* LICENSE file in the root directory of this source tree.
|
* 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>
|
#import <UIKit/UIKit.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#import <yoga/YGEnums.h>
|
#import <yoga/YGEnums.h>
|
||||||
#import <yoga/YGMacros.h>
|
#import <yoga/YGMacros.h>
|
||||||
#import <yoga/Yoga.h>
|
#import <yoga/Yoga.h>
|
||||||
|
@@ -157,6 +157,11 @@ YGValue YGPercentValue(CGFloat value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static YGConfigRef globalConfig;
|
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 ()
|
@interface YGLayout ()
|
||||||
|
|
||||||
@@ -175,7 +180,7 @@ static YGConfigRef globalConfig;
|
|||||||
globalConfig = YGConfigNew();
|
globalConfig = YGConfigNew();
|
||||||
YGConfigSetExperimentalFeatureEnabled(
|
YGConfigSetExperimentalFeatureEnabled(
|
||||||
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
||||||
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
|
YGConfigSetPointScaleFactor(globalConfig, scaleFactor());
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithView:(UIView*)view {
|
- (instancetype)initWithView:(UIView*)view {
|
||||||
@@ -362,10 +367,18 @@ static YGSize YGMeasureView(
|
|||||||
//
|
//
|
||||||
// See https://github.com/facebook/yoga/issues/606 for more information.
|
// See https://github.com/facebook/yoga/issues/606 for more information.
|
||||||
if (!view.yoga.isUIView || [view.subviews count] > 0) {
|
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){
|
sizeThatFits = [view sizeThatFits:(CGSize){
|
||||||
.width = constrainedWidth,
|
.width = constrainedWidth,
|
||||||
.height = constrainedHeight,
|
.height = constrainedHeight,
|
||||||
}];
|
}];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return (YGSize){
|
return (YGSize){
|
||||||
@@ -452,7 +465,7 @@ static CGFloat YGRoundPixelValue(CGFloat value) {
|
|||||||
static CGFloat scale;
|
static CGFloat scale;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^() {
|
dispatch_once(&onceToken, ^() {
|
||||||
scale = [UIScreen mainScreen].scale;
|
scale = scaleFactor();
|
||||||
});
|
});
|
||||||
|
|
||||||
return roundf(value * scale) / scale;
|
return roundf(value * scale) / scale;
|
||||||
|
Reference in New Issue
Block a user