Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kennic committed Dec 31, 2020
1 parent 4a5d57b commit b09f0c5
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 127 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion FrameLayoutKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FrameLayoutKit'
s.version = '6.0.0'
s.version = '5.2.3'
s.summary = 'FrameLayoutKit is a super fast and easy to use layout kit'
s.description = <<-DESC
An auto layout kit helps you to layout your UI easier, faster and more effective
Expand Down
28 changes: 14 additions & 14 deletions FrameLayoutKit/Classes/DoubleFrameLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct UnitPercentage<Value: FloatingPoint> {
}
*/

open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
open class DoubleFrameLayout: FrameLayout {
public var distribution: NKLayoutDistribution = .top
public var axis: NKLayoutAxis = .vertical

Expand Down Expand Up @@ -135,7 +135,7 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {

// MARK: -

public var frameLayout1: FrameLayout = FrameLayout<T>() {
public var frameLayout1: FrameLayout = FrameLayout() {
didSet {
if frameLayout1 != oldValue {
if oldValue.superview == self {
Expand All @@ -149,7 +149,7 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
}
}

public var frameLayout2: FrameLayout = FrameLayout<T>() {
public var frameLayout2: FrameLayout = FrameLayout() {
didSet {
if frameLayout2 != oldValue {
if oldValue.superview == self {
Expand All @@ -163,22 +163,22 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
}
}

public var topFrameLayout: FrameLayout<T> {
public var topFrameLayout: FrameLayout {
get { frameLayout1 }
set { frameLayout1 = newValue }
}

public var leftFrameLayout: FrameLayout<T> {
public var leftFrameLayout: FrameLayout {
get { frameLayout1 }
set { frameLayout1 = newValue }
}

public var bottomFrameLayout: FrameLayout<T> {
public var bottomFrameLayout: FrameLayout {
get { frameLayout2 }
set { frameLayout2 = newValue }
}

public var rightFrameLayout: FrameLayout<T> {
public var rightFrameLayout: FrameLayout {
get { frameLayout2 }
set { frameLayout2 = newValue }
}
Expand All @@ -197,7 +197,7 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
try block(self)
}

convenience public init(axis: NKLayoutAxis, distribution: NKLayoutDistribution = .top, views: [T]? = nil) {
convenience public init(axis: NKLayoutAxis, distribution: NKLayoutDistribution = .top, views: [UIView]? = nil) {
self.init()

self.axis = axis
Expand Down Expand Up @@ -252,8 +252,8 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
// MARK: -

@discardableResult
open func setLeft(_ view: T?) -> FrameLayout<T> {
if let frameLayout = view as? FrameLayout<T>, frameLayout.superview == nil {
open func setLeft(_ view: UIView?) -> FrameLayout {
if let frameLayout = view as? FrameLayout, frameLayout.superview == nil {
self.frameLayout1 = frameLayout
return frameLayout
}
Expand All @@ -263,8 +263,8 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
}

@discardableResult
open func setRight(_ view: T?) -> FrameLayout<T> {
if let frameLayout = view as? FrameLayout<T>, frameLayout.superview == nil {
open func setRight(_ view: UIView?) -> FrameLayout {
if let frameLayout = view as? FrameLayout, frameLayout.superview == nil {
self.frameLayout2 = frameLayout
return frameLayout
}
Expand All @@ -274,12 +274,12 @@ open class DoubleFrameLayout<T: UIView>: FrameLayout<T> {
}

@discardableResult
open func setTop(_ view: T?) -> FrameLayout<T> {
open func setTop(_ view: UIView?) -> FrameLayout {
return setLeft(view)
}

@discardableResult
open func setBottom(_ view: T?) -> FrameLayout<T> {
open func setBottom(_ view: UIView?) -> FrameLayout {
return setRight(view)
}

Expand Down
30 changes: 15 additions & 15 deletions FrameLayoutKit/Classes/FlowFrameLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

open class FlowFrameLayout<T: UIView>: FrameLayout<T> {
open class FlowFrameLayout: FrameLayout {
public var axis: NKLayoutAxis = .horizontal {
didSet {
stackLayout.axis = axis == .horizontal ? .vertical : .horizontal
Expand Down Expand Up @@ -98,15 +98,15 @@ open class FlowFrameLayout<T: UIView>: FrameLayout<T> {
return stackLayout.frameLayouts.count
}

public var stacks: [StackFrameLayout<UIView>] {
return stackLayout.frameLayouts as? [StackFrameLayout<UIView>] ?? []
public var stacks: [StackFrameLayout] {
return stackLayout.frameLayouts as? [StackFrameLayout] ?? []
}

public var firstStack: StackFrameLayout<UIView>? {
public var firstStack: StackFrameLayout? {
return stackLayout.firstFrameLayout as? StackFrameLayout
}

public var lastStack: StackFrameLayout<UIView>? {
public var lastStack: StackFrameLayout? {
return stackLayout.lastFrameLayout as? StackFrameLayout
}

Expand All @@ -116,7 +116,7 @@ open class FlowFrameLayout<T: UIView>: FrameLayout<T> {
public fileprivate(set) var viewCount: Int = 0

/// Array of views that needs to be filled in this flow layout
public var views: [T] = [] {
public var views: [UIView] = [] {
didSet {
lastSize = .zero
viewCount = views.count
Expand Down Expand Up @@ -149,30 +149,30 @@ open class FlowFrameLayout<T: UIView>: FrameLayout<T> {

// MARK: -

public func viewAt(row: Int, column: Int) -> T? {
return frameLayout(row: row, column: column)?.targetView as? T
public func viewAt(row: Int, column: Int) -> UIView? {
return frameLayout(row: row, column: column)?.targetView
}

public func viewsAt(stack: Int) -> [T]? {
return stacks(at: stack)?.frameLayouts.compactMap( { return $0.targetView as? T } )
public func viewsAt(stack: Int) -> [UIView]? {
return stacks(at: stack)?.frameLayouts.compactMap( { return $0 } )
}

public func stacks(at index: Int) -> StackFrameLayout<UIView>? {
public func stacks(at index: Int) -> StackFrameLayout? {
guard index > -1, index < stackLayout.frameLayouts.count, let frameLayout = stackLayout.frameLayouts[index] as? StackFrameLayout else { return nil }
return frameLayout
}

public func frameLayout(row: Int, column: Int) -> FrameLayout<UIView>? {
public func frameLayout(row: Int, column: Int) -> FrameLayout? {
guard row > -1, row < stackLayout.frameLayouts.count else { return nil }
guard let rowLayout = stackLayout.frameLayouts[row] as? StackFrameLayout else { return nil }
return rowLayout.frameLayout(at: column)
}

public func allFrameLayouts() -> [FrameLayout<UIView>] {
public func allFrameLayouts() -> [FrameLayout] {
return stackLayout.frameLayouts.compactMap { $0 as? StackFrameLayout }.flatMap { $0.frameLayouts }
}

public func lastFrameLayout(containsView: Bool = false) -> FrameLayout<UIView>? {
public func lastFrameLayout(containsView: Bool = false) -> FrameLayout? {
guard let lastStack = lastStack else { return nil }

if containsView {
Expand All @@ -185,7 +185,7 @@ open class FlowFrameLayout<T: UIView>: FrameLayout<T> {

// MARK: -

fileprivate func newStack() -> StackFrameLayout<UIView> {
fileprivate func newStack() -> StackFrameLayout {
let layout = StackFrameLayout(axis: axis, distribution: distribution)
layout.spacing = axis == .horizontal ? interItemSpacing : lineSpacing
layout.isJustified = isJustified
Expand Down
61 changes: 29 additions & 32 deletions FrameLayoutKit/Classes/FrameLayout+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit
public extension FrameLayout {

@discardableResult
static func +(lhs: FrameLayout<T>, rhs: T? = nil) -> FrameLayout<T> {
static func +(lhs: FrameLayout, rhs: UIView? = nil) -> FrameLayout {
lhs.targetView = rhs
return lhs
}
Expand All @@ -23,34 +23,34 @@ infix operator ---
public extension StackFrameLayout {

@discardableResult
static func ---(lhs: StackFrameLayout<T>, _ size: CGFloat = 0) -> FrameLayout<T> {
static func ---(lhs: StackFrameLayout, _ size: CGFloat = 0) -> FrameLayout {
return lhs.addSpace(size)
}

@discardableResult
static func +(lhs: StackFrameLayout<T>, rhs: T? = nil) -> FrameLayout<T> {
static func +(lhs: StackFrameLayout, rhs: UIView? = nil) -> FrameLayout {
return lhs.add(rhs)
}

@discardableResult
static func +(lhs: StackFrameLayout<T>, rhs: [T]? = nil) -> [FrameLayout<T>] {
var results = [FrameLayout<T>]()
static func +(lhs: StackFrameLayout, rhs: [UIView]? = nil) -> [FrameLayout] {
var results = [FrameLayout]()
rhs?.forEach { results.append(lhs.add($0)) }
return results
}

@discardableResult
static func +(lhs: StackFrameLayout<T>, rhs: CGFloat = 0) -> FrameLayout<T> {
static func +(lhs: StackFrameLayout, rhs: CGFloat = 0) -> FrameLayout {
return lhs.addSpace(rhs)
}

@discardableResult
static func +(lhs: StackFrameLayout<T>, rhs: Double = 0) -> FrameLayout<T> {
static func +(lhs: StackFrameLayout, rhs: Double = 0) -> FrameLayout {
return lhs.addSpace(CGFloat(rhs))
}

@discardableResult
static func +(lhs: StackFrameLayout<T>, rhs: Int = 0) -> FrameLayout<T> {
static func +(lhs: StackFrameLayout, rhs: Int = 0) -> FrameLayout {
return lhs.addSpace(CGFloat(rhs))
}

Expand All @@ -59,34 +59,34 @@ public extension StackFrameLayout {
public extension ScrollStackView {

@discardableResult
static func ---(lhs: ScrollStackView, _ size: CGFloat = 0) -> FrameLayout<UIView> {
static func ---(lhs: ScrollStackView, _ size: CGFloat = 0) -> FrameLayout {
return lhs.addSpace(size)
}

@discardableResult
static func +(lhs: ScrollStackView, rhs: UIView? = nil) -> FrameLayout<UIView> {
static func +(lhs: ScrollStackView, rhs: UIView? = nil) -> FrameLayout {
return lhs.add(rhs)
}

@discardableResult
static func +(lhs: ScrollStackView, rhs: [UIView]? = nil) -> [FrameLayout<UIView>] {
var results = [FrameLayout<UIView>]()
static func +(lhs: ScrollStackView, rhs: [UIView]? = nil) -> [FrameLayout] {
var results = [FrameLayout]()
rhs?.forEach { results.append(lhs.add($0)) }
return results
}

@discardableResult
static func +(lhs: ScrollStackView, rhs: CGFloat = 0) -> FrameLayout <UIView>{
static func +(lhs: ScrollStackView, rhs: CGFloat = 0) -> FrameLayout {
return lhs.addSpace(rhs)
}

@discardableResult
static func +(lhs: ScrollStackView, rhs: Double = 0) -> FrameLayout<UIView> {
static func +(lhs: ScrollStackView, rhs: Double = 0) -> FrameLayout {
return lhs.addSpace(CGFloat(rhs))
}

@discardableResult
static func +(lhs: ScrollStackView, rhs: Int = 0) -> FrameLayout<UIView> {
static func +(lhs: ScrollStackView, rhs: Int = 0) -> FrameLayout {
return lhs.addSpace(CGFloat(rhs))
}

Expand All @@ -98,8 +98,8 @@ infix operator +>
public extension DoubleFrameLayout {

@discardableResult
static func <+(lhs: DoubleFrameLayout<T>, rhs: T? = nil) -> FrameLayout<T> {
if let frameLayout = rhs as? FrameLayout<T>, frameLayout.superview == nil {
static func <+(lhs: DoubleFrameLayout, rhs: UIView? = nil) -> FrameLayout {
if let frameLayout = rhs as? FrameLayout, frameLayout.superview == nil {
lhs.leftFrameLayout = frameLayout
}
else {
Expand All @@ -110,8 +110,8 @@ public extension DoubleFrameLayout {
}

@discardableResult
static func +>(lhs: DoubleFrameLayout<T>, rhs: T? = nil) -> FrameLayout<T> {
if let frameLayout = rhs as? FrameLayout<T>, frameLayout.superview == nil {
static func +>(lhs: DoubleFrameLayout, rhs: UIView? = nil) -> FrameLayout {
if let frameLayout = rhs as? FrameLayout, frameLayout.superview == nil {
lhs.rightFrameLayout = frameLayout
}
else {
Expand All @@ -125,7 +125,7 @@ public extension DoubleFrameLayout {

// MARK: -

open class StackLayout<T: UIView>: StackFrameLayout<T> {
open class StackLayout: StackFrameLayout {

@discardableResult
public init(_ block: (StackLayout) throws -> Void) rethrows {
Expand All @@ -139,7 +139,7 @@ open class StackLayout<T: UIView>: StackFrameLayout<T> {

}

open class HStackLayout<T: UIView>: StackFrameLayout<T> {
open class HStackLayout: StackFrameLayout {

@discardableResult
public init(_ block: (HStackLayout) throws -> Void) rethrows {
Expand All @@ -159,7 +159,7 @@ open class HStackLayout<T: UIView>: StackFrameLayout<T> {

}

open class VStackLayout<T: UIView>: StackFrameLayout<T> {
open class VStackLayout: StackFrameLayout {

@discardableResult
public init(_ block: (VStackLayout) throws -> Void) rethrows {
Expand All @@ -179,38 +179,35 @@ open class VStackLayout<T: UIView>: StackFrameLayout<T> {

}

public protocol Then {}
extension Then { // where Self: AnyObject {
public protocol With {}
extension With where Self: FrameLayout {

/// Add ability to set properties with closures just after initializing.
///
/// let frameLayout = FrameLayout().then {
/// let frameLayout = FrameLayout().with {
/// $0.alignment = (.top, .center)
/// $0.padding(top: 5, left: 5, bottom: 5, right: 5)
/// }
///
/// So you can also nest a block of FrameLayout into another by:
///
/// let stack = StackFrameLayout(axis: .vertical)
/// stack + HStackLayout {
/// ($0 + imageView).then {
/// $0.flexible()
/// $0.fixHeight = 50
/// }
/// stack + HStackLayout().with {
/// $0 + imageView
/// $0 + label
/// }
/// stack + textField
///
///
@discardableResult
public func then(_ block: (Self) throws -> Void) rethrows -> Self {
public func with(_ block: (Self) throws -> Void) rethrows -> Self {
try block(self)
return self
}

}

extension FrameLayout: Then {}
extension FrameLayout: With {}

extension CGSize {

Expand Down
Loading

0 comments on commit b09f0c5

Please sign in to comment.