Skip to content

Commit fcb0b99

Browse files
Merge pull request devpass-tech#30 from vitor-rc1/feature/address-view
Feature/AddressView
2 parents 224cf8e + 13d9198 commit fcb0b99

File tree

3 files changed

+132
-37
lines changed

3 files changed

+132
-37
lines changed

solutions/devsprint-vinicius-carvalho-3/DeliveryApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1E2324E328871F2F00414138 /* ViewCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2324E228871F2F00414138 /* ViewCode.swift */; };
1111
1E2324E5288720CA00414138 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2324E4288720CA00414138 /* LoadingView.swift */; };
12+
1EAC8D92288A22E900A37973 /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EAC8D91288A22E900A37973 /* AddressView.swift */; };
1213
8B113973288865DE00A42625 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B113972288865DE00A42625 /* EmptyView.swift */; };
1314
98228D7D27BC489F006A38BB /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98228D7C27BC489F006A38BB /* Address.swift */; };
1415
98228D7F27BC490E006A38BB /* RestaurantDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98228D7E27BC490E006A38BB /* RestaurantDetails.swift */; };
@@ -49,6 +50,7 @@
4950
/* Begin PBXFileReference section */
5051
1E2324E228871F2F00414138 /* ViewCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCode.swift; sourceTree = "<group>"; };
5152
1E2324E4288720CA00414138 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
53+
1EAC8D91288A22E900A37973 /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
5254
8B113972288865DE00A42625 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = "<group>"; };
5355
98228D7C27BC489F006A38BB /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = "<group>"; };
5456
98228D7E27BC490E006A38BB /* RestaurantDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantDetails.swift; sourceTree = "<group>"; };
@@ -254,6 +256,7 @@
254256
children = (
255257
98C4368027ADADC000D9048A /* SampleComponentView.swift */,
256258
1E2324E4288720CA00414138 /* LoadingView.swift */,
259+
1EAC8D91288A22E900A37973 /* AddressView.swift */,
257260
8B113972288865DE00A42625 /* EmptyView.swift */,
258261
);
259262
path = Components;
@@ -383,6 +386,7 @@
383386
98AF572427ADB16E00339A66 /* SampleComponentView.swift in Sources */,
384387
8B113973288865DE00A42625 /* EmptyView.swift in Sources */,
385388
98AF572527ADB16E00339A66 /* HomeViewController.swift in Sources */,
389+
1EAC8D92288A22E900A37973 /* AddressView.swift in Sources */,
386390
98AF572627ADB16E00339A66 /* HomeView.swift in Sources */,
387391
98AF572727ADB16E00339A66 /* AddressSearchViewController.swift in Sources */,
388392
98AF572827ADB16E00339A66 /* AddressListView.swift in Sources */,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// AddressView.swift
3+
// DeliveryApp
4+
//
5+
// Created by Vitor Conceicao on 21/07/22.
6+
//
7+
8+
import UIKit
9+
10+
final class AddressView: UIView {
11+
private lazy var addressLabel: UILabel = {
12+
let addressLabel = UILabel()
13+
addressLabel.font = .boldSystemFont(ofSize: 15)
14+
return addressLabel
15+
}()
16+
17+
private lazy var editButton: UIButton = {
18+
let buttonVerticalPadding: CGFloat = 10.0
19+
let buttonHorizontalPadding: CGFloat = 16.0
20+
21+
let editButton = UIButton(configuration: .plain())
22+
editButton.configuration?.subtitle = "Editar"
23+
editButton.configuration?.background.strokeColor = .systemBlue
24+
editButton.configuration?.background.strokeWidth = 2.0
25+
editButton.configuration?.cornerStyle = .large
26+
editButton.configuration?.contentInsets = NSDirectionalEdgeInsets(top: buttonVerticalPadding,
27+
leading: buttonHorizontalPadding,
28+
bottom: buttonVerticalPadding,
29+
trailing: buttonHorizontalPadding)
30+
editButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
31+
return editButton
32+
}()
33+
34+
private lazy var horizontalStackView: UIStackView = {
35+
let horizontalStackView = UIStackView()
36+
horizontalStackView.axis = .horizontal
37+
horizontalStackView.spacing = spacing
38+
horizontalStackView.distribution = .fill
39+
horizontalStackView.alignment = .center
40+
horizontalStackView.translatesAutoresizingMaskIntoConstraints = false
41+
return horizontalStackView
42+
}()
43+
44+
// MARK: private properties
45+
46+
private let spacing: CGFloat = 16.0
47+
48+
// MARK: inits
49+
50+
convenience init() {
51+
self.init(frame: .zero)
52+
setup()
53+
}
54+
55+
// MARK: configuration
56+
57+
struct AddressViewConfiguration {
58+
let address: String
59+
}
60+
61+
// MARK: methods
62+
63+
func updateView(with configuration: AddressViewConfiguration) {
64+
addressLabel.text = configuration.address
65+
}
66+
}
67+
68+
extension AddressView: ViewCode {
69+
func setupSubviews() {
70+
horizontalStackView.addArrangedSubview(addressLabel)
71+
horizontalStackView.addArrangedSubview(editButton)
72+
73+
addSubview(horizontalStackView)
74+
}
75+
76+
func setupConstraints() {
77+
setupHorizontalStackViewConstraints()
78+
}
79+
80+
private func setupHorizontalStackViewConstraints() {
81+
NSLayoutConstraint.activate([
82+
horizontalStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: spacing),
83+
horizontalStackView.topAnchor.constraint(equalTo: topAnchor, constant: spacing),
84+
horizontalStackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing)
85+
])
86+
}
87+
}

solutions/devsprint-vinicius-carvalho-3/DeliveryApp/Screens/Home/HomeView.swift

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,76 @@ final class HomeView: UIView {
1717
private let restaurantCellIdentifier = "RestaurantCellIdentifier"
1818

1919
private var restaurants: [Restaurant] = []
20+
21+
private lazy var addressView: AddressView = {
22+
let addressView = AddressView()
23+
addressView.updateView(with: .init(address: "R. Guiratinga, 500"))
24+
addressView.translatesAutoresizingMaskIntoConstraints = false
25+
return addressView
26+
}()
2027

2128
private lazy var tableView: UITableView = {
22-
2329
let tableView = UITableView(frame: .zero)
2430
tableView.translatesAutoresizingMaskIntoConstraints = false
25-
tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.restaurantCellIdentifier)
31+
tableView.register(UITableViewCell.self, forCellReuseIdentifier: restaurantCellIdentifier)
2632
tableView.dataSource = self
2733
return tableView
2834
}()
2935

30-
init() {
31-
32-
super.init(frame: .zero)
33-
34-
self.setupViews()
35-
}
36-
37-
required init?(coder: NSCoder) {
38-
fatalError("init(coder:) has not been implemented")
36+
convenience init() {
37+
self.init(frame: .zero)
38+
setup()
3939
}
4040

4141
func updateView(with restaurants: [Restaurant]) {
42-
4342
self.restaurants = restaurants
44-
self.tableView.reloadData()
43+
tableView.reloadData()
4544
}
4645
}
4746

48-
private extension HomeView {
49-
50-
func setupViews() {
51-
52-
self.backgroundColor = .white
53-
54-
self.configureSubviews()
55-
self.configureSubviewsConstraints()
47+
extension HomeView: ViewCode {
48+
func setupSubviews() {
49+
addSubview(addressView)
50+
addSubview(tableView)
5651
}
57-
58-
func configureSubviews() {
59-
60-
self.addSubview(self.tableView)
52+
53+
func setupConstraints() {
54+
setupTableViewConstraints()
55+
setupAddressViewConstraints()
6156
}
62-
63-
func configureSubviewsConstraints() {
64-
57+
58+
func setupExtraConfiguration() {
59+
backgroundColor = .white
60+
}
61+
62+
private func setupTableViewConstraints() {
6563
NSLayoutConstraint.activate([
66-
67-
self.tableView.leadingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.leadingAnchor),
68-
self.tableView.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor),
69-
self.tableView.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor),
70-
self.tableView.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor)
64+
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
65+
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
66+
tableView.topAnchor.constraint(equalTo: addressView.bottomAnchor),
67+
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
68+
])
69+
}
70+
71+
private func setupAddressViewConstraints() {
72+
NSLayoutConstraint.activate([
73+
addressView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
74+
addressView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
75+
addressView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
7176
])
7277
}
7378
}
7479

7580
extension HomeView: UITableViewDataSource {
7681

7782
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
78-
79-
return self.restaurants.count
83+
return restaurants.count
8084
}
8185

8286
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
8387

84-
let cell = tableView.dequeueReusableCell(withIdentifier: self.restaurantCellIdentifier)!
85-
cell.textLabel?.text = self.restaurants[indexPath.row].name
88+
let cell = tableView.dequeueReusableCell(withIdentifier: restaurantCellIdentifier)!
89+
cell.textLabel?.text = restaurants[indexPath.row].name
8690
return cell
8791
}
8892
}

0 commit comments

Comments
 (0)