From 7cfc2f6095677af74b2574f2cb8d163db4a39642 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Sun, 6 Dec 2015 20:56:54 +0100 Subject: [PATCH 1/2] renaming direction to flexDirection and using correct enum --- Few-Mac/Label.swift | 19 +++++++++++-- Few-iOS/Label.swift | 20 ++++++++++++-- FewCore/Element.swift | 43 +++++++++++++++++++++++------- FewDemo-iOS/ViewController.swift | 14 +++++----- FewDemo/AppDelegate.swift | 4 +-- FewDemo/Counter.swift | 2 +- FewDemo/Demo.swift | 12 ++++----- FewDemo/TemperatureConverter.swift | 4 +-- 8 files changed, 87 insertions(+), 31 deletions(-) diff --git a/Few-Mac/Label.swift b/Few-Mac/Label.swift index 3832b40..225b879 100644 --- a/Few-Mac/Label.swift +++ b/Few-Mac/Label.swift @@ -65,8 +65,23 @@ public class Label: Element { public override func assembleLayoutNode() -> Node { let childNodes = children.map { $0.assembleLayoutNode() } - return Node(size: frame.size, children: childNodes, direction: direction, margin: marginWithPlatformSpecificAdjustments, padding: paddingWithPlatformSpecificAdjustments, wrap: wrap, justification: justification, selfAlignment: selfAlignment, childAlignment: childAlignment, flex: flex) { w in - estimateStringSize(self.attributedString, maxSize: CGSize(width: w.isNaN ? ABigDimension : w, height: ABigDimension)) + return Node( + size: frame.size, + children: childNodes, + flexDirection: flexDirection, + margin: marginWithPlatformSpecificAdjustments, + padding: paddingWithPlatformSpecificAdjustments, + wrap: wrap, + justification: justification, + selfAlignment: selfAlignment, + childAlignment: childAlignment, + flex: flex + ) { w in + estimateStringSize( + self.attributedString, + maxSize: CGSize( + width: w.isNaN ? ABigDimension : w, + height: ABigDimension)) } } } diff --git a/Few-iOS/Label.swift b/Few-iOS/Label.swift index d1e5d8e..af4a8b2 100644 --- a/Few-iOS/Label.swift +++ b/Few-iOS/Label.swift @@ -72,8 +72,24 @@ public class Label: Element { public override func assembleLayoutNode() -> Node { let childNodes = children.map { $0.assembleLayoutNode() } - return Node(size: frame.size, children: childNodes, direction: direction, margin: marginWithPlatformSpecificAdjustments, padding: paddingWithPlatformSpecificAdjustments, wrap: wrap, justification: justification, selfAlignment: selfAlignment, childAlignment: childAlignment, flex: flex) { w in - estimateStringSize(self.attributedString, maxSize: CGSize(width: w.isNaN ? ABigDimension : w, height: ABigDimension), numberOfLines: self.numberOfLines) + return Node( + size: frame.size, + children: childNodes, + flexDirection: flexDirection, + margin: marginWithPlatformSpecificAdjustments, + padding: paddingWithPlatformSpecificAdjustments, + wrap: wrap, + justification: justification, + selfAlignment: selfAlignment, + childAlignment: childAlignment, + flex: flex + ) { w in + estimateStringSize( + self.attributedString, + maxSize: CGSize( + width: w.isNaN ? ABigDimension : w, + height: ABigDimension), + numberOfLines: self.numberOfLines) } } } diff --git a/FewCore/Element.swift b/FewCore/Element.swift index 52a50e5..be83147 100644 --- a/FewCore/Element.swift +++ b/FewCore/Element.swift @@ -36,7 +36,7 @@ public class Element { public var children: [Element] { didSet { #if os(OSX) - if direction == .Column { + if flexDirection == .Column { children = children.reverse() } #endif @@ -44,15 +44,15 @@ public class Element { } #if os(OSX) - public var direction: Direction { + public var flexDirection: FlexDirection { didSet { - if direction != oldValue { + if flexDirection != oldValue { children = children.reverse() } } } #else - public var direction: Direction + public var flexDirection: FlexDirection #endif public var margin: Edges @@ -66,14 +66,29 @@ public class Element { /// Should the input make itself the focus after it's been realized? public var autofocus: Bool - public init(frame: CGRect = CGRect(x: 0, y: 0, width: Node.Undefined, height: Node.Undefined), key: String? = nil, hidden: Bool = false, alpha: CGFloat = 1, autofocus: Bool = false, children: [Element] = [], direction: Direction = .Row, margin: Edges = Edges(), padding: Edges = Edges(), wrap: Bool = false, justification: Justification = .FlexStart, selfAlignment: SelfAlignment = .Auto, childAlignment: ChildAlignment = .Stretch, flex: CGFloat = 0) { + public init( + frame: CGRect = CGRect(x: 0, y: 0, width: Node.Undefined, height: Node.Undefined), + key: String? = nil, + hidden: Bool = false, + alpha: CGFloat = 1, + autofocus: Bool = false, + children: [Element] = [], + flexDirection: FlexDirection = .Row, + margin: Edges = Edges(), + padding: Edges = Edges(), + wrap: Bool = false, + justification: Justification = .FlexStart, + selfAlignment: SelfAlignment = .Auto, + childAlignment: ChildAlignment = .Stretch, + flex: CGFloat = 0 + ) { self.frame = frame self.key = key self.hidden = hidden self.alpha = alpha self.autofocus = autofocus self.children = children - self.direction = direction + self.flexDirection = flexDirection self.margin = margin self.padding = padding self.wrap = wrap @@ -193,7 +208,17 @@ public class Element { public func assembleLayoutNode() -> Node { let childNodes = children.map { $0.assembleLayoutNode() } - return Node(size: frame.size, children: childNodes, direction: direction, margin: marginWithPlatformSpecificAdjustments, padding: paddingWithPlatformSpecificAdjustments, wrap: wrap, justification: justification, selfAlignment: selfAlignment, childAlignment: childAlignment, flex: flex) + return Node( + size: frame.size, + children: childNodes, + flexDirection: flexDirection, + margin: marginWithPlatformSpecificAdjustments, + padding: paddingWithPlatformSpecificAdjustments, + wrap: wrap, + justification: justification, + selfAlignment: selfAlignment, + childAlignment: childAlignment, + flex: flex) } private final func verticallyFlippedEdges(edges: Edges) -> Edges { @@ -278,8 +303,8 @@ extension Element { return self } - public func direction(d: Direction) -> Self { - direction = d + public func flexDirection(d: FlexDirection) -> Self { + flexDirection = d return self } diff --git a/FewDemo-iOS/ViewController.swift b/FewDemo-iOS/ViewController.swift index 9307b39..3b97338 100644 --- a/FewDemo-iOS/ViewController.swift +++ b/FewDemo-iOS/ViewController.swift @@ -18,7 +18,7 @@ func renderCounter(component: Component, count: Int) -> Element { // The children should be centered in the view. .childAlignment(.Center) // Layout children in a column. - .direction(.Column) + .flexDirection(.Column) .flex(1) .children([ Label("You've clicked \(count) times!"), @@ -32,7 +32,7 @@ let Counter = { Component(initialState: 0, render: renderCounter) } private func renderRow1(row: Int) -> Element { return Element() - .direction(.Row) + .flexDirection(.Row) .padding(Edges(uniform: 10)) .children([ Image(UIImage(named: "Apple_Swift_Logo.png")) @@ -40,7 +40,7 @@ private func renderRow1(row: Int) -> Element { .selfAlignment(.FlexStart), Element() .margin(Edges(left: 10)) - .direction(.Column) + .flexDirection(.Column) .children([ Label("I am a banana.", textColor: UIColor.blackColor(), font: UIFont.systemFontOfSize(18)), Label("\(row)", textColor: UIColor.greenColor()) @@ -50,7 +50,7 @@ private func renderRow1(row: Int) -> Element { private func renderRow2(row: Int) -> Element { return Element() - .direction(.Row) + .flexDirection(.Row) .padding(Edges(uniform: 10)) .children([ Image(UIImage(named: "Apple_Swift_Logo.png")) @@ -58,7 +58,7 @@ private func renderRow2(row: Int) -> Element { .selfAlignment(.FlexStart), Element() .margin(Edges(left: 10)) - .direction(.Column) + .flexDirection(.Column) .children([ Label("I am a banana.", textColor: UIColor.redColor(), font: UIFont.systemFontOfSize(18)), Label("\(row)", textColor: UIColor.greenColor()) @@ -108,7 +108,7 @@ func renderInput(component: Component, state: String) -> Element { .flex(1) .children([ View(backgroundColor: UIColor.greenColor()) - .direction(.Column) + .flexDirection(.Column) .children([ View(backgroundColor: UIColor.blueColor(), borderColor: UIColor.blackColor(), borderWidth: 2, cornerRadius: 5) .margin(Edges(uniform: 10)) @@ -153,7 +153,7 @@ func renderApp(component: Component, state: AppState) -> Element { let showMore = { component.updateState(toggleDisplay) } return Element() - .direction(.Column) + .flexDirection(.Column) .children([ Element() .children([ diff --git a/FewDemo/AppDelegate.swift b/FewDemo/AppDelegate.swift index 1cce26a..24cbe6a 100644 --- a/FewDemo/AppDelegate.swift +++ b/FewDemo/AppDelegate.swift @@ -29,7 +29,7 @@ func renderApp(component: Component, state: ActiveComponent) -> return Element() .justification(.Center) .childAlignment(.Center) - .direction(.Column) + .flexDirection(.Column) .children([ contentComponent, CustomButton(title: "Show me more!") { @@ -39,7 +39,7 @@ func renderApp(component: Component, state: ActiveComponent) -> ]) // return Element() -// .direction(.Column) +// .flexDirection(.Column) // .justification(.Center) // .children([ // Element().height(90).children([ diff --git a/FewDemo/Counter.swift b/FewDemo/Counter.swift index a8a2fbf..7078a52 100644 --- a/FewDemo/Counter.swift +++ b/FewDemo/Counter.swift @@ -24,7 +24,7 @@ class Counter_: Component { // The children should be centered in the view. .childAlignment(.Center) // Layout children in a column. - .direction(.Column) + .flexDirection(.Column) .children([ Label("You've clicked \(count) times!"), Button(title: "Click me!", action: { diff --git a/FewDemo/Demo.swift b/FewDemo/Demo.swift index e145800..065f096 100644 --- a/FewDemo/Demo.swift +++ b/FewDemo/Demo.swift @@ -32,7 +32,7 @@ private func renderInput(component: Component, label: String, secure } return Element() - .direction(.Row) + .flexDirection(.Row) .padding(Edges(bottom: 4)) .children([ Label(label).size(75, 19), @@ -80,7 +80,7 @@ private func renderScrollView() -> Element { keyDown: { _, event in return keyDown(event, component: component) }) - .direction(.Column) + .flexDirection(.Column) .children([ Label("\(items.count) \(itemPlurality)"), TableView(items, selectionChanged: { row in @@ -93,7 +93,7 @@ private func renderScrollView() -> Element { private func renderRow1(row: Int) -> Element { return Element() - .direction(.Column) + .flexDirection(.Column) .children([ Label("\(row)"), Label("I am a banana.", textColor: .blackColor(), font: .systemFontOfSize(18)), @@ -103,7 +103,7 @@ private func renderRow1(row: Int) -> Element { private func renderRow2(row: Int) -> Element { return Element() - .direction(.Row) + .flexDirection(.Row) .children([ Image(NSImage(named: NSImageNameApplicationIcon)).size(14, 14), Label("I am a banana.", textColor: .redColor(), font: .systemFontOfSize(11)), @@ -114,7 +114,7 @@ private func renderLogin() -> Element { return Component(initialState: LoginState()) { component, state in let loginEnabled = !state.username.isEmpty && !state.password.isEmpty return Element() - .direction(.Column) + .flexDirection(.Column) .children([ renderThingy(state.username.utf16.count), renderInput(component, label: "Username", secure: false) { @@ -145,7 +145,7 @@ class Demo_: Component<()> { return Element() .justification(.Center) .childAlignment(.Center) - .direction(.Column) + .flexDirection(.Column) .children([ renderLogin(), renderScrollView().size(100, 200), diff --git a/FewDemo/TemperatureConverter.swift b/FewDemo/TemperatureConverter.swift index 5a5b3be..9f1ad61 100644 --- a/FewDemo/TemperatureConverter.swift +++ b/FewDemo/TemperatureConverter.swift @@ -30,7 +30,7 @@ private func f2c(f: CGFloat) -> CGFloat { private func renderLabeledInput(label: String, value: String, autofocus: Bool, fn: String -> ()) -> Element { return Element() - .direction(.Row) + .flexDirection(.Row) .padding(Edges(bottom: 4)) .children([ Label(label).width(75), @@ -58,7 +58,7 @@ class TemperatureConverter_: Component { return Element() .justification(.Center) .childAlignment(.Center) - .direction(.Column) + .flexDirection(.Column) .children([ renderLabeledInput("Fahrenheit", value: "\(state.fahrenheit)", autofocus: true) { if let f = parseFloat($0) { From 7f3ab26c45b4e6b67a2464aa0cc1800b4a341247 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Sun, 6 Dec 2015 21:00:39 +0100 Subject: [PATCH 2/2] updated dependencies, binaries are build with correct Xcode version removes "Module file was created by an older version of the compiler" error for Quick --- Cartfile.private | 4 ++-- Cartfile.resolved | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cartfile.private b/Cartfile.private index 9ebafb7..35c778f 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,2 +1,2 @@ -github "Quick/Quick" "v0.6.0" -github "Quick/Nimble" "v2.0.0-rc.3" +github "Quick/Quick" "v0.8.0" +github "Quick/Nimble" "v3.0.0" diff --git a/Cartfile.resolved b/Cartfile.resolved index 7daa160..1a91b89 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Quick/Nimble" "v2.0.0-rc.3" -github "Quick/Quick" "v0.6.0" -github "joshaber/SwiftBox" "6ec5ef5492c411163d34cd46c46434bbd2181faf" +github "Quick/Nimble" "v3.0.0" +github "Quick/Quick" "v0.8.0" +github "joshaber/SwiftBox" "c316daebb98237a0c20c5fc7cb92028f44809861"