diff --git a/YogaKit/UIView+YogaKit.h b/YogaKit/UIView+YogaKit.h index 9d6b1f27..d6f0b8bf 100644 --- a/YogaKit/UIView+YogaKit.h +++ b/YogaKit/UIView+YogaKit.h @@ -15,25 +15,25 @@ /** The property that decides if we should include this view when calculating layout. Defaults to YES. */ -@property (nonatomic, setter=yk_setIncludeInLayout:) BOOL yk_includeInLayout; +@property (nonatomic, setter=yk_setIncludeInLayout:) BOOL yk_includeInLayout NS_SWIFT_NAME(includeInLayout); /** The property that decides during layout/sizing whether or not yk_* properties should be applied. Defaults to NO. */ -@property (nonatomic, setter=yk_setUsesYoga:) BOOL yk_usesYoga; +@property (nonatomic, setter=yk_setUsesYoga:) BOOL yk_usesYoga NS_SWIFT_NAME(usesYoga); -@property (nonatomic, setter=yk_setDirection:) YKDirection yk_direction; -@property (nonatomic, setter=yk_setFlexDirection:) YKFlexDirection yk_flexDirection; -@property (nonatomic, setter=yk_setJustifyContent:) YKJustify yk_justifyContent; -@property (nonatomic, setter=yk_setAlignContent:) YKAlign yk_alignContent; -@property (nonatomic, setter=yk_setAlignItems:) YKAlign yk_alignItems; -@property (nonatomic, setter=yk_setAlignSelf:) YKAlign yk_alignSelf; -@property (nonatomic, setter=yk_setPositionType:) YKPositionType yk_positionType; -@property (nonatomic, setter=yk_setFlexWrap:) YKWrap yk_flexWrap; +@property (nonatomic, setter=yk_setDirection:) YKDirection yk_direction NS_SWIFT_NAME(layoutDirection); +@property (nonatomic, setter=yk_setFlexDirection:) YKFlexDirection yk_flexDirection NS_SWIFT_NAME(layoutFlexDirection); +@property (nonatomic, setter=yk_setJustifyContent:) YKJustify yk_justifyContent NS_SWIFT_NAME(layoutJustifyContent); +@property (nonatomic, setter=yk_setAlignContent:) YKAlign yk_alignContent NS_SWIFT_NAME(layoutAlignContent); +@property (nonatomic, setter=yk_setAlignItems:) YKAlign yk_alignItems NS_SWIFT_NAME(layoutAlignItems); +@property (nonatomic, setter=yk_setAlignSelf:) YKAlign yk_alignSelf NS_SWIFT_NAME(layoutAlignSelf); +@property (nonatomic, setter=yk_setPositionType:) YKPositionType yk_positionType NS_SWIFT_NAME(layoutPositionType); +@property (nonatomic, setter=yk_setFlexWrap:) YKWrap yk_flexWrap NS_SWIFT_NAME(layoutFlexWrap); -@property (nonatomic, setter=yk_setFlexGrow:) CGFloat yk_flexGrow; -@property (nonatomic, setter=yk_setFlexShrink:) CGFloat yk_flexShrink; -@property (nonatomic, setter=yk_setFlexBasis:) CGFloat yk_flexBasis; +@property (nonatomic, setter=yk_setFlexGrow:) CGFloat yk_flexGrow NS_SWIFT_NAME(layoutFlexGrow); +@property (nonatomic, setter=yk_setFlexShrink:) CGFloat yk_flexShrink NS_SWIFT_NAME(layoutFlexShrink); +@property (nonatomic, setter=yk_setFlexBasis:) CGFloat yk_flexBasis NS_SWIFT_NAME(layoutFlexBasis); - (void)yk_positionForEdge:(YKEdge)edge; - (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge; @@ -42,34 +42,34 @@ - (void)yk_paddingForEdge:(YKEdge)edge; - (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge; -@property (nonatomic, setter=yk_setWidth:) CGFloat yk_width; -@property (nonatomic, setter=yk_setHeight:) CGFloat yk_height; -@property (nonatomic, setter=yk_setMinWidth:) CGFloat yk_minWidth; -@property (nonatomic, setter=yk_setMinHeight:) CGFloat yk_minHeight; -@property (nonatomic, setter=yk_setMaxWidth:) CGFloat yk_maxWidth; -@property (nonatomic, setter=yk_setMaxHeight:) CGFloat yk_maxHeight; +@property (nonatomic, setter=yk_setWidth:) CGFloat yk_width NS_SWIFT_NAME(layoutWidth); +@property (nonatomic, setter=yk_setHeight:) CGFloat yk_height NS_SWIFT_NAME(layoutHeight); +@property (nonatomic, setter=yk_setMinWidth:) CGFloat yk_minWidth NS_SWIFT_NAME(layoutMinWidth); +@property (nonatomic, setter=yk_setMinHeight:) CGFloat yk_minHeight NS_SWIFT_NAME(layoutMinHeight); +@property (nonatomic, setter=yk_setMaxWidth:) CGFloat yk_maxWidth NS_SWIFT_NAME(layoutMaxWidth); +@property (nonatomic, setter=yk_setMaxHeight:) CGFloat yk_maxHeight NS_SWIFT_NAME(layoutMaxHeight); // Yoga specific properties, not compatible with flexbox specification -@property (nonatomic, setter=yk_setAspectRatio:) CGFloat yk_aspectRatio; +@property (nonatomic, setter=yk_setAspectRatio:) CGFloat yk_aspectRatio NS_SWIFT_NAME(layoutAspectRatio); /** Get the resolved direction of this node. This won't be YGDirectionInherit */ -@property (nonatomic, readonly) CGFloat yk_resolvedDirection; +@property (nonatomic, readonly) CGFloat yk_resolvedDirection NS_SWIFT_NAME(layoutResolvedDirection); /** Perform a layout calculation and update the frames of the views in the hierarchy with the results */ -- (void)yk_applyLayout; +- (void)yk_applyLayout NS_SWIFT_NAME(applyLayout()); /** Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; */ -@property (nonatomic, readonly) CGSize yk_intrinsicSize; +@property (nonatomic, readonly) CGSize yk_intrinsicSize NS_SWIFT_NAME(layoutIntrinsicSize); /** Returns the number of children that are using Flexbox. */ -@property (nonatomic, readonly) NSUInteger yk_numberOfChildren; +@property (nonatomic, readonly) NSUInteger yk_numberOfChildren NS_SWIFT_NAME(layoutNumberOfChildren); @end diff --git a/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj b/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj index 011a3824..a3eb674e 100644 --- a/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj +++ b/YogaKit/YogaKit/YogaKit.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 63EE08501E06EECB00EE5F9A /* Yoga.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D631DF8778F00E7C260 /* Yoga.h */; }; 63EE08511E06EECB00EE5F9A /* UIView+YogaKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 13687D691DF8778F00E7C260 /* UIView+YogaKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 63EE08531E06F3D100EE5F9A /* YKEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 63EE08521E06F3D100EE5F9A /* YKEnums.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 63EE08551E072EF800EE5F9A /* SwiftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63EE08541E072EF800EE5F9A /* SwiftViewController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -72,6 +73,7 @@ 63EE083F1E06ED3D00EE5F9A /* YogaKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YogaKit.h; sourceTree = ""; }; 63EE08401E06ED3D00EE5F9A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 63EE08521E06F3D100EE5F9A /* YKEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = YKEnums.h; path = ../../YKEnums.h; sourceTree = ""; }; + 63EE08541E072EF800EE5F9A /* SwiftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -121,6 +123,7 @@ 13687D4A1DF8748400E7C260 /* AppDelegate.m */, 13687D4C1DF8748400E7C260 /* ViewController.h */, 13687D4D1DF8748400E7C260 /* ViewController.m */, + 63EE08541E072EF800EE5F9A /* SwiftViewController.swift */, 13687D521DF8748400E7C260 /* Assets.xcassets */, 13687D571DF8748400E7C260 /* Info.plist */, 13687D461DF8748400E7C260 /* Supporting Files */, @@ -238,6 +241,7 @@ TargetAttributes = { 13687D421DF8748300E7C260 = { CreatedOnToolsVersion = 8.1; + LastSwiftMigration = 0820; ProvisioningStyle = Automatic; }; 63EE083C1E06ED3D00EE5F9A = { @@ -288,6 +292,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 63EE08551E072EF800EE5F9A /* SwiftViewController.swift in Sources */, 13687D4E1DF8748400E7C260 /* ViewController.m in Sources */, 13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */, 13687D481DF8748400E7C260 /* main.m in Sources */, @@ -409,10 +414,13 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = YogaKitSample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -420,10 +428,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; INFOPLIST_FILE = YogaKitSample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate b/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate index a338638b..daec9dbc 100644 Binary files a/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate and b/YogaKit/YogaKit/YogaKit.xcodeproj/project.xcworkspace/xcuserdata/david.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/YogaKit/YogaKit/YogaKitSample/SwiftViewController.swift b/YogaKit/YogaKit/YogaKitSample/SwiftViewController.swift new file mode 100644 index 00000000..40c032ef --- /dev/null +++ b/YogaKit/YogaKit/YogaKitSample/SwiftViewController.swift @@ -0,0 +1,41 @@ +// +// SwiftViewController.swift +// YogaKit +// +// Created by David Hart on 18.12.16. +// Copyright © 2016 facebook. All rights reserved. +// + +import UIKit +import YogaKit + +class SwiftViewController : UIViewController { + override func viewDidLoad() { + let root = view! + root.backgroundColor = .red + root.usesYoga = true + root.layoutWidth = view.bounds.size.width + root.layoutHeight = view.bounds.size.height + root.layoutAlignItems = .center + root.layoutJustifyContent = .center + + let child1 = UIView() + child1.backgroundColor = .blue + child1.usesYoga = true + child1.layoutWidth = 100 + child1.layoutHeight = 100 + + let child2 = UIView() + child2.backgroundColor = .green + child2.frame = CGRect(origin: .zero, size: CGSize(width: 200, height: 100)) + + let child3 = UIView() + child3.backgroundColor = .yellow + child3.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100)) + + child2.addSubview(child3) + root.addSubview(child1) + root.addSubview(child2) + root.applyLayout() + } +} diff --git a/YogaKit/YogaKit/YogaKitSample/ViewController.h b/YogaKit/YogaKit/YogaKitSample/ViewController.h index f5642871..e9c49504 100644 --- a/YogaKit/YogaKit/YogaKitSample/ViewController.h +++ b/YogaKit/YogaKit/YogaKitSample/ViewController.h @@ -10,6 +10,5 @@ @interface ViewController : UIViewController - @end