From f1c502f86fb6827a81c7afccf55314286b3d658b Mon Sep 17 00:00:00 2001 From: Anderson Oliveira Date: Wed, 4 May 2022 13:53:54 -0300 Subject: [PATCH 1/4] CategoryCell finished. CategoryListView initialized --- .../DeliveryApp.xcodeproj/project.pbxproj | 16 ++++- .../DeliveryApp/Models/Ctegory.swift | 13 ++++ .../Screens/Components/CategoryCell.swift | 71 +++++++++++++++++++ .../Screens/Components/CategoryListView.swift | 70 ++++++++++++++++++ 4 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift create mode 100644 solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift create mode 100644 solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj index 52e0069..c4a7677 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj @@ -7,11 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - 87FACFE62819B3A500CDA67E /* RestaurantCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */; }; 870B56F8281993AE00A4D17A /* AddressCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870B56F7281993AE00A4D17A /* AddressCell.swift */; }; + 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */; }; + 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CBA02822AF6700A38B61 /* CategoryListView.swift */; }; 873B6EE828205E3C003B4088 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE728205E3C003B4088 /* EmptyView.swift */; }; 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B2D28186170002C0B95 /* LoadingView.swift */; }; 877B5B3328186467002C0B95 /* ViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B3228186467002C0B95 /* ViewConfiguration.swift */; }; + 87EA105D2822E486008B4116 /* Ctegory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA105C2822E486008B4116 /* Ctegory.swift */; }; + 87FACFE62819B3A500CDA67E /* RestaurantCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */; }; 983271C6272752B50010C63A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 983271C5272752B50010C63A /* Assets.xcassets */; }; 983271C9272752B50010C63A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 983271C7272752B50010C63A /* LaunchScreen.storyboard */; }; 983271D4272752B50010C63A /* DeliveryAppTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983271D3272752B50010C63A /* DeliveryAppTests.swift */; }; @@ -47,11 +50,14 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantCell.swift; sourceTree = ""; }; 870B56F7281993AE00A4D17A /* AddressCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressCell.swift; sourceTree = ""; }; + 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = ""; }; + 8734CBA02822AF6700A38B61 /* CategoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListView.swift; sourceTree = ""; }; 873B6EE728205E3C003B4088 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = ""; }; 877B5B2D28186170002C0B95 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 877B5B3228186467002C0B95 /* ViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewConfiguration.swift; sourceTree = ""; }; + 87EA105C2822E486008B4116 /* Ctegory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ctegory.swift; sourceTree = ""; }; + 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantCell.swift; sourceTree = ""; }; 983271B9272752AF0010C63A /* DeliveryApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeliveryApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 983271BC272752AF0010C63A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 983271BE272752AF0010C63A /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -209,6 +215,7 @@ isa = PBXGroup; children = ( 98C4368627ADAEA500D9048A /* Restaurant.swift */, + 87EA105C2822E486008B4116 /* Ctegory.swift */, ); path = Models; sourceTree = ""; @@ -271,6 +278,8 @@ 98C4368027ADADC000D9048A /* SampleComponentView.swift */, 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */, 870B56F7281993AE00A4D17A /* AddressCell.swift */, + 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */, + 8734CBA02822AF6700A38B61 /* CategoryListView.swift */, ); path = Components; sourceTree = ""; @@ -397,6 +406,7 @@ 98AF572227ADB16E00339A66 /* AppDelegate.swift in Sources */, 98AF573627ADB34C00339A66 /* DebugViewController.swift in Sources */, 98AF572327ADB16E00339A66 /* SceneDelegate.swift in Sources */, + 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */, 98AF572427ADB16E00339A66 /* SampleComponentView.swift in Sources */, 873B6EE828205E3C003B4088 /* EmptyView.swift in Sources */, 98AF572527ADB16E00339A66 /* HomeViewController.swift in Sources */, @@ -410,12 +420,14 @@ 98AF572B27ADB16E00339A66 /* RestaurantDetailsViewController.swift in Sources */, 98AF572C27ADB16E00339A66 /* RestaurantDetailsView.swift in Sources */, 98AF572D27ADB16E00339A66 /* MenuItemViewController.swift in Sources */, + 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */, 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */, 98AF572E27ADB16E00339A66 /* MenuItemView.swift in Sources */, 98AF572F27ADB16E00339A66 /* SettingsViewController.swift in Sources */, 98AF573027ADB16E00339A66 /* SettingsView.swift in Sources */, 98AF573127ADB16E00339A66 /* DeliveryApi.swift in Sources */, 98AF573227ADB16E00339A66 /* Restaurant.swift in Sources */, + 87EA105D2822E486008B4116 /* Ctegory.swift in Sources */, 98AF573327ADB16E00339A66 /* String+Extensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift new file mode 100644 index 0000000..0730c82 --- /dev/null +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift @@ -0,0 +1,13 @@ +// +// Ctegory.swift +// DeliveryApp +// +// Created by Cora on 04/05/22. +// + +import Foundation + +struct Category: Decodable { + let categoryName: String + let categoryImageLabel: String +} diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift new file mode 100644 index 0000000..720f8e1 --- /dev/null +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift @@ -0,0 +1,71 @@ +// +// CategoryCell.swift +// DeliveryApp +// +// Created by Cora on 04/05/22. +// + +import Foundation +import UIKit + +final class CategoryCell: UITableViewCell, ViewConfiguration { + + static var identifier = "CategoryCell" + + private lazy var categoryStackView: UIStackView = { + let stackView = UIStackView() + stackView.spacing = 10 + stackView.axis = .vertical + stackView.alignment = .center + return stackView + }() + + private lazy var categoryImage: UIImageView = { + let catImage = UIImageView() + catImage.image = UIImage(named: "pizza") + return catImage + }() + + private lazy var categoryLabel: UILabel = { + let catLabel = UILabel() + catLabel.text = "Pizza" + return catLabel + }() + + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setupViews() + } + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func updateCell(imageName: String, category: String){ + categoryImage.image = UIImage(named: imageName) + categoryLabel.text = category + } + + func configViews() { } + + func buildViews() { + [categoryStackView].forEach(addSubview) + [categoryImage,categoryLabel].forEach(categoryStackView.addArrangedSubview) + } + + func setupConstraints() { + [categoryStackView,categoryLabel,categoryImage].forEach { + $0.translatesAutoresizingMaskIntoConstraints = false + } + NSLayoutConstraint.activate([ + categoryStackView.topAnchor.constraint(equalTo: topAnchor), + categoryStackView.leadingAnchor.constraint(equalTo: leadingAnchor), + categoryStackView.trailingAnchor.constraint(equalTo: trailingAnchor), + categoryStackView.bottomAnchor.constraint(equalTo: bottomAnchor), + + categoryImage.heightAnchor.constraint(equalToConstant: 54), + categoryImage.widthAnchor.constraint(equalToConstant: 54) + ]) + } +} diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift new file mode 100644 index 0000000..1f717e2 --- /dev/null +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift @@ -0,0 +1,70 @@ +// +// CategoryListView.swift +// DeliveryApp +// +// Created by Cora on 04/05/22. +// + +import Foundation +import UIKit + +final class CategoryListView: UIView, ViewConfiguration { + + + let num = Category(categoryName: "Futeborrr", categoryImageLabel: "pizza") + let num2 = Category(categoryName: "Firrrme ", categoryImageLabel: "pizza") + + var listCategories: [Category] = [] + + lazy var tableView: UITableView = { + let table = UITableView() + table.register(CategoryCell.self, forCellReuseIdentifier: CategoryCell.identifier) + table.backgroundColor = .lightGray + table.translatesAutoresizingMaskIntoConstraints = false + return table + }() + + init() { + super.init(frame: .zero) + tableView.delegate = self + tableView.dataSource = self + setupViews() + listCategories = [num, num2] + } + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + + func configViews() { + backgroundColor = .white + print("entri") + } + + func buildViews() { + [tableView].forEach(addSubview) + } + + func setupConstraints() { + NSLayoutConstraint.activate([ + tableView.topAnchor.constraint(equalTo: topAnchor), + tableView.leadingAnchor.constraint(equalTo: leadingAnchor), + tableView.trailingAnchor.constraint(equalTo: trailingAnchor), + tableView.bottomAnchor.constraint(equalTo: bottomAnchor) + ]) + } +} + +extension CategoryListView: UITableViewDelegate, UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return 2 + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let category = listCategories[indexPath.row] + let cell = tableView.dequeueReusableCell(withIdentifier: CategoryCell.identifier, for: indexPath) as! CategoryCell + cell.updateCell(imageName: category.categoryImageLabel, category: category.categoryName) + return cell + } +} From a784f9dd3337833b7e5bb0d17d2e1e3293cfe4be Mon Sep 17 00:00:00 2001 From: Anderson Oliveira Date: Fri, 6 May 2022 17:19:50 -0300 Subject: [PATCH 2/4] CategoryCell and CategoryListView finished --- .../DeliveryApp.xcodeproj/project.pbxproj | 16 +++++ .../Screens/Components/CategoryCell.swift | 28 ++++---- .../Screens/Components/CategoryListView.swift | 71 ++++++++++--------- 3 files changed, 69 insertions(+), 46 deletions(-) diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj index c4a7677..1077bf3 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 8704C0E428258D6800E53106 /* ViewTestePraChamarCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8704C0E328258D6800E53106 /* ViewTestePraChamarCollection.swift */; }; 870B56F8281993AE00A4D17A /* AddressCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870B56F7281993AE00A4D17A /* AddressCell.swift */; }; 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */; }; 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CBA02822AF6700A38B61 /* CategoryListView.swift */; }; @@ -14,6 +15,7 @@ 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B2D28186170002C0B95 /* LoadingView.swift */; }; 877B5B3328186467002C0B95 /* ViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B3228186467002C0B95 /* ViewConfiguration.swift */; }; 87EA105D2822E486008B4116 /* Ctegory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA105C2822E486008B4116 /* Ctegory.swift */; }; + 87EA106128231315008B4116 /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA106028231315008B4116 /* CollectionView.swift */; }; 87FACFE62819B3A500CDA67E /* RestaurantCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */; }; 983271C6272752B50010C63A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 983271C5272752B50010C63A /* Assets.xcassets */; }; 983271C9272752B50010C63A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 983271C7272752B50010C63A /* LaunchScreen.storyboard */; }; @@ -50,6 +52,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 8704C0E328258D6800E53106 /* ViewTestePraChamarCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTestePraChamarCollection.swift; sourceTree = ""; }; 870B56F7281993AE00A4D17A /* AddressCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressCell.swift; sourceTree = ""; }; 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = ""; }; 8734CBA02822AF6700A38B61 /* CategoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListView.swift; sourceTree = ""; }; @@ -57,6 +60,7 @@ 877B5B2D28186170002C0B95 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 877B5B3228186467002C0B95 /* ViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewConfiguration.swift; sourceTree = ""; }; 87EA105C2822E486008B4116 /* Ctegory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ctegory.swift; sourceTree = ""; }; + 87EA106028231315008B4116 /* CollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = ""; }; 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantCell.swift; sourceTree = ""; }; 983271B9272752AF0010C63A /* DeliveryApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeliveryApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 983271BC272752AF0010C63A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -127,6 +131,15 @@ path = ViewConfiguration; sourceTree = ""; }; + 87EA105E282312FE008B4116 /* TESTEEEEEECOLECT */ = { + isa = PBXGroup; + children = ( + 87EA106028231315008B4116 /* CollectionView.swift */, + 8704C0E328258D6800E53106 /* ViewTestePraChamarCollection.swift */, + ); + path = TESTEEEEEECOLECT; + sourceTree = ""; + }; 983271B0272752AF0010C63A = { isa = PBXGroup; children = ( @@ -148,6 +161,7 @@ 983271BB272752AF0010C63A /* DeliveryApp */ = { isa = PBXGroup; children = ( + 87EA105E282312FE008B4116 /* TESTEEEEEECOLECT */, 983271EC272752C50010C63A /* Resources */, 983271ED272752D20010C63A /* AppDelegate */, 983271EE272752EE0010C63A /* Screens */, @@ -426,6 +440,8 @@ 98AF572F27ADB16E00339A66 /* SettingsViewController.swift in Sources */, 98AF573027ADB16E00339A66 /* SettingsView.swift in Sources */, 98AF573127ADB16E00339A66 /* DeliveryApi.swift in Sources */, + 87EA106128231315008B4116 /* CollectionView.swift in Sources */, + 8704C0E428258D6800E53106 /* ViewTestePraChamarCollection.swift in Sources */, 98AF573227ADB16E00339A66 /* Restaurant.swift in Sources */, 87EA105D2822E486008B4116 /* Ctegory.swift in Sources */, 98AF573327ADB16E00339A66 /* String+Extensions.swift in Sources */, diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift index 720f8e1..3f7140a 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift @@ -8,33 +8,35 @@ import Foundation import UIKit -final class CategoryCell: UITableViewCell, ViewConfiguration { - +class CategoryCell: UICollectionViewCell, ViewConfiguration { + static var identifier = "CategoryCell" private lazy var categoryStackView: UIStackView = { let stackView = UIStackView() stackView.spacing = 10 stackView.axis = .vertical - stackView.alignment = .center + stackView.distribution = .equalSpacing return stackView }() - private lazy var categoryImage: UIImageView = { - let catImage = UIImageView() - catImage.image = UIImage(named: "pizza") + lazy var categoryImage: UIImageView = { + let catImage = UIImageView() + catImage.layer.masksToBounds = true + catImage.layer.cornerRadius = 14 return catImage }() - private lazy var categoryLabel: UILabel = { - let catLabel = UILabel() - catLabel.text = "Pizza" + lazy var categoryLabel: UILabel = { + let catLabel = UILabel() + catLabel.textAlignment = .center + catLabel.font = .systemFont(ofSize: 12) + catLabel.textColor = UIColor(red: 0.235, green: 0.235, blue: 0.263, alpha: 0.6) return catLabel }() - - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) + override init(frame: CGRect){ + super.init(frame: frame) setupViews() } @available(*, unavailable) @@ -62,10 +64,8 @@ final class CategoryCell: UITableViewCell, ViewConfiguration { categoryStackView.topAnchor.constraint(equalTo: topAnchor), categoryStackView.leadingAnchor.constraint(equalTo: leadingAnchor), categoryStackView.trailingAnchor.constraint(equalTo: trailingAnchor), - categoryStackView.bottomAnchor.constraint(equalTo: bottomAnchor), categoryImage.heightAnchor.constraint(equalToConstant: 54), - categoryImage.widthAnchor.constraint(equalToConstant: 54) ]) } } diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift index 1f717e2..ca9b494 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryListView.swift @@ -1,70 +1,77 @@ // -// CategoryListView.swift +// CollectionView.swift // DeliveryApp // -// Created by Cora on 04/05/22. +// Created by Anderson Oliveira on 04/05/22. // import Foundation + + + import UIKit final class CategoryListView: UIView, ViewConfiguration { + private var categories: [Category] - let num = Category(categoryName: "Futeborrr", categoryImageLabel: "pizza") - let num2 = Category(categoryName: "Firrrme ", categoryImageLabel: "pizza") - - var listCategories: [Category] = [] - - lazy var tableView: UITableView = { - let table = UITableView() - table.register(CategoryCell.self, forCellReuseIdentifier: CategoryCell.identifier) - table.backgroundColor = .lightGray - table.translatesAutoresizingMaskIntoConstraints = false - return table + private lazy var collectionView: UICollectionView = { + let layout = UICollectionViewFlowLayout() + layout.scrollDirection = .horizontal + layout.itemSize = CGSize(width: 64, height: 80) + layout.sectionInset = UIEdgeInsets(top: 21.5, left: 18, bottom: 21.5, right: 18) + let collection = UICollectionView(frame: .zero, collectionViewLayout: layout) + collection.register(CategoryCell.self, forCellWithReuseIdentifier: CategoryCell.identifier) + collection.translatesAutoresizingMaskIntoConstraints = false + return collection }() - init() { + + init(categories: [Category]) { + self.categories = categories super.init(frame: .zero) - tableView.delegate = self - tableView.dataSource = self + collectionView.delegate = self + collectionView.dataSource = self setupViews() - listCategories = [num, num2] } + @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - - + func configViews() { backgroundColor = .white - print("entri") } func buildViews() { - [tableView].forEach(addSubview) + [collectionView].forEach(addSubview) } func setupConstraints() { NSLayoutConstraint.activate([ - tableView.topAnchor.constraint(equalTo: topAnchor), - tableView.leadingAnchor.constraint(equalTo: leadingAnchor), - tableView.trailingAnchor.constraint(equalTo: trailingAnchor), - tableView.bottomAnchor.constraint(equalTo: bottomAnchor) + collectionView.topAnchor.constraint(equalTo: topAnchor), + collectionView.leadingAnchor.constraint(equalTo: leadingAnchor), + collectionView.trailingAnchor.constraint(equalTo: trailingAnchor), + collectionView.bottomAnchor.constraint(equalTo: bottomAnchor), ]) } } - -extension CategoryListView: UITableViewDelegate, UITableViewDataSource { - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 2 +extension CategoryListView: UICollectionViewDataSource { + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return categories.count } - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let category = listCategories[indexPath.row] - let cell = tableView.dequeueReusableCell(withIdentifier: CategoryCell.identifier, for: indexPath) as! CategoryCell + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let category = categories[indexPath.row] + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CategoryCell.identifier, for: indexPath) as! CategoryCell + cell.updateCell(imageName: category.categoryImageLabel, category: category.categoryName) return cell } } + +extension CategoryListView: UICollectionViewDelegate { + +} From fa58736ff18b4249bbd0f6d70d38e8394b04170e Mon Sep 17 00:00:00 2001 From: Anderson Oliveira Date: Fri, 6 May 2022 20:22:08 -0300 Subject: [PATCH 3/4] changed name of creator in some files --- .../DeliveryApp.xcodeproj/project.pbxproj | 24 ++++--------------- .../Models/{Ctegory.swift => Category.swift} | 4 ++-- .../Screens/Components/AddressCell.swift | 2 +- .../Screens/Components/CategoryCell.swift | 2 +- 4 files changed, 8 insertions(+), 24 deletions(-) rename solutions/devsprint-ana-nogal-1/DeliveryApp/Models/{Ctegory.swift => Category.swift} (68%) diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj index 1077bf3..1e5dc52 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj @@ -7,15 +7,13 @@ objects = { /* Begin PBXBuildFile section */ - 8704C0E428258D6800E53106 /* ViewTestePraChamarCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8704C0E328258D6800E53106 /* ViewTestePraChamarCollection.swift */; }; 870B56F8281993AE00A4D17A /* AddressCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870B56F7281993AE00A4D17A /* AddressCell.swift */; }; 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */; }; 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CBA02822AF6700A38B61 /* CategoryListView.swift */; }; 873B6EE828205E3C003B4088 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE728205E3C003B4088 /* EmptyView.swift */; }; 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B2D28186170002C0B95 /* LoadingView.swift */; }; 877B5B3328186467002C0B95 /* ViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B3228186467002C0B95 /* ViewConfiguration.swift */; }; - 87EA105D2822E486008B4116 /* Ctegory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA105C2822E486008B4116 /* Ctegory.swift */; }; - 87EA106128231315008B4116 /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA106028231315008B4116 /* CollectionView.swift */; }; + 87EA105D2822E486008B4116 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA105C2822E486008B4116 /* Category.swift */; }; 87FACFE62819B3A500CDA67E /* RestaurantCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */; }; 983271C6272752B50010C63A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 983271C5272752B50010C63A /* Assets.xcassets */; }; 983271C9272752B50010C63A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 983271C7272752B50010C63A /* LaunchScreen.storyboard */; }; @@ -52,15 +50,13 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 8704C0E328258D6800E53106 /* ViewTestePraChamarCollection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewTestePraChamarCollection.swift; sourceTree = ""; }; 870B56F7281993AE00A4D17A /* AddressCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressCell.swift; sourceTree = ""; }; 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = ""; }; 8734CBA02822AF6700A38B61 /* CategoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListView.swift; sourceTree = ""; }; 873B6EE728205E3C003B4088 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = ""; }; 877B5B2D28186170002C0B95 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 877B5B3228186467002C0B95 /* ViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewConfiguration.swift; sourceTree = ""; }; - 87EA105C2822E486008B4116 /* Ctegory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ctegory.swift; sourceTree = ""; }; - 87EA106028231315008B4116 /* CollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = ""; }; + 87EA105C2822E486008B4116 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = ""; }; 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantCell.swift; sourceTree = ""; }; 983271B9272752AF0010C63A /* DeliveryApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeliveryApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 983271BC272752AF0010C63A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -131,15 +127,6 @@ path = ViewConfiguration; sourceTree = ""; }; - 87EA105E282312FE008B4116 /* TESTEEEEEECOLECT */ = { - isa = PBXGroup; - children = ( - 87EA106028231315008B4116 /* CollectionView.swift */, - 8704C0E328258D6800E53106 /* ViewTestePraChamarCollection.swift */, - ); - path = TESTEEEEEECOLECT; - sourceTree = ""; - }; 983271B0272752AF0010C63A = { isa = PBXGroup; children = ( @@ -161,7 +148,6 @@ 983271BB272752AF0010C63A /* DeliveryApp */ = { isa = PBXGroup; children = ( - 87EA105E282312FE008B4116 /* TESTEEEEEECOLECT */, 983271EC272752C50010C63A /* Resources */, 983271ED272752D20010C63A /* AppDelegate */, 983271EE272752EE0010C63A /* Screens */, @@ -229,7 +215,7 @@ isa = PBXGroup; children = ( 98C4368627ADAEA500D9048A /* Restaurant.swift */, - 87EA105C2822E486008B4116 /* Ctegory.swift */, + 87EA105C2822E486008B4116 /* Category.swift */, ); path = Models; sourceTree = ""; @@ -440,10 +426,8 @@ 98AF572F27ADB16E00339A66 /* SettingsViewController.swift in Sources */, 98AF573027ADB16E00339A66 /* SettingsView.swift in Sources */, 98AF573127ADB16E00339A66 /* DeliveryApi.swift in Sources */, - 87EA106128231315008B4116 /* CollectionView.swift in Sources */, - 8704C0E428258D6800E53106 /* ViewTestePraChamarCollection.swift in Sources */, 98AF573227ADB16E00339A66 /* Restaurant.swift in Sources */, - 87EA105D2822E486008B4116 /* Ctegory.swift in Sources */, + 87EA105D2822E486008B4116 /* Category.swift in Sources */, 98AF573327ADB16E00339A66 /* String+Extensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Category.swift similarity index 68% rename from solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift rename to solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Category.swift index 0730c82..79c91bb 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Ctegory.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Models/Category.swift @@ -1,8 +1,8 @@ // -// Ctegory.swift +// Category.swift // DeliveryApp // -// Created by Cora on 04/05/22. +// Created by Anderson Oliveira on 04/05/22. // import Foundation diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift index eae8048..afce8be 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/AddressCell.swift @@ -2,7 +2,7 @@ // AddressCell.swift // DeliveryApp // -// Created by Cora on 27/04/22. +// Created by Anderson Oliveira on 27/04/22. // import UIKit diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift index 3f7140a..bf37bea 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift @@ -2,7 +2,7 @@ // CategoryCell.swift // DeliveryApp // -// Created by Cora on 04/05/22. +// Created by Anderson Oliveira on 04/05/22. // import Foundation From 240ab1fb4f21672c1c8230d2a2cdf436a93762c5 Mon Sep 17 00:00:00 2001 From: Anderson Oliveira Date: Sat, 7 May 2022 08:17:38 -0300 Subject: [PATCH 4/4] categoryCell edited to be equal figma --- .../DeliveryApp.xcodeproj/project.pbxproj | 10 ++++------ .../Screens/Components/CategoryCell.swift | 14 +++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj index f700205..6530ba7 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp.xcodeproj/project.pbxproj @@ -8,15 +8,14 @@ /* Begin PBXBuildFile section */ 870B56F8281993AE00A4D17A /* AddressCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 870B56F7281993AE00A4D17A /* AddressCell.swift */; }; + 87148A0228215E2B0058F5D2 /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87148A0128215E2B0058F5D2 /* Address.swift */; }; 8734CB9F2822AAD400A38B61 /* CategoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */; }; 8734CBA12822AF6700A38B61 /* CategoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8734CBA02822AF6700A38B61 /* CategoryListView.swift */; }; - 873B6EEA2820715A003B4088 /* MenuItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE92820715A003B4088 /* MenuItemCell.swift */; }; - 87148A0228215E2B0058F5D2 /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87148A0128215E2B0058F5D2 /* Address.swift */; }; 873B6EE828205E3C003B4088 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE728205E3C003B4088 /* EmptyView.swift */; }; + 873B6EEA2820715A003B4088 /* MenuItemCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 873B6EE92820715A003B4088 /* MenuItemCell.swift */; }; 877B5B2E28186170002C0B95 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B2D28186170002C0B95 /* LoadingView.swift */; }; 877B5B3328186467002C0B95 /* ViewConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 877B5B3228186467002C0B95 /* ViewConfiguration.swift */; }; 87EA105D2822E486008B4116 /* Category.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87EA105C2822E486008B4116 /* Category.swift */; }; - 87148A0228215E2B0058F5D2 /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87148A0128215E2B0058F5D2 /* Address.swift */; }; 87FACFE62819B3A500CDA67E /* RestaurantCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */; }; 983271C6272752B50010C63A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 983271C5272752B50010C63A /* Assets.xcassets */; }; 983271C9272752B50010C63A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 983271C7272752B50010C63A /* LaunchScreen.storyboard */; }; @@ -54,15 +53,14 @@ /* Begin PBXFileReference section */ 870B56F7281993AE00A4D17A /* AddressCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressCell.swift; sourceTree = ""; }; + 87148A0128215E2B0058F5D2 /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = ""; }; 8734CB9E2822AAD400A38B61 /* CategoryCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryCell.swift; sourceTree = ""; }; 8734CBA02822AF6700A38B61 /* CategoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryListView.swift; sourceTree = ""; }; - 873B6EE92820715A003B4088 /* MenuItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemCell.swift; sourceTree = ""; }; - 87148A0128215E2B0058F5D2 /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = ""; }; 873B6EE728205E3C003B4088 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = ""; }; + 873B6EE92820715A003B4088 /* MenuItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuItemCell.swift; sourceTree = ""; }; 877B5B2D28186170002C0B95 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 877B5B3228186467002C0B95 /* ViewConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewConfiguration.swift; sourceTree = ""; }; 87EA105C2822E486008B4116 /* Category.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Category.swift; sourceTree = ""; }; - 87148A0128215E2B0058F5D2 /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = ""; }; 87FACFE52819B3A500CDA67E /* RestaurantCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantCell.swift; sourceTree = ""; }; 983271B9272752AF0010C63A /* DeliveryApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeliveryApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 983271BC272752AF0010C63A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; diff --git a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift index bf37bea..622e16d 100644 --- a/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift +++ b/solutions/devsprint-ana-nogal-1/DeliveryApp/Screens/Components/CategoryCell.swift @@ -52,8 +52,7 @@ class CategoryCell: UICollectionViewCell, ViewConfiguration { func configViews() { } func buildViews() { - [categoryStackView].forEach(addSubview) - [categoryImage,categoryLabel].forEach(categoryStackView.addArrangedSubview) + [categoryImage,categoryLabel].forEach(addSubview) } func setupConstraints() { @@ -61,9 +60,14 @@ class CategoryCell: UICollectionViewCell, ViewConfiguration { $0.translatesAutoresizingMaskIntoConstraints = false } NSLayoutConstraint.activate([ - categoryStackView.topAnchor.constraint(equalTo: topAnchor), - categoryStackView.leadingAnchor.constraint(equalTo: leadingAnchor), - categoryStackView.trailingAnchor.constraint(equalTo: trailingAnchor), + categoryImage.topAnchor.constraint(equalTo: topAnchor), + categoryImage.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 2.5), + categoryImage.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -2.5), + + categoryLabel.topAnchor.constraint(equalTo: categoryImage.bottomAnchor, constant: 10), + categoryLabel.leadingAnchor.constraint(equalTo: leadingAnchor), + categoryLabel.trailingAnchor.constraint(equalTo: trailingAnchor), + categoryLabel.bottomAnchor.constraint(equalTo: bottomAnchor), categoryImage.heightAnchor.constraint(equalToConstant: 54), ])