Skip to content

Commit 99ddd6e

Browse files
authored
Merge pull request #159 from rantingmong/mong/baselinelayout
Add baseline item support!
2 parents 397dbe6 + 85cee6d commit 99ddd6e

File tree

8 files changed

+297
-14
lines changed

8 files changed

+297
-14
lines changed

Example/FlexLayoutSample.xcodeproj/project.pbxproj

+22-9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
24FB883E1F59CA8B00615D33 /* TableViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */; };
3636
24FB88411F59CA9A00615D33 /* MethodCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883F1F59CA9A00615D33 /* MethodCell.swift */; };
3737
24FB88421F59CA9A00615D33 /* MethodGroupHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */; };
38+
60BAE156247DF4120020119C /* YogaExampleFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE155247DF4120020119C /* YogaExampleFView.swift */; };
39+
60BAE158247DF4CE0020119C /* YogaExampleFViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */; };
3840
B9BDD93E240A70C3005298B3 /* FlexLayout in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD93D240A70C3005298B3 /* FlexLayout */; };
3941
B9BDD940240A70C3005298B3 /* FlexLayoutYoga in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD93F240A70C3005298B3 /* FlexLayoutYoga */; };
4042
B9BDD942240A70C3005298B3 /* FlexLayoutYogaKit in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD941240A70C3005298B3 /* FlexLayoutYogaKit */; };
@@ -134,6 +136,8 @@
134136
24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewExampleViewController.swift; sourceTree = "<group>"; };
135137
24FB883F1F59CA9A00615D33 /* MethodCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MethodCell.swift; sourceTree = "<group>"; };
136138
24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MethodGroupHeader.swift; sourceTree = "<group>"; };
139+
60BAE155247DF4120020119C /* YogaExampleFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFView.swift; sourceTree = "<group>"; };
140+
60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFViewController.swift; sourceTree = "<group>"; };
137141
82FCE524E22C2FF5BC4DFBAB /* Pods_FlexLayoutSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayoutSample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
138142
8561ACDBCFFA1B4B9ABEAB16 /* Pods-FlexLayoutSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlexLayoutSample.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample.debug.xcconfig"; sourceTree = "<group>"; };
139143
B9EA7C522409B79B000D8E35 /* FlexLayoutSampleSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlexLayoutSampleSPM.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -192,16 +196,17 @@
192196
2439CC371E665C5E003326FB /* Examples */ = {
193197
isa = PBXGroup;
194198
children = (
199+
24901F071F93D40F0025D11B /* CollectionViewExample */,
200+
247D73421F6757A00001AE2C /* Example1 */,
195201
24B14C581F278CB400C90490 /* Intro */,
196202
24E835131F4CC323009F95CC /* RaywenderlichTutorial */,
197-
24901F071F93D40F0025D11B /* CollectionViewExample */,
198203
24FB883A1F59CA7800615D33 /* TableViewExample */,
199-
247D73421F6757A00001AE2C /* Example1 */,
200204
DF91747C1F1F6F8B0034632D /* YogaExampleA */,
201205
DF0E85281F1F742C00AB1956 /* YogaExampleB */,
202206
24CD0D121F1F8D1100D56FC3 /* YogaExampleC */,
203207
24CD0D171F1F8E3D00D56FC3 /* YogaExampleD */,
204208
24CD0D1C1F1F90AF00D56FC3 /* YogaExampleE */,
209+
60BAE154247DF3F40020119C /* YogaExampleF */,
205210
);
206211
path = Examples;
207212
sourceTree = "<group>";
@@ -366,6 +371,15 @@
366371
name = Frameworks;
367372
sourceTree = "<group>";
368373
};
374+
60BAE154247DF3F40020119C /* YogaExampleF */ = {
375+
isa = PBXGroup;
376+
children = (
377+
60BAE155247DF4120020119C /* YogaExampleFView.swift */,
378+
60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */,
379+
);
380+
path = YogaExampleF;
381+
sourceTree = "<group>";
382+
};
369383
85CAAE97812075333AF3E88F /* Pods */ = {
370384
isa = PBXGroup;
371385
children = (
@@ -529,15 +543,12 @@
529543
buildActionMask = 2147483647;
530544
files = (
531545
);
532-
inputPaths = (
533-
"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks.sh",
534-
"${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework",
535-
"${BUILT_PRODUCTS_DIR}/PinLayout/PinLayout.framework",
546+
inputFileListPaths = (
547+
"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
536548
);
537549
name = "[CP] Embed Pods Frameworks";
538-
outputPaths = (
539-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework",
540-
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinLayout.framework",
550+
outputFileListPaths = (
551+
"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
541552
);
542553
runOnlyForDeploymentPostprocessing = 0;
543554
shellPath = /bin/sh;
@@ -610,10 +621,12 @@
610621
24FB883D1F59CA8B00615D33 /* TableViewExampleView.swift in Sources */,
611622
242AECE41FA011630024E7C2 /* BasicView.swift in Sources */,
612623
24AADD4B1F4E177700CB77E6 /* ShowTableViewCell.swift in Sources */,
624+
60BAE158247DF4CE0020119C /* YogaExampleFViewController.swift in Sources */,
613625
242AECE31FA011630024E7C2 /* BaseViewController.swift in Sources */,
614626
24901F0C1F93D40F0025D11B /* CollectionViewExampleView.swift in Sources */,
615627
DF0E852C1F1F749C00AB1956 /* YogaExampleBViewController.swift in Sources */,
616628
DF1F2A091F17D11700BA1B97 /* MenuView.swift in Sources */,
629+
60BAE156247DF4120020119C /* YogaExampleFView.swift in Sources */,
617630
24AADD4C1F4E177700CB77E6 /* ExpandedTableView.swift in Sources */,
618631
DF91747F1F1F6F9A0034632D /* YogaExampleAView.swift in Sources */,
619632
24FB88421F59CA9A00615D33 /* MethodGroupHeader.swift in Sources */,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
5+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
6+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
7+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
9+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
11+
// POSSIBILITY OF SUCH DAMAGE.
12+
//
13+
// Created by Michael Ong on 2020-05-27.
14+
15+
import UIKit
16+
import FlexLayout
17+
import PinLayout
18+
19+
class YogaExampleFView: UIView {
20+
fileprivate let rootFlexContainer = UIView()
21+
22+
init() {
23+
super.init(frame: .zero)
24+
backgroundColor = .white
25+
26+
let imageView = UIView()
27+
imageView.backgroundColor = .flexLayoutColor
28+
29+
// Yoga's Android example
30+
rootFlexContainer.flex.padding(20).direction(.column).define {
31+
32+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
33+
34+
let label = UILabel()
35+
36+
label.font = .systemFont(ofSize: 20)
37+
label.text = "Leading Font"
38+
39+
$0.addItem(label).marginRight(5).markDirty()
40+
41+
let info = UILabel()
42+
43+
info.font = .systemFont(ofSize: 10)
44+
info.text = "Trailing Font"
45+
46+
$0.addItem(info).markDirty()
47+
}
48+
49+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
50+
51+
let label = UILabel()
52+
53+
label.font = .systemFont(ofSize: 20)
54+
label.text = "Leading Multiline\nText Oh yeah!"
55+
label.numberOfLines = 2
56+
57+
$0.addItem(label).marginRight(5).markDirty()
58+
59+
let info = UILabel()
60+
61+
info.font = .systemFont(ofSize: 10)
62+
info.text = "Trailing Font"
63+
64+
$0.addItem(info).markDirty()
65+
}
66+
67+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
68+
69+
let label = UILabel()
70+
71+
label.font = .systemFont(ofSize: 12)
72+
label.text = "Name:"
73+
label.numberOfLines = 2
74+
75+
$0.addItem(label).marginRight(5).markDirty()
76+
77+
let info = UITextField()
78+
79+
info.font = .systemFont(ofSize: 16)
80+
info.placeholder = "Enter name here!"
81+
82+
$0.addItem(info).markDirty()
83+
}
84+
85+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
86+
87+
let label = UILabel()
88+
89+
label.font = .systemFont(ofSize: 12)
90+
label.text = "Age:"
91+
label.numberOfLines = 2
92+
93+
$0.addItem(label).marginRight(5).markDirty()
94+
95+
let info = UITextField()
96+
97+
info.borderStyle = .roundedRect
98+
99+
info.font = .systemFont(ofSize: 16)
100+
info.placeholder = "Enter name here!"
101+
102+
$0.addItem(info).markDirty()
103+
}
104+
105+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
106+
107+
let label = UILabel()
108+
109+
label.font = .systemFont(ofSize: 12)
110+
label.text = "Status:"
111+
label.numberOfLines = 2
112+
113+
$0.addItem(label).marginRight(5).markDirty()
114+
115+
let info = UITextField()
116+
117+
info.borderStyle = .line
118+
119+
info.font = .systemFont(ofSize: 16)
120+
info.placeholder = "Enter name here!"
121+
122+
$0.addItem(info).markDirty()
123+
}
124+
125+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
126+
127+
let label = UILabel()
128+
129+
label.font = .systemFont(ofSize: 12)
130+
label.text = "Gender:"
131+
label.numberOfLines = 2
132+
133+
$0.addItem(label).marginRight(5).markDirty()
134+
135+
let info = UITextField()
136+
137+
info.borderStyle = .bezel
138+
139+
info.font = .systemFont(ofSize: 16)
140+
info.placeholder = "Enter name here!"
141+
142+
$0.addItem(info).markDirty()
143+
}
144+
145+
$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {
146+
147+
let label = UILabel()
148+
149+
label.font = .systemFont(ofSize: 12)
150+
label.text = "About:"
151+
label.numberOfLines = 2
152+
153+
$0.addItem(label).marginRight(5).markDirty()
154+
155+
let info = UITextView()
156+
157+
info.font = .systemFont(ofSize: 16)
158+
info.text = "Place text here!"
159+
160+
$0.addItem(info).grow(1).height(200).markDirty()
161+
}
162+
}
163+
addSubview(rootFlexContainer)
164+
}
165+
166+
required init?(coder aDecoder: NSCoder) {
167+
super.init(coder: aDecoder)
168+
}
169+
170+
override func layoutSubviews() {
171+
super.layoutSubviews()
172+
173+
// Layout the flexbox container using PinLayout
174+
// NOTE: Could be also layouted by setting directly rootFlexContainer.frame
175+
rootFlexContainer.pin.top(pin.safeArea).horizontally(pin.safeArea).height(300)
176+
177+
// Then let the flexbox container layout itself
178+
rootFlexContainer.flex.layout()
179+
}
180+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4+
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
5+
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
6+
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
7+
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
9+
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10+
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
11+
// POSSIBILITY OF SUCH DAMAGE.
12+
//
13+
// Created by Michael Ong on 2020-05-27.
14+
15+
import UIKit
16+
17+
class YogaExampleFViewController: BaseViewController {
18+
fileprivate var mainView: YogaExampleFView {
19+
return self.view as! YogaExampleFView
20+
}
21+
22+
init(pageType: PageType) {
23+
super.init()
24+
title = pageType.text
25+
}
26+
27+
required init?(coder aDecoder: NSCoder) {
28+
super.init(coder: aDecoder)
29+
}
30+
31+
override func loadView() {
32+
view = YogaExampleFView()
33+
}
34+
}

Example/FlexLayoutSample/UI/Menu/MenuViewController.swift

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum PageType: Int {
2323
case yogaExampleC
2424
case yogaExampleD
2525
case yogaExampleE
26+
case yogaExampleF
2627
//case flex
2728

2829
case count
@@ -39,6 +40,7 @@ enum PageType: Int {
3940
case .yogaExampleC: return "Yoga Java Example"
4041
case .yogaExampleD: return "Yoga C# Example"
4142
case .yogaExampleE: return "Yoga Android Example"
43+
case .yogaExampleF: return "Yoga Baseline Example"
4244
//case .flex: return "Flexbox"
4345
case .count: return ""
4446
}
@@ -56,6 +58,7 @@ enum PageType: Int {
5658
case .yogaExampleC: return YogaExampleCViewController(pageType: self)
5759
case .yogaExampleD: return YogaExampleDViewController(pageType: self)
5860
case .yogaExampleE: return YogaExampleEViewController(pageType: self)
61+
case .yogaExampleF: return YogaExampleFViewController(pageType: self)
5962
//case .flex: return FlexboxViewController(pageType: self)
6063
case .count: return UIViewController()
6164
}

FlexLayout.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@
8484
24AE97351FEAF30A00995987 /* FlexLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexLayout.h; sourceTree = "<group>"; };
8585
24AE97361FEAF30A00995987 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8686
24AE97381FEAF30A00995987 /* UIView+Yoga.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Yoga.h"; sourceTree = "<group>"; };
87-
24AE97391FEAF30A00995987 /* UIView+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIView+Yoga.mm"; sourceTree = "<group>"; };
87+
24AE97391FEAF30A00995987 /* UIView+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIView+Yoga.mm"; sourceTree = "<group>"; tabWidth = 2; };
8888
24AE973A1FEAF30A00995987 /* YGLayout+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YGLayout+Private.h"; sourceTree = "<group>"; };
89-
24AE973C1FEAF30A00995987 /* YGLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = YGLayout.mm; sourceTree = "<group>"; };
89+
24AE973C1FEAF30A00995987 /* YGLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = YGLayout.mm; sourceTree = "<group>"; tabWidth = 2; };
9090
24AE973D1FEAF30A00995987 /* YGLayoutExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YGLayoutExtensions.swift; sourceTree = "<group>"; };
9191
24DA375A1EF843C500D1AB2F /* FlexLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FlexLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9292
24DA37631EF843C500D1AB2F /* FlexLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlexLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };

Sources/Swift/FlexLayout.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -1197,8 +1197,7 @@ public final class Flex {
11971197
/// Items are positioned at the end of the container
11981198
case end
11991199
/// Items are positioned at the baseline of the container
1200-
// Not currently supported by Yoga.
1201-
//case baseline
1200+
case baseline
12021201
}
12031202

12041203
/**

Sources/Swift/Impl/FlexLayout+Enum.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ extension Flex.AlignItems {
116116
case .start: return YGAlign.flexStart
117117
case .center: return YGAlign.center
118118
case .end: return YGAlign.flexEnd
119-
//case .baseline: return YGAlign.baseline
119+
case .baseline: return YGAlign.baseline
120120
}
121121
}
122122
}

0 commit comments

Comments
 (0)