Skip to content

Commit fd1c389

Browse files
Merge pull request #16 from mr-araujo/implementar-category-list-view
[ViewCode-MD] Implementar Category List View
2 parents af10d9d + 203167c commit fd1c389

File tree

7 files changed

+193
-85
lines changed

7 files changed

+193
-85
lines changed

solutions/devsprint-michael-douglas-2/DeliveryApp.xcodeproj/project.pbxproj

Lines changed: 72 additions & 63 deletions
Large diffs are not rendered by default.

solutions/devsprint-michael-douglas-2/DeliveryApp.xcodeproj/xcshareddata/xcschemes/DeliveryApp.xcscheme

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
7-
buildImplicitDependencies = "YES">
7+
buildImplicitDependencies = "YES"
8+
runPostActionsOnFailure = "NO">
89
<BuildActionEntries>
910
<BuildActionEntry
1011
buildForTesting = "YES"
@@ -26,16 +27,8 @@
2627
buildConfiguration = "Debug"
2728
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2829
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
onlyGenerateCoverageForSpecifiedTargets = "NO"
2931
shouldUseLaunchSchemeArgsEnv = "YES">
30-
<MacroExpansion>
31-
<BuildableReference
32-
BuildableIdentifier = "primary"
33-
BlueprintIdentifier = "25D3EF7051FF9C9EA9A15959"
34-
BuildableName = "DeliveryApp.app"
35-
BlueprintName = "DeliveryApp"
36-
ReferencedContainer = "container:DeliveryApp.xcodeproj">
37-
</BuildableReference>
38-
</MacroExpansion>
3932
<Testables>
4033
<TestableReference
4134
skipped = "NO">
@@ -48,6 +41,17 @@
4841
</BuildableReference>
4942
</TestableReference>
5043
</Testables>
44+
<MacroExpansion>
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "25D3EF7051FF9C9EA9A15959"
48+
BuildableName = "DeliveryApp.app"
49+
BlueprintName = "DeliveryApp"
50+
ReferencedContainer = "container:DeliveryApp.xcodeproj">
51+
</BuildableReference>
52+
</MacroExpansion>
53+
<CommandLineArguments>
54+
</CommandLineArguments>
5155
</TestAction>
5256
<LaunchAction
5357
buildConfiguration = "Debug"
@@ -69,6 +73,8 @@
6973
ReferencedContainer = "container:DeliveryApp.xcodeproj">
7074
</BuildableReference>
7175
</BuildableProductRunnable>
76+
<CommandLineArguments>
77+
</CommandLineArguments>
7278
</LaunchAction>
7379
<ProfileAction
7480
buildConfiguration = "Release"
@@ -86,6 +92,8 @@
8692
ReferencedContainer = "container:DeliveryApp.xcodeproj">
8793
</BuildableReference>
8894
</BuildableProductRunnable>
95+
<CommandLineArguments>
96+
</CommandLineArguments>
8997
</ProfileAction>
9098
<AnalyzeAction
9199
buildConfiguration = "Debug">

solutions/devsprint-michael-douglas-2/DeliveryApp/Screens/Components/Category/CategoryCellView.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
import UIKit
99

10-
final class CategoryCellView: UIView {
10+
final class CategoryCellView: UICollectionViewCell {
11+
12+
static let identifier = "CategoryCell"
1113

1214
private lazy var imageView: UIImageView = {
1315
let image = UIImageView()
@@ -24,31 +26,29 @@ final class CategoryCellView: UIView {
2426
return label
2527
}()
2628

27-
public init() {
28-
super.init(frame: .zero)
29-
29+
override init(frame: CGRect) {
30+
super.init(frame: frame)
3031
addSubviews()
3132
setConstraints()
3233
setStyle()
3334
}
3435

35-
required init?(coder: NSCoder) {
36-
super.init(coder: coder)
37-
}
36+
@available(*, unavailable)
37+
required init?(coder: NSCoder) { nil }
3838

3939
private func addSubviews() {
40-
addSubview(imageView)
41-
addSubview(titleLabel)
40+
contentView.addSubview(imageView)
41+
contentView.addSubview(titleLabel)
4242
}
4343

4444
private func setConstraints() {
45-
subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }
45+
contentView.subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }
4646

4747
NSLayoutConstraint.activate ([
4848
imageView.topAnchor.constraint(equalTo: topAnchor, constant: 5),
49-
imageView.centerXAnchor.constraint(equalTo: centerXAnchor),
5049
imageView.widthAnchor.constraint(equalToConstant: 54),
5150
imageView.heightAnchor.constraint(equalToConstant: 54),
51+
imageView.centerXAnchor.constraint(equalTo: centerXAnchor),
5252

5353
titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 8),
5454
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//
2+
// CategoryListView.swift
3+
// DeliveryApp
4+
//
5+
// Created by Murillo R. Araújo on 28/02/22.
6+
//
7+
8+
import UIKit
9+
10+
class CategoryListView: UIView {
11+
12+
private lazy var collectionView: UICollectionView = {
13+
let layout = UICollectionViewFlowLayout()
14+
layout.sectionInset = .init(top: 16, left: 16, bottom: 16, right: 16)
15+
layout.itemSize = .init(width: 60, height: 90)
16+
layout.scrollDirection = .horizontal
17+
18+
let collection = UICollectionView(frame: .zero, collectionViewLayout: layout)
19+
collection.dataSource = self
20+
collection.delegate = self
21+
collection.showsHorizontalScrollIndicator = false
22+
collection.register(CategoryCellView.self, forCellWithReuseIdentifier: CategoryCellView.identifier)
23+
24+
return collection
25+
}()
26+
27+
init() {
28+
super.init(frame: .zero)
29+
addSubviews()
30+
setConstraints()
31+
setStyle()
32+
}
33+
34+
@available(*, unavailable)
35+
required init?(coder: NSCoder) { nil }
36+
37+
38+
private func addSubviews() {
39+
addSubview(collectionView)
40+
}
41+
42+
private func setConstraints() {
43+
subviews.forEach { $0.translatesAutoresizingMaskIntoConstraints = false }
44+
45+
NSLayoutConstraint.activate ([
46+
collectionView.topAnchor.constraint(equalTo: self.topAnchor),
47+
collectionView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
48+
collectionView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
49+
collectionView.heightAnchor.constraint(equalToConstant: 110)
50+
])
51+
}
52+
53+
func setStyle() {
54+
backgroundColor = .white
55+
}
56+
}
57+
58+
extension CategoryListView: UICollectionViewDataSource, UICollectionViewDelegate {
59+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
60+
10
61+
}
62+
63+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
64+
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CategoryCellView.identifier, for: indexPath) as? CategoryCellView else {
65+
return .init()
66+
}
67+
68+
return cell
69+
}
70+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// CategoryListViewSnapshotTests.swift
3+
// DeliveryAppTests
4+
//
5+
// Created by Murillo R. Araújo on 28/02/22.
6+
//
7+
8+
import XCTest
9+
import SnapshotTesting
10+
@testable import DeliveryApp
11+
12+
class CategoryListViewSnapshotTests: XCTestCase {
13+
14+
let snapshotSize = CGSize(width: 250, height: 110)
15+
16+
func test_categoryListView_whenSnapshot_shouldSucceed() {
17+
let categoryListView = CategoryListView()
18+
19+
assertSnapshot(matching: categoryListView, as: .image(size: snapshotSize))
20+
}
21+
}

solutions/devsprint-michael-douglas-2/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPEC CHECKSUMS:
1313

1414
PODFILE CHECKSUM: eed1b6882996396c07abdbbdb955edb2ea0353a2
1515

16-
COCOAPODS: 1.10.1
16+
COCOAPODS: 1.11.2

0 commit comments

Comments
 (0)