Skip to content

Commit

Permalink
Merge pull request #31 from mobillium/feature/new-funcs
Browse files Browse the repository at this point in the history
Feature/new funcs
  • Loading branch information
aslanmehmetsalih authored Jun 30, 2021
2 parents f583ac3 + 7b587db commit e004e55
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- MobilliumBuilders (1.2.0)
- MobilliumBuilders (1.4.0)

DEPENDENCIES:
- MobilliumBuilders (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
MobilliumBuilders: 5c5fbc2ba2f5f2bf9e1bf92a7022e3ddb09ffcaa
MobilliumBuilders: 9990948aea3e132044431289dda869f524fcadac

PODFILE CHECKSUM: 61f4e0575a18a912fde25a7e488696c4df09c291

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/MobilliumBuilders.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Example/Tests/UICollectionViewBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,41 @@ class UICollectionViewBuilderTests: XCTestCase {

XCTAssertTrue(isContainsIdentifier)
}

func testCornerRadius() {
let cornerRadius: CGFloat = 10
let collectionView = UICollectionViewBuilder()
.cornerRadius(10)
.build()

XCTAssertEqual(cornerRadius, collectionView.layer.cornerRadius)
}

func testClipsToBounds() {
let clipsToBounds = true
let collectionView = UICollectionViewBuilder()
.clipsToBounds(true)
.build()

XCTAssertEqual(clipsToBounds, collectionView.clipsToBounds)
}

func testItemSize() {
let itemSize: CGSize = .init(width: 10, height: 10)
let collectionView = UICollectionViewBuilder()
.itemSize(itemSize)
.build()

XCTAssertEqual(itemSize, (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.itemSize)
}

func testTintColor() {
let tintColor: UIColor = .black
let collectionView = UICollectionViewBuilder()
.tintColor(tintColor)
.build()

XCTAssertEqual(tintColor, collectionView.tintColor)
}

}
12 changes: 12 additions & 0 deletions Example/Tests/UIImageViewBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,16 @@ class UIImageViewBuilderTests: XCTestCase {
XCTAssertEqual(imageView.accessibilityIdentifier, accessibilityIdentifier)
}

func testSize() {
let size: CGSize = .init(width: 10, height: 10)
let imageView = UIImageViewBuilder()
.size(size)
.build()

let widthConstraint = imageView.constraints.filter({ $0.firstAttribute == NSLayoutConstraint.Attribute.width }).first!
let heightConstraint = imageView.constraints.filter({ $0.firstAttribute == NSLayoutConstraint.Attribute.height }).first!
XCTAssertEqual(widthConstraint.constant, size.width)
XCTAssertEqual(heightConstraint.constant, size.height)
}

}
2 changes: 1 addition & 1 deletion MobilliumBuilders.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'MobilliumBuilders'
s.version = '1.3.0'
s.version = '1.4.0'
s.summary = 'Builders classes'

s.homepage = 'https://github.com/mobillium/MobilliumBuilders'
Expand Down
26 changes: 26 additions & 0 deletions MobilliumBuilders/Classes/UICollectionViewBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ public class UICollectionViewBuilder<T: UICollectionView> {
return self
}

@discardableResult
public func cornerRadius(_ cornerRadius: CGFloat) -> Self {
self.collectionView.layer.cornerRadius = cornerRadius
return self
}

@discardableResult
public func clipsToBounds(_ clipsToBounds: Bool) -> Self {
self.collectionView.clipsToBounds = clipsToBounds
return self
}

@discardableResult
public func itemSize(_ itemSize: CGSize) -> Self {
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
layout.itemSize = itemSize
}
return self
}

@discardableResult
public func tintColor(_ tintColor: UIColor) -> Self {
self.collectionView.tintColor = tintColor
return self
}

public func build() -> T {
return collectionView
}
Expand Down
8 changes: 8 additions & 0 deletions MobilliumBuilders/Classes/UIImageViewBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ public class UIImageViewBuilder<T: UIImageView> {
return self
}

@discardableResult
public func size(_ size: CGSize) -> Self {
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.widthAnchor.constraint(equalToConstant: size.width).isActive = true
imageView.heightAnchor.constraint(equalToConstant: size.height).isActive = true
return self
}

public func build() -> T {
return imageView
}
Expand Down

0 comments on commit e004e55

Please sign in to comment.