From c0152fe9c991894733bdc5a87d4545e68cdaf31d Mon Sep 17 00:00:00 2001 From: Remmington Damper Date: Fri, 17 Dec 2021 18:49:06 -0500 Subject: [PATCH 01/10] finished Lux --- .../Contents.swift | 2 +- Example/Podfile.lock | 8 +- .../LUXPinterestStyleLayout.swift | 101 ++++++++++++++++++ 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift diff --git a/Example/LUX/MultiSizeCollectionVIewLayout.playground/Contents.swift b/Example/LUX/MultiSizeCollectionVIewLayout.playground/Contents.swift index e1fd3c0..79a3662 100644 --- a/Example/LUX/MultiSizeCollectionVIewLayout.playground/Contents.swift +++ b/Example/LUX/MultiSizeCollectionVIewLayout.playground/Contents.swift @@ -20,7 +20,7 @@ enum House: String, Codable, CaseIterable { } struct Emperor: Codable { var name: String? - var imageUrlString: String? = "https://preview.redd.it/e6c2zqbu9gf51.jpg?width=500&format=pjpg&auto=webp&s=9c1e6dcf6d163ae036d534fc315a190223e77ed8" + var imageUrlString: String? = "https://picsum.photos/200/200" } struct Reign: Codable { var id: Int diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 3a415b5..cdf7d6a 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -93,9 +93,9 @@ PODS: - Prelude (~> 3.0) - PlaygroundVCHelpers (0.0.2) - Prelude (3.0.0) - - SDWebImage (5.12.1): - - SDWebImage/Core (= 5.12.1) - - SDWebImage/Core (5.12.1) + - SDWebImage (5.12.2): + - SDWebImage/Core (= 5.12.2) + - SDWebImage/Core (5.12.2) - Slippers/Core (0.1.1) DEPENDENCIES: @@ -164,7 +164,7 @@ SPEC CHECKSUMS: LUX: a0a8013d109a4d4887f75fcc91637221e6749abb PlaygroundVCHelpers: c7cc8994d2851ebd1590217101b4c6888d1c9cc8 Prelude: fe4cc0fd961d34edf48fe6b04d05c863449efb0a - SDWebImage: 4dc3e42d9ec0c1028b960a33ac6b637bb432207b + SDWebImage: 240e5c12b592fb1268c1d03b8c90d90e8c2ffe82 Slippers: 5a3c6f24a556a59a091e2cb60e588472827be87c PODFILE CHECKSUM: 940b727264080c97240a108fc65ed553ccdfa5dc diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift new file mode 100644 index 0000000..d6f167b --- /dev/null +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -0,0 +1,101 @@ +// +// LUXPinterestStyleLayout.swift +// LUX +// +// Created by Remmington Damper on 12/12/21. +// + +import UIKit + + +public class LUXPinterestStyleLayout: UICollectionViewLayout { + + private var numberOfColumns = 2 + private let cellPadding: CGFloat = 6 + private var cache: [UICollectionViewLayoutAttributes] = [] + private var contentHeight: CGFloat = 0 + + private var _contentSize: CGSize? { didSet { invalidateLayout() }} + public func setContentSize(_ contentSize: CGSize) { _contentSize = contentSize } + + open var heightForCellAtIndexPath: ((UICollectionView, IndexPath) -> CGFloat)? + + private var contentWidth: CGFloat { + guard let collectionView = collectionView else { + return 0 + } + let insets = collectionView.contentInset + return collectionView.bounds.width - (insets.left + insets.right) + } + + open func setContentSizeFromCache() { + if let last = cache.last { + _contentSize = CGSize(width: contentWidth, height: last.frame.minY + last.frame.height) + } + } + + public override var collectionViewContentSize: CGSize { + return CGSize(width: contentWidth, height: contentHeight) + } + + public override func prepare() { + super.prepare() + + guard let collectionView = collectionView else { return } + cacheFramesAndCalculate(collectionView.numberOfSections, collectionView.numberOfItems(inSection:)) + + setContentSizeFromCache() + + } + + open func cacheFramesAndCalculate(_ numberOfSections: Int, _ numberOfItemsInSection: (Int) -> Int) { + cache.removeAll() + guard cache.isEmpty, let collectionView = collectionView else { return } + + let columnWidth = contentWidth / CGFloat(numberOfColumns) + var xOffset: [CGFloat] = [] + + for column in 0.. [UICollectionViewLayoutAttributes]? { + var attributes: [UICollectionViewLayoutAttributes] = [] + for attribute in cache { + if attribute.frame.intersects(rect) { + attributes.append(attribute) + } + } + return attributes + } + + public override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + return cache[indexPath.item] + } + +} From 8b2f9dd5f952940b3437818fce5120b4605aec7e Mon Sep 17 00:00:00 2001 From: Remmington Damper Date: Tue, 21 Dec 2021 12:25:29 -0500 Subject: [PATCH 02/10] finished making the layout more robust --- .../LUXPinterestStyleLayout.swift | 69 +++++++++++-------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift index d6f167b..01c16fe 100644 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -13,42 +13,57 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { private var numberOfColumns = 2 private let cellPadding: CGFloat = 6 private var cache: [UICollectionViewLayoutAttributes] = [] - private var contentHeight: CGFloat = 0 - - private var _contentSize: CGSize? { didSet { invalidateLayout() }} - public func setContentSize(_ contentSize: CGSize) { _contentSize = contentSize } - - open var heightForCellAtIndexPath: ((UICollectionView, IndexPath) -> CGFloat)? - - private var contentWidth: CGFloat { + private var contentHeight: CGFloat = 0.0 { didSet { invalidateLayout() }} + private var contentHeightSetter: CGFloat { + get { return contentHeight } + set { contentHeight = newValue} + } + private var contentWidth: CGFloat = 0.0 { didSet { invalidateLayout() }} + private var contentWidthSetter: CGFloat { guard let collectionView = collectionView else { return 0 } let insets = collectionView.contentInset - return collectionView.bounds.width - (insets.left + insets.right) + contentWidth = collectionView.bounds.width - (insets.left + insets.right) + return contentWidth + } + private var contentSize: CGSize? { didSet { invalidateLayout() }} + private var contentSizeSetter: CGSize { + get { return contentSize ?? CGSize(width: 0, height: 0) } + set { contentSize = newValue} } + private var itemCount: Int { calculateItemCount() } + + open var heightForCellAtIndexPath: ((UICollectionView, IndexPath) -> CGFloat)? + open func setContentSizeFromCache() { if let last = cache.last { - _contentSize = CGSize(width: contentWidth, height: last.frame.minY + last.frame.height) + contentSizeSetter = CGSize(width: contentWidth, height: last.frame.minY + last.frame.height) } } public override var collectionViewContentSize: CGSize { - return CGSize(width: contentWidth, height: contentHeight) + return contentSize ?? CGSize(width: contentWidth, height: contentHeight) + } + + open func calculateItemCount() -> Int { + var count = 0 + if let cv = collectionView { + for i in 0.. Int) { + open func cacheFramesAndCalculate() { cache.removeAll() guard cache.isEmpty, let collectionView = collectionView else { return } @@ -62,25 +77,25 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { var column = 0 var yOffset: [CGFloat] = .init(repeating: 0, count: numberOfColumns) - for item in 0.. Date: Sun, 26 Dec 2021 14:24:33 -0500 Subject: [PATCH 03/10] Added a test --- Example/Tests/LoginViewModelTests.swift | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Example/Tests/LoginViewModelTests.swift b/Example/Tests/LoginViewModelTests.swift index d968646..0791892 100644 --- a/Example/Tests/LoginViewModelTests.swift +++ b/Example/Tests/LoginViewModelTests.swift @@ -248,5 +248,37 @@ class LoginViewModelTests: XCTestCase { viewModel.rightViewPressed() XCTAssertTrue(wasCalled) } + + func testUsernameAndPasswordChangedAndSaved() { + var wasCalled = false + var calledSaveToken = false + var shouldAdvance = false + + let call = CombineNetCall(configuration: ServerConfiguration(host: "lithobyte.co", apiRoute: "api/v1"), Endpoint()) + call.firingFunc = { + _ in wasCalled = true + call.responder?.data = "Hi".data(using: .utf8) + } + let viewModel = LUXLoginViewModel(credsCall: call, loginModelToJson: { _, _ in Human() }) { + _ in calledSaveToken = true + return true + } + let cancel = viewModel.outputs.advanceAuthedPublisher.sink { _ in + shouldAdvance = true + } + + viewModel.inputs.usernameChanged(username: "Jacob") + viewModel.inputs.passwordChanged(password: "Password") + viewModel.inputs.submitButtonPressed() + + XCTAssertEqual(viewModel.username, "Jacob") + XCTAssertEqual(viewModel.password, "Password") + XCTAssert(wasCalled) + XCTAssert(calledSaveToken) + XCTAssert(shouldAdvance) + cancel.cancel() + } + + } From 25f4a0a7fed174f9e1773d3a686eee400c3d6794 Mon Sep 17 00:00:00 2001 From: Remmington Damper Date: Tue, 4 Jan 2022 18:54:40 -0500 Subject: [PATCH 04/10] finished pinterest --- Example/Tests/ListViewModelTests.swift | 1 + .../Base/CollectionViews/LUXPinterestStyleLayout.swift | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Example/Tests/ListViewModelTests.swift b/Example/Tests/ListViewModelTests.swift index 2be4f16..2dc4ae5 100644 --- a/Example/Tests/ListViewModelTests.swift +++ b/Example/Tests/ListViewModelTests.swift @@ -60,4 +60,5 @@ class ListViewModelTests: XCTestCase { XCTAssert(wasFiltered) cancel.cancel() } + } diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift index 01c16fe..ef971cf 100644 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -13,20 +13,19 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { private var numberOfColumns = 2 private let cellPadding: CGFloat = 6 private var cache: [UICollectionViewLayoutAttributes] = [] - private var contentHeight: CGFloat = 0.0 { didSet { invalidateLayout() }} + private var contentHeight: CGFloat = 0.0 private var contentHeightSetter: CGFloat { get { return contentHeight } set { contentHeight = newValue} } - private var contentWidth: CGFloat = 0.0 { didSet { invalidateLayout() }} - private var contentWidthSetter: CGFloat { + private var contentWidth: CGFloat { guard let collectionView = collectionView else { return 0 } let insets = collectionView.contentInset - contentWidth = collectionView.bounds.width - (insets.left + insets.right) - return contentWidth + return collectionView.bounds.width - (insets.left + insets.right) } + private var contentSize: CGSize? { didSet { invalidateLayout() }} private var contentSizeSetter: CGSize { get { return contentSize ?? CGSize(width: 0, height: 0) } From ba1bd5e0ca645da731c1bc2b3e66f618feda8468 Mon Sep 17 00:00:00 2001 From: Remmington Damper Date: Wed, 5 Jan 2022 18:12:38 -0500 Subject: [PATCH 05/10] fixed issues --- .../LUXPinterestStyleLayout.swift | 115 ------------------ 1 file changed, 115 deletions(-) delete mode 100644 LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift deleted file mode 100644 index ef971cf..0000000 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ /dev/null @@ -1,115 +0,0 @@ -// -// LUXPinterestStyleLayout.swift -// LUX -// -// Created by Remmington Damper on 12/12/21. -// - -import UIKit - - -public class LUXPinterestStyleLayout: UICollectionViewLayout { - - private var numberOfColumns = 2 - private let cellPadding: CGFloat = 6 - private var cache: [UICollectionViewLayoutAttributes] = [] - private var contentHeight: CGFloat = 0.0 - private var contentHeightSetter: CGFloat { - get { return contentHeight } - set { contentHeight = newValue} - } - private var contentWidth: CGFloat { - guard let collectionView = collectionView else { - return 0 - } - let insets = collectionView.contentInset - return collectionView.bounds.width - (insets.left + insets.right) - } - - private var contentSize: CGSize? { didSet { invalidateLayout() }} - private var contentSizeSetter: CGSize { - get { return contentSize ?? CGSize(width: 0, height: 0) } - set { contentSize = newValue} - } - private var itemCount: Int { calculateItemCount() } - - open var heightForCellAtIndexPath: ((UICollectionView, IndexPath) -> CGFloat)? - - - open func setContentSizeFromCache() { - if let last = cache.last { - contentSizeSetter = CGSize(width: contentWidth, height: last.frame.minY + last.frame.height) - } - } - - public override var collectionViewContentSize: CGSize { - return contentSize ?? CGSize(width: contentWidth, height: contentHeight) - } - - open func calculateItemCount() -> Int { - var count = 0 - if let cv = collectionView { - for i in 0.. [UICollectionViewLayoutAttributes]? { - var attributes: [UICollectionViewLayoutAttributes] = [] - for attribute in cache { - if attribute.frame.intersects(rect) { - attributes.append(attribute) - } - } - return attributes - } - - public override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { - return cache[indexPath.item] - } - -} From a6a1318d90b3a6badf126687728ddd40e883161f Mon Sep 17 00:00:00 2001 From: Remmington Damper Date: Wed, 5 Jan 2022 18:15:00 -0500 Subject: [PATCH 06/10] fixed issues --- .../LUXPinterestStyleLayout.swift | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift new file mode 100644 index 0000000..04a7711 --- /dev/null +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -0,0 +1,128 @@ +// +// LUXPinterestStyleLayout.swift +// LUX +// +// Created by Remmington Damper on 12/12/21. +// + +import UIKit + + +public class LUXPinterestStyleLayout: UICollectionViewLayout { + + private var _columnCount = 2 { didSet {invalidateLayout() }} + public func setColumnCount(_ count: Int) { _columnCount = count } + + private var _cellPadding: CGFloat = 0 { didSet { invalidateLayout() }} + public func setCellPadding(_ padding: CGFloat = 0) { _cellPadding = padding } + + private var cache: [UICollectionViewLayoutAttributes] = [] + + private var _baseItemWidth: CGFloat = 0 { didSet {invalidateLayout() }} + public func setBaseItemWidth(_ width: CGFloat) { _baseItemWidth = width } + + public var widthForColumn: ((Int) -> CGFloat?)? = { _ in return nil } + + private var contentHeight: CGFloat = 0.0 + private var contentWidth: CGFloat { + guard let collectionView = collectionView else { + return 0 + } + let insets = collectionView.contentInset + return collectionView.bounds.width - (insets.left + insets.right) + } + + private var _contentSize: CGSize? { didSet { invalidateLayout() }} + public func setContentSize(_ size: CGSize) { _contentSize = size } + + private var itemCount: Int { calculateItemCount() } + + open var heightForCellAtIndexPath: ((UICollectionView, IndexPath) -> CGFloat)? + + + open func setContentSizeFromCache() { + if let last = cache.last { + _contentSize = CGSize(width: contentWidth, height: last.frame.minY + last.frame.height) + } + } + + public override var collectionViewContentSize: CGSize { + return _contentSize ?? CGSize(width: contentWidth, height: contentHeight) + } + + open func calculateItemCount() -> Int { + var count = 0 + if let cv = collectionView { + for i in 0.. [CGFloat]? { + guard _columnCount > 0 else { return nil } + guard _baseItemWidth > 0 else { return nil } + + let columnWidth = contentWidth / CGFloat(_columnCount) + + var xOffSet: [CGFloat] = [] + for column in 0..<_columnCount { + xOffSet.append(CGFloat(column) * columnWidth) + } + return xOffSet + } + + open func cacheFramesAndCalculate() { + cache.removeAll() + guard cache.isEmpty, let collectionView = collectionView else { return } + + let columnWidth = contentWidth / CGFloat(_columnCount) + var column = 0 + var yOffset: [CGFloat] = .init(repeating: 0, count: _columnCount) + + for item in 0.. [UICollectionViewLayoutAttributes]? { + var attributes: [UICollectionViewLayoutAttributes] = [] + for attribute in cache { + if attribute.frame.intersects(rect) { + attributes.append(attribute) + } + } + return attributes + } + + public override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { + return cache[indexPath.item] + } + +} From 41a570a9d357ff68c73717c6a4af9ae4bc600d41 Mon Sep 17 00:00:00 2001 From: Remmington Damper Date: Sun, 9 Jan 2022 08:10:33 -0500 Subject: [PATCH 07/10] added requested functionality --- .../LUXPinterestStyleLayout.swift | 56 +++++++++++++------ 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift index 04a7711..0ce8efc 100644 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -9,16 +9,17 @@ import UIKit public class LUXPinterestStyleLayout: UICollectionViewLayout { - - private var _columnCount = 2 { didSet {invalidateLayout() }} + private var _columnCount: Int? { didSet { invalidateLayout() }} public func setColumnCount(_ count: Int) { _columnCount = count } - private var _cellPadding: CGFloat = 0 { didSet { invalidateLayout() }} + private var _cellPadding: CGFloat = 0 {didSet { invalidateLayout() }} public func setCellPadding(_ padding: CGFloat = 0) { _cellPadding = padding } + private var _tuple: (columnCount: Int, baseItemWidth: CGFloat) = (0, 0.0) + private var cache: [UICollectionViewLayoutAttributes] = [] - private var _baseItemWidth: CGFloat = 0 { didSet {invalidateLayout() }} + private var _baseItemWidth: CGFloat? { didSet { invalidateLayout() }} public func setBaseItemWidth(_ width: CGFloat) { _baseItemWidth = width } public var widthForColumn: ((Int) -> CGFloat?)? = { _ in return nil } @@ -66,15 +67,35 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { } - private func calculateXOffset() -> [CGFloat]? { - guard _columnCount > 0 else { return nil } - guard _baseItemWidth > 0 else { return nil } - - let columnWidth = contentWidth / CGFloat(_columnCount) - + private func calculateXOffset() -> [CGFloat] { + var columnCount: Int = 0 var xOffSet: [CGFloat] = [] - for column in 0..<_columnCount { - xOffSet.append(CGFloat(column) * columnWidth) + var offSet: CGFloat = 0 + + if let columnCount = _columnCount { + let columnWidth = contentWidth / CGFloat(_columnCount!) + offSet = columnWidth + for column in 0.. Date: Sun, 9 Jan 2022 10:34:32 -0500 Subject: [PATCH 08/10] finsihed --- .../LUXPinterestStyleLayout.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift index 0ce8efc..c20e314 100644 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -101,18 +101,18 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { } open func cacheFramesAndCalculate() { - cache.removeAll() - guard cache.isEmpty, let collectionView = collectionView else { return } + cache.removeAll() + guard cache.isEmpty, let collectionView = collectionView else { return } - let xOffset = calculateXOffset() - let columnWidth = contentWidth / CGFloat(_columnCount!) - var column = 0 - var yOffset: [CGFloat] = .init(repeating: 0, count: _columnCount!) + let xOffset = calculateXOffset() + let columnWidth = contentWidth / CGFloat(_columnCount!) + var column = 0 + var yOffset: [CGFloat] = .init(repeating: 0, count: _columnCount!) - for item in 0.. Date: Tue, 11 Jan 2022 10:24:37 -0500 Subject: [PATCH 09/10] added width functionality --- .../Base/CollectionViews/LUXPinterestStyleLayout.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift index c20e314..73cf245 100644 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -15,14 +15,13 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { private var _cellPadding: CGFloat = 0 {didSet { invalidateLayout() }} public func setCellPadding(_ padding: CGFloat = 0) { _cellPadding = padding } - private var _tuple: (columnCount: Int, baseItemWidth: CGFloat) = (0, 0.0) - private var cache: [UICollectionViewLayoutAttributes] = [] private var _baseItemWidth: CGFloat? { didSet { invalidateLayout() }} public func setBaseItemWidth(_ width: CGFloat) { _baseItemWidth = width } - public var widthForColumn: ((Int) -> CGFloat?)? = { _ in return nil } + public var setWidthForColumn: Int? + private var widthForColumn: ((Int) -> CGFloat?)? = { _ in return nil } private var contentHeight: CGFloat = 0.0 private var contentWidth: CGFloat { @@ -76,7 +75,8 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { let columnWidth = contentWidth / CGFloat(_columnCount!) offSet = columnWidth for column in 0.. Date: Tue, 11 Jan 2022 17:32:16 -0500 Subject: [PATCH 10/10] Added Requested Functionality --- .../LUXPinterestStyleLayout.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift index 73cf245..f7494d0 100644 --- a/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift +++ b/LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift @@ -21,7 +21,7 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { public func setBaseItemWidth(_ width: CGFloat) { _baseItemWidth = width } public var setWidthForColumn: Int? - private var widthForColumn: ((Int) -> CGFloat?)? = { _ in return nil } + public var widthForColumn: ((Int) -> CGFloat?)? = { _ in return nil } private var contentHeight: CGFloat = 0.0 private var contentWidth: CGFloat { @@ -72,11 +72,20 @@ public class LUXPinterestStyleLayout: UICollectionViewLayout { var offSet: CGFloat = 0 if let columnCount = _columnCount { - let columnWidth = contentWidth / CGFloat(_columnCount!) + if let width = widthForColumn { + xOffSet = [0] + let columnWidth = contentWidth / CGFloat(columnCount) offSet = columnWidth - for column in 0..