[yoga] Support SPM (Swift Package Manager) #1096
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: "YogaKit",
|
||||
exclude: ["Source/YGLayoutExtensions.swift"],
|
||||
sources: ["Source"],
|
||||
publicHeadersPath: "Source/modulemap",
|
||||
cSettings: [
|
||||
.headerSearchPath("..")
|
||||
]),
|
||||
.target(
|
||||
name: "Yoga",
|
||||
path: "yoga",
|
||||
sources: ["."],
|
||||
publicHeadersPath: "modulemap",
|
||||
cSettings: [
|
||||
.headerSearchPath("..")
|
||||
])
|
||||
],
|
||||
cLanguageStandard: .gnu11,
|
||||
cxxLanguageStandard: .gnucxx14
|
||||
)
|
@@ -5,8 +5,16 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "YGLayout.h"
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
@import AppKit;
|
||||
#define UIView NSView
|
||||
#else
|
||||
@import UIKit;
|
||||
#endif
|
||||
|
||||
#import "YogaKit.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@@ -5,9 +5,9 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <objc/runtime.h>
|
||||
#import "UIView+Yoga.h"
|
||||
#import "YGLayout+Private.h"
|
||||
@import ObjectiveC;
|
||||
|
||||
static const void* kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
|
||||
|
||||
|
@@ -5,8 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <yoga/Yoga.h>
|
||||
#import "YGLayout.h"
|
||||
#import "../../yoga/Yoga.h"
|
||||
#import "YogaKit.h"
|
||||
|
||||
@interface YGLayout ()
|
||||
|
||||
|
@@ -5,10 +5,17 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <yoga/YGEnums.h>
|
||||
#import <yoga/YGMacros.h>
|
||||
#import <yoga/Yoga.h>
|
||||
#import <TargetConditionals.h>
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
@import AppKit;
|
||||
#else
|
||||
@import UIKit;
|
||||
#endif
|
||||
|
||||
#import "../../yoga/YGEnums.h"
|
||||
#import "../../yoga/YGMacros.h"
|
||||
#import "../../yoga/Yoga.h"
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
@@ -158,6 +158,20 @@ YGValue YGPercentValue(CGFloat value) {
|
||||
|
||||
static YGConfigRef globalConfig;
|
||||
|
||||
static CGFloat scaleFactor(void) {
|
||||
static CGFloat scaleFactor = 1;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
#if TARGET_OS_OSX
|
||||
scaleFactor = [NSScreen mainScreen].backingScaleFactor;
|
||||
#else
|
||||
scaleFactor = [UIScreen mainScreen].scale;
|
||||
#endif
|
||||
});
|
||||
|
||||
return scaleFactor;
|
||||
}
|
||||
|
||||
@interface YGLayout ()
|
||||
|
||||
@property(nonatomic, weak, readonly) UIView* view;
|
||||
@@ -175,7 +189,7 @@ static YGConfigRef globalConfig;
|
||||
globalConfig = YGConfigNew();
|
||||
YGConfigSetExperimentalFeatureEnabled(
|
||||
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
||||
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
|
||||
YGConfigSetPointScaleFactor(globalConfig, scaleFactor());
|
||||
}
|
||||
|
||||
- (instancetype)initWithView:(UIView*)view {
|
||||
@@ -362,10 +376,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 +474,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;
|
5
YogaKit/Source/modulemap/module.modulemap
Normal file
5
YogaKit/Source/modulemap/module.modulemap
Normal file
@@ -0,0 +1,5 @@
|
||||
module YogaKit {
|
||||
header "../YogaKit.h"
|
||||
header "../UIView+Yoga.h"
|
||||
export *
|
||||
}
|
7
yoga/modulemap/module.modulemap
Normal file
7
yoga/modulemap/module.modulemap
Normal file
@@ -0,0 +1,7 @@
|
||||
module Yoga [extern_c] {
|
||||
header "../Yoga.h"
|
||||
header "../YGValue.h"
|
||||
header "../YGMacros.h"
|
||||
header "../YGEnums.h"
|
||||
export *
|
||||
}
|
Reference in New Issue
Block a user