Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -164,7 +164,7 @@ SPEC CHECKSUMS:
LUX: a0a8013d109a4d4887f75fcc91637221e6749abb
PlaygroundVCHelpers: c7cc8994d2851ebd1590217101b4c6888d1c9cc8
Prelude: fe4cc0fd961d34edf48fe6b04d05c863449efb0a
SDWebImage: 4dc3e42d9ec0c1028b960a33ac6b637bb432207b
SDWebImage: 240e5c12b592fb1268c1d03b8c90d90e8c2ffe82
Slippers: 5a3c6f24a556a59a091e2cb60e588472827be87c

PODFILE CHECKSUM: 940b727264080c97240a108fc65ed553ccdfa5dc
Expand Down
1 change: 1 addition & 0 deletions Example/Tests/ListViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ class ListViewModelTests: XCTestCase {
XCTAssert(wasFiltered)
cancel.cancel()
}

}
32 changes: 32 additions & 0 deletions Example/Tests/LoginViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}



}
159 changes: 159 additions & 0 deletions LUX/Classes/Base/CollectionViews/LUXPinterestStyleLayout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
//
// LUXPinterestStyleLayout.swift
// LUX
//
// Created by Remmington Damper on 12/12/21.
//

import UIKit


public class LUXPinterestStyleLayout: UICollectionViewLayout {
private var _columnCount: Int? { 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? { didSet { invalidateLayout() }}
public func setBaseItemWidth(_ width: CGFloat) { _baseItemWidth = width }

public var setWidthForColumn: Int?
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..<cv.numberOfSections { count += cv.numberOfItems(inSection: i) }
}
return count
}

public override func prepare() {
super.prepare()

cacheFramesAndCalculate()
setContentSizeFromCache()

}

private func calculateXOffset() -> [CGFloat] {
var columnCount: Int = 0
var xOffSet: [CGFloat] = []
var offSet: CGFloat = 0

if let columnCount = _columnCount {
if let width = widthForColumn {
xOffSet = [0]
let columnWidth = contentWidth / CGFloat(columnCount)
offSet = columnWidth
for column in 0..<columnCount - 1 {
let columnWidth = width(setWidthForColumn!) ?? offSet
xOffSet.append(columnWidth * CGFloat(column))
}
} else {
let columnWidth = contentWidth / CGFloat(columnCount)
offSet = columnWidth
for column in 0..<columnCount {
xOffSet.append(offSet * CGFloat(column))
}
}
} else if let baseWidth = _baseItemWidth {
if _columnCount == nil {
columnCount = Int(contentWidth / baseWidth)
offSet = baseWidth / CGFloat(columnCount)

for column in 0..<columnCount {
xOffSet.append(offSet * CGFloat(column))
}
} else {
columnCount = _columnCount!
for column in 0..<columnCount {
xOffSet.append((CGFloat(baseWidth)) * CGFloat(column))
}
}
} else {
for column in 0..<2 {
xOffSet.append((contentWidth / 2) * CGFloat(column))
}
}
return xOffSet
}

open func cacheFramesAndCalculate() {
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!)

for item in 0..<itemCount {
let indexPath = IndexPath(item: item, section: 0)

let photoHeight = heightForCellAtIndexPath?(collectionView, indexPath) ?? 180
let height = _cellPadding * 2 + photoHeight

//had to give a magic number. Not sure if the magic number is good.
let frame = CGRect(x: xOffset[column],
y: yOffset[column],
width: columnWidth,
height: height)
let insetFrame = frame.insetBy(dx: _cellPadding, dy: _cellPadding)

let attributes = UICollectionViewLayoutAttributes(forCellWith: indexPath)
attributes.frame = insetFrame
cache.append(attributes)

contentHeight = max(contentHeight, frame.maxY)
yOffset[column] = yOffset[column] + height

column = column < ( _columnCount! - 1) ? (column + 1) : 0
}
}

public override func layoutAttributesForElements(in rect: CGRect) -> [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]
}

}