Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add baseline item support! #159

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions Example/FlexLayoutSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
24FB883E1F59CA8B00615D33 /* TableViewExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */; };
24FB88411F59CA9A00615D33 /* MethodCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB883F1F59CA9A00615D33 /* MethodCell.swift */; };
24FB88421F59CA9A00615D33 /* MethodGroupHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */; };
60BAE156247DF4120020119C /* YogaExampleFView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE155247DF4120020119C /* YogaExampleFView.swift */; };
60BAE158247DF4CE0020119C /* YogaExampleFViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */; };
B9BDD93E240A70C3005298B3 /* FlexLayout in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD93D240A70C3005298B3 /* FlexLayout */; };
B9BDD940240A70C3005298B3 /* FlexLayoutYoga in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD93F240A70C3005298B3 /* FlexLayoutYoga */; };
B9BDD942240A70C3005298B3 /* FlexLayoutYogaKit in Frameworks */ = {isa = PBXBuildFile; productRef = B9BDD941240A70C3005298B3 /* FlexLayoutYogaKit */; };
Expand Down Expand Up @@ -134,6 +136,8 @@
24FB883C1F59CA8B00615D33 /* TableViewExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewExampleViewController.swift; sourceTree = "<group>"; };
24FB883F1F59CA9A00615D33 /* MethodCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MethodCell.swift; sourceTree = "<group>"; };
24FB88401F59CA9A00615D33 /* MethodGroupHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MethodGroupHeader.swift; sourceTree = "<group>"; };
60BAE155247DF4120020119C /* YogaExampleFView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFView.swift; sourceTree = "<group>"; };
60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YogaExampleFViewController.swift; sourceTree = "<group>"; };
82FCE524E22C2FF5BC4DFBAB /* Pods_FlexLayoutSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_FlexLayoutSample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
B9EA7C522409B79B000D8E35 /* FlexLayoutSampleSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlexLayoutSampleSPM.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -192,16 +196,17 @@
2439CC371E665C5E003326FB /* Examples */ = {
isa = PBXGroup;
children = (
24901F071F93D40F0025D11B /* CollectionViewExample */,
247D73421F6757A00001AE2C /* Example1 */,
24B14C581F278CB400C90490 /* Intro */,
24E835131F4CC323009F95CC /* RaywenderlichTutorial */,
24901F071F93D40F0025D11B /* CollectionViewExample */,
24FB883A1F59CA7800615D33 /* TableViewExample */,
247D73421F6757A00001AE2C /* Example1 */,
DF91747C1F1F6F8B0034632D /* YogaExampleA */,
DF0E85281F1F742C00AB1956 /* YogaExampleB */,
24CD0D121F1F8D1100D56FC3 /* YogaExampleC */,
24CD0D171F1F8E3D00D56FC3 /* YogaExampleD */,
24CD0D1C1F1F90AF00D56FC3 /* YogaExampleE */,
60BAE154247DF3F40020119C /* YogaExampleF */,
);
path = Examples;
sourceTree = "<group>";
Expand Down Expand Up @@ -366,6 +371,15 @@
name = Frameworks;
sourceTree = "<group>";
};
60BAE154247DF3F40020119C /* YogaExampleF */ = {
isa = PBXGroup;
children = (
60BAE155247DF4120020119C /* YogaExampleFView.swift */,
60BAE157247DF4CE0020119C /* YogaExampleFViewController.swift */,
);
path = YogaExampleF;
sourceTree = "<group>";
};
85CAAE97812075333AF3E88F /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -529,15 +543,12 @@
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/FlexLayout/FlexLayout.framework",
"${BUILT_PRODUCTS_DIR}/PinLayout/PinLayout.framework",
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FlexLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PinLayout.framework",
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FlexLayoutSample/Pods-FlexLayoutSample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -610,10 +621,12 @@
24FB883D1F59CA8B00615D33 /* TableViewExampleView.swift in Sources */,
242AECE41FA011630024E7C2 /* BasicView.swift in Sources */,
24AADD4B1F4E177700CB77E6 /* ShowTableViewCell.swift in Sources */,
60BAE158247DF4CE0020119C /* YogaExampleFViewController.swift in Sources */,
242AECE31FA011630024E7C2 /* BaseViewController.swift in Sources */,
24901F0C1F93D40F0025D11B /* CollectionViewExampleView.swift in Sources */,
DF0E852C1F1F749C00AB1956 /* YogaExampleBViewController.swift in Sources */,
DF1F2A091F17D11700BA1B97 /* MenuView.swift in Sources */,
60BAE156247DF4120020119C /* YogaExampleFView.swift in Sources */,
24AADD4C1F4E177700CB77E6 /* ExpandedTableView.swift in Sources */,
DF91747F1F1F6F9A0034632D /* YogaExampleAView.swift in Sources */,
24FB88421F59CA9A00615D33 /* MethodGroupHeader.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Created by Michael Ong on 2020-05-27.

import UIKit
import FlexLayout
import PinLayout

class YogaExampleFView: UIView {
fileprivate let rootFlexContainer = UIView()

init() {
super.init(frame: .zero)
backgroundColor = .white

let imageView = UIView()
imageView.backgroundColor = .flexLayoutColor

// Yoga's Android example
rootFlexContainer.flex.padding(20).direction(.column).define {

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 20)
label.text = "Leading Font"

$0.addItem(label).marginRight(5).markDirty()

let info = UILabel()

info.font = .systemFont(ofSize: 10)
info.text = "Trailing Font"

$0.addItem(info).markDirty()
}

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 20)
label.text = "Leading Multiline\nText Oh yeah!"
label.numberOfLines = 2

$0.addItem(label).marginRight(5).markDirty()

let info = UILabel()

info.font = .systemFont(ofSize: 10)
info.text = "Trailing Font"

$0.addItem(info).markDirty()
}

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 12)
label.text = "Name:"
label.numberOfLines = 2

$0.addItem(label).marginRight(5).markDirty()

let info = UITextField()

info.font = .systemFont(ofSize: 16)
info.placeholder = "Enter name here!"

$0.addItem(info).markDirty()
}

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 12)
label.text = "Age:"
label.numberOfLines = 2

$0.addItem(label).marginRight(5).markDirty()

let info = UITextField()

info.borderStyle = .roundedRect

info.font = .systemFont(ofSize: 16)
info.placeholder = "Enter name here!"

$0.addItem(info).markDirty()
}

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 12)
label.text = "Status:"
label.numberOfLines = 2

$0.addItem(label).marginRight(5).markDirty()

let info = UITextField()

info.borderStyle = .line

info.font = .systemFont(ofSize: 16)
info.placeholder = "Enter name here!"

$0.addItem(info).markDirty()
}

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 12)
label.text = "Gender:"
label.numberOfLines = 2

$0.addItem(label).marginRight(5).markDirty()

let info = UITextField()

info.borderStyle = .bezel

info.font = .systemFont(ofSize: 16)
info.placeholder = "Enter name here!"

$0.addItem(info).markDirty()
}

$0.addItem().direction(.row).alignItems(.baseline).marginBottom(20).define {

let label = UILabel()

label.font = .systemFont(ofSize: 12)
label.text = "About:"
label.numberOfLines = 2

$0.addItem(label).marginRight(5).markDirty()

let info = UITextView()

info.font = .systemFont(ofSize: 16)
info.text = "Place text here!"

$0.addItem(info).grow(1).height(200).markDirty()
}
}
addSubview(rootFlexContainer)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func layoutSubviews() {
super.layoutSubviews()

// Layout the flexbox container using PinLayout
// NOTE: Could be also layouted by setting directly rootFlexContainer.frame
rootFlexContainer.pin.top(pin.safeArea).horizontally(pin.safeArea).height(300)

// Then let the flexbox container layout itself
rootFlexContainer.flex.layout()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Created by Michael Ong on 2020-05-27.

import UIKit

class YogaExampleFViewController: BaseViewController {
fileprivate var mainView: YogaExampleFView {
return self.view as! YogaExampleFView
}

init(pageType: PageType) {
super.init()
title = pageType.text
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

override func loadView() {
view = YogaExampleFView()
}
}
3 changes: 3 additions & 0 deletions Example/FlexLayoutSample/UI/Menu/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum PageType: Int {
case yogaExampleC
case yogaExampleD
case yogaExampleE
case yogaExampleF
//case flex

case count
Expand All @@ -39,6 +40,7 @@ enum PageType: Int {
case .yogaExampleC: return "Yoga Java Example"
case .yogaExampleD: return "Yoga C# Example"
case .yogaExampleE: return "Yoga Android Example"
case .yogaExampleF: return "Yoga Baseline Example"
//case .flex: return "Flexbox"
case .count: return ""
}
Expand All @@ -56,6 +58,7 @@ enum PageType: Int {
case .yogaExampleC: return YogaExampleCViewController(pageType: self)
case .yogaExampleD: return YogaExampleDViewController(pageType: self)
case .yogaExampleE: return YogaExampleEViewController(pageType: self)
case .yogaExampleF: return YogaExampleFViewController(pageType: self)
//case .flex: return FlexboxViewController(pageType: self)
case .count: return UIViewController()
}
Expand Down
4 changes: 2 additions & 2 deletions FlexLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
24AE97351FEAF30A00995987 /* FlexLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FlexLayout.h; sourceTree = "<group>"; };
24AE97361FEAF30A00995987 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
24AE97381FEAF30A00995987 /* UIView+Yoga.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Yoga.h"; sourceTree = "<group>"; };
24AE97391FEAF30A00995987 /* UIView+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIView+Yoga.mm"; sourceTree = "<group>"; };
24AE97391FEAF30A00995987 /* UIView+Yoga.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = "UIView+Yoga.mm"; sourceTree = "<group>"; tabWidth = 2; };
24AE973A1FEAF30A00995987 /* YGLayout+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "YGLayout+Private.h"; sourceTree = "<group>"; };
24AE973C1FEAF30A00995987 /* YGLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = YGLayout.mm; sourceTree = "<group>"; };
24AE973C1FEAF30A00995987 /* YGLayout.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.objcpp; path = YGLayout.mm; sourceTree = "<group>"; tabWidth = 2; };
24AE973D1FEAF30A00995987 /* YGLayoutExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YGLayoutExtensions.swift; sourceTree = "<group>"; };
24DA375A1EF843C500D1AB2F /* FlexLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FlexLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; };
24DA37631EF843C500D1AB2F /* FlexLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FlexLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down
3 changes: 1 addition & 2 deletions Sources/Swift/FlexLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,7 @@ public final class Flex {
/// Items are positioned at the end of the container
case end
/// Items are positioned at the baseline of the container
// Not currently supported by Yoga.
//case baseline
case baseline
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swift/Impl/FlexLayout+Enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ extension Flex.AlignItems {
case .start: return YGAlign.flexStart
case .center: return YGAlign.center
case .end: return YGAlign.flexEnd
//case .baseline: return YGAlign.baseline
case .baseline: return YGAlign.baseline
}
}
}
Expand Down
Loading