Skip to content

Commit

Permalink
Merge branch 'release/2.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Ermolenko committed Feb 28, 2018
2 parents 2a2c43b + 3df85dc commit e185ae3
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Framezilla.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "Framezilla"
spec.version = "2.9.0"
spec.version = "2.9.1"
spec.summary = "Comfortable syntax for working with frames."

spec.homepage = "https://github.com/Otbivnoe/Framezilla"
Expand Down
4 changes: 4 additions & 0 deletions Framezilla.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
8442F9431EC75A8500B72551 /* MakerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8442F93B1EC75A8500B72551 /* MakerTests.swift */; };
8442F9441EC75A8500B72551 /* MakerWidthHeightTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8442F93C1EC75A8500B72551 /* MakerWidthHeightTests.swift */; };
8442F9451EC75A8500B72551 /* StateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8442F93D1EC75A8500B72551 /* StateTests.swift */; };
844BE8F320457634004C19A8 /* Maker+Unavailable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BE8F220457634004C19A8 /* Maker+Unavailable.swift */; };
845108071EE2F5BC006DC1C8 /* ScrollViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845108061EE2F5BC006DC1C8 /* ScrollViewTests.swift */; };
8497C0111E59EB7700447E2F /* Number.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8497C0101E59EB7700447E2F /* Number.swift */; };
8497C0131E59FA4B00447E2F /* Array+Stack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8497C0121E59FA4B00447E2F /* Array+Stack.swift */; };
Expand Down Expand Up @@ -63,6 +64,7 @@
8442F93B1EC75A8500B72551 /* MakerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MakerTests.swift; sourceTree = "<group>"; };
8442F93C1EC75A8500B72551 /* MakerWidthHeightTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MakerWidthHeightTests.swift; sourceTree = "<group>"; };
8442F93D1EC75A8500B72551 /* StateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateTests.swift; sourceTree = "<group>"; };
844BE8F220457634004C19A8 /* Maker+Unavailable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Maker+Unavailable.swift"; sourceTree = "<group>"; };
845108061EE2F5BC006DC1C8 /* ScrollViewTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollViewTests.swift; sourceTree = "<group>"; };
8497C0101E59EB7700447E2F /* Number.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Number.swift; sourceTree = "<group>"; };
8497C0121E59FA4B00447E2F /* Array+Stack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Stack.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -122,6 +124,7 @@
8497C0101E59EB7700447E2F /* Number.swift */,
8497C0121E59FA4B00447E2F /* Array+Stack.swift */,
842BB7FB1F0638E9000D1CFF /* Parameters.swift */,
844BE8F220457634004C19A8 /* Maker+Unavailable.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -297,6 +300,7 @@
11FB41471D844F8F00700A40 /* MakerHelper.swift in Sources */,
8497C0131E59FA4B00447E2F /* Array+Stack.swift in Sources */,
11FB41481D844F8F00700A40 /* UIView+Installer.swift in Sources */,
844BE8F320457634004C19A8 /* Maker+Unavailable.swift in Sources */,
11FB41491D844F8F00700A40 /* UIView+Relations.swift in Sources */,
842BB7FC1F0638E9000D1CFF /* Parameters.swift in Sources */,
);
Expand Down
29 changes: 29 additions & 0 deletions Sources/Maker+Unavailable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Maker+Unavailable.swift
// Framezilla iOS
//
// Created by Nikita Ermolenko on 27/02/2018.
//

import Foundation

extension Maker {

/// Calculates the width that best fits the specified size.
///
/// - returns: `Maker` instance for chaining relations.

@available(*, unavailable, renamed: "widthThatFits(maxWidth:)")
@discardableResult public func widthThatFits(width: Number) -> Maker {
return self
}

/// Calculates the height that best fits the specified size.
///
/// - returns: `Maker` instance for chaining relations.

@available(*, unavailable, renamed: "heightThatFits(maxHeight:)")
@discardableResult public func heightThatFits(height: Number) -> Maker {
return self
}
}
42 changes: 12 additions & 30 deletions Sources/Maker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,36 +382,41 @@ public final class Maker {
///
/// - returns: `Maker` instance for chaining relations.

@available(*, deprecated, message: "there is a more flexible container method - сheck the method description.")
@discardableResult public func container() -> Maker {
return _container()
}

@discardableResult func _container() -> Maker {
var frame = CGRect.zero

var minX: CGFloat = 0
var minY: CGFloat = 0

for subview in view.subviews {
if subview.frame.origin.x < 0 {
subview.frame.origin.x = 0
}

if subview.frame.origin.y < 0 {
subview.frame.origin.y = 0
}

if subview.frame.origin.x < minX {
minX = subview.frame.origin.x
}
if subview.frame.origin.y < minY {
minY = subview.frame.origin.y
}
}

for subview in view.subviews {
subview.frame.origin.x -= minX
subview.frame.origin.y -= minY

frame = frame.union(subview.frame)
}

setHighPriorityValue(frame.width, for: .width)
setHighPriorityValue(frame.height, for: .height)
return self
Expand Down Expand Up @@ -971,26 +976,3 @@ public final class Maker {
}
}
}

// MARK: - Deprecated

extension Maker {

/// Calculates the width that best fits the specified size.
///
/// - returns: `Maker` instance for chaining relations.

@available(*, unavailable, renamed: "widthThatFits(maxWidth:)")
@discardableResult public func widthThatFits(width: Number) -> Maker {
return self
}

/// Calculates the height that best fits the specified size.
///
/// - returns: `Maker` instance for chaining relations.

@available(*, unavailable, renamed: "heightThatFits(maxHeight:)")
@discardableResult public func heightThatFits(height: Number) -> Maker {
return self
}
}
31 changes: 26 additions & 5 deletions Sources/UIView+Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public enum ContainerRelation {
case vertical(top: Number, bottom: Number)
}

public extension Collection where Iterator.Element: UIView, Self.Index == Int, Self.IndexDistance == Int {
public extension Collection where Iterator.Element: UIView {

/// Configures all subview within a passed container.
///
Expand All @@ -143,35 +143,56 @@ public extension Collection where Iterator.Element: UIView, Self.Index == Int, S
public func configure(container: UIView, relation: ContainerRelation? = nil, installerBlock: () -> Void) {
container.frame = .zero

var relationWidth: CGFloat?
var relationHeight: CGFloat?

if let relation = relation {
switch relation {
case let .width(width): container.frame.size.width = width.value
case let .height(height): container.frame.size.height = height.value
case let .width(width):
container.frame.size.width = width.value
relationWidth = width.value

case let .height(height):
container.frame.size.height = height.value
relationHeight = height.value

case let .horizontal(lInset, rInset):
container.configureFrame { maker in
maker.left(inset: lInset).right(inset: rInset)
}
let width = container.frame.width
container.frame = .zero
container.frame.size.width = width
relationWidth = width

case let .vertical(tInset, bInset):
container.configureFrame { maker in
maker.top(inset: tInset).bottom(inset: bInset)
}
let height = container.frame.height
container.frame = .zero
container.frame.size.height = height
relationHeight = height
}
}

for subview in self {
for subview in self where subview.superview != container {
container.addSubview(subview)
}

installerBlock()
container.configureFrame { maker in
maker.container()
maker._container()
}

if let width = relationWidth {
container.frame.size.width = width
}

if let height = relationHeight {
container.frame.size.height = height
}

installerBlock()
}

Expand Down
56 changes: 56 additions & 0 deletions Tests/ContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,60 @@ class ContainerTests: BaseTest {
XCTAssertEqual(content3.frame, CGRect(x: 140, y: 0, width: 70, height: 200))
XCTAssertEqual(content4.frame, CGRect(x: 230, y: 85, width: 30, height: 30))
}

func testContainerHaveConstantWidthWithLeftAndRightRelations() {
let content1 = UIView()

let container = [content1].container(in: mainView, relation: .horizontal(left: 50, right: 50)) {
content1.configureFrame { maker in
maker.top()
maker.size(width: 500, height: 100)
}
}

XCTAssertEqual(container.frame, CGRect(x: 0, y: 0, width: 400, height: 100))
XCTAssertEqual(content1.frame, CGRect(x: 0, y: 0, width: 500, height: 100))
}

func testContainerHaveConstantWidthWithWidthRelation() {
let content1 = UIView()

let container = [content1].container(in: mainView, relation: .width(400)) {
content1.configureFrame { maker in
maker.top()
maker.size(width: 500, height: 100)
}
}

XCTAssertEqual(container.frame, CGRect(x: 0, y: 0, width: 400, height: 100))
XCTAssertEqual(content1.frame, CGRect(x: 0, y: 0, width: 500, height: 100))
}

func testContainerHaveConstantHeightWithTopAndBottomRelations() {
let content1 = UIView()

let container = [content1].container(in: mainView, relation: .vertical(top: 50, bottom: 50)) {
content1.configureFrame { maker in
maker.top()
maker.size(width: 100, height: 500)
}
}

XCTAssertEqual(container.frame, CGRect(x: 0, y: 0, width: 100, height: 400))
XCTAssertEqual(content1.frame, CGRect(x: 0, y: 0, width: 100, height: 500))
}

func testContainerHaveConstantHeightWithHeightRelation() {
let content1 = UIView()

let container = [content1].container(in: mainView, relation: .height(400)) {
content1.configureFrame { maker in
maker.top()
maker.size(width: 100, height: 500)
}
}

XCTAssertEqual(container.frame, CGRect(x: 0, y: 0, width: 100, height: 400))
XCTAssertEqual(content1.frame, CGRect(x: 0, y: 0, width: 100, height: 500))
}
}
2 changes: 1 addition & 1 deletion Tests/MakerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class MakerTests: BaseTest {
containet.addSubview(view2)

containet.configureFrame { maker in
maker.container()
maker._container()
}
XCTAssertEqual(containet.frame, CGRect(x: 0, y: 0, width: 120, height: 120))
}
Expand Down

0 comments on commit e185ae3

Please sign in to comment.