Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

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 @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1E2324E328871F2F00414138 /* ViewCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2324E228871F2F00414138 /* ViewCode.swift */; };
1E2324E5288720CA00414138 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E2324E4288720CA00414138 /* LoadingView.swift */; };
1EAC8D92288A22E900A37973 /* AddressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EAC8D91288A22E900A37973 /* AddressView.swift */; };
8B113973288865DE00A42625 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8B113972288865DE00A42625 /* EmptyView.swift */; };
98228D7D27BC489F006A38BB /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98228D7C27BC489F006A38BB /* Address.swift */; };
98228D7F27BC490E006A38BB /* RestaurantDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98228D7E27BC490E006A38BB /* RestaurantDetails.swift */; };
Expand Down Expand Up @@ -49,6 +50,7 @@
/* Begin PBXFileReference section */
1E2324E228871F2F00414138 /* ViewCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewCode.swift; sourceTree = "<group>"; };
1E2324E4288720CA00414138 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
1EAC8D91288A22E900A37973 /* AddressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressView.swift; sourceTree = "<group>"; };
8B113972288865DE00A42625 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = "<group>"; };
98228D7C27BC489F006A38BB /* Address.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = "<group>"; };
98228D7E27BC490E006A38BB /* RestaurantDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestaurantDetails.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -254,6 +256,7 @@
children = (
98C4368027ADADC000D9048A /* SampleComponentView.swift */,
1E2324E4288720CA00414138 /* LoadingView.swift */,
1EAC8D91288A22E900A37973 /* AddressView.swift */,
8B113972288865DE00A42625 /* EmptyView.swift */,
);
path = Components;
Expand Down Expand Up @@ -383,6 +386,7 @@
98AF572427ADB16E00339A66 /* SampleComponentView.swift in Sources */,
8B113973288865DE00A42625 /* EmptyView.swift in Sources */,
98AF572527ADB16E00339A66 /* HomeViewController.swift in Sources */,
1EAC8D92288A22E900A37973 /* AddressView.swift in Sources */,
98AF572627ADB16E00339A66 /* HomeView.swift in Sources */,
98AF572727ADB16E00339A66 /* AddressSearchViewController.swift in Sources */,
98AF572827ADB16E00339A66 /* AddressListView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// AddressView.swift
// DeliveryApp
//
// Created by Vitor Conceicao on 21/07/22.
//

import UIKit

final class AddressView: UIView {
private lazy var addressLabel: UILabel = {
let addressLabel = UILabel()
addressLabel.font = .boldSystemFont(ofSize: 15)
return addressLabel
}()

private lazy var editButton: UIButton = {
let buttonVerticalPadding: CGFloat = 10.0
let buttonHorizontalPadding: CGFloat = 16.0

let editButton = UIButton(configuration: .plain())
editButton.configuration?.subtitle = "Editar"
editButton.configuration?.background.strokeColor = .systemBlue
editButton.configuration?.background.strokeWidth = 2.0
editButton.configuration?.cornerStyle = .large
editButton.configuration?.contentInsets = NSDirectionalEdgeInsets(top: buttonVerticalPadding,
leading: buttonHorizontalPadding,
bottom: buttonVerticalPadding,
trailing: buttonHorizontalPadding)
editButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
return editButton
}()

private lazy var horizontalStackView: UIStackView = {
let horizontalStackView = UIStackView()
horizontalStackView.axis = .horizontal
horizontalStackView.spacing = spacing
horizontalStackView.distribution = .fill
horizontalStackView.alignment = .center
horizontalStackView.translatesAutoresizingMaskIntoConstraints = false
return horizontalStackView
}()

// MARK: private properties

private let spacing: CGFloat = 16.0

// MARK: inits

convenience init() {
self.init(frame: .zero)
setup()
}

// MARK: configuration

struct AddressViewConfiguration {
let address: String
}

// MARK: methods

func updateView(with configuration: AddressViewConfiguration) {
addressLabel.text = configuration.address
}
}

extension AddressView: ViewCode {
func setupSubviews() {
horizontalStackView.addArrangedSubview(addressLabel)
horizontalStackView.addArrangedSubview(editButton)

addSubview(horizontalStackView)
}

func setupConstraints() {
setupHorizontalStackViewConstraints()
}

private func setupHorizontalStackViewConstraints() {
NSLayoutConstraint.activate([
horizontalStackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: spacing),
horizontalStackView.topAnchor.constraint(equalTo: topAnchor, constant: spacing),
horizontalStackView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -spacing)
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,72 +17,76 @@ final class HomeView: UIView {
private let restaurantCellIdentifier = "RestaurantCellIdentifier"

private var restaurants: [Restaurant] = []

private lazy var addressView: AddressView = {
let addressView = AddressView()
addressView.updateView(with: .init(address: "R. Guiratinga, 500"))
addressView.translatesAutoresizingMaskIntoConstraints = false
return addressView
}()

private lazy var tableView: UITableView = {

let tableView = UITableView(frame: .zero)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(UITableViewCell.self, forCellReuseIdentifier: self.restaurantCellIdentifier)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: restaurantCellIdentifier)
tableView.dataSource = self
return tableView
}()

init() {

super.init(frame: .zero)

self.setupViews()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
convenience init() {
self.init(frame: .zero)
setup()
}

func updateView(with restaurants: [Restaurant]) {

self.restaurants = restaurants
self.tableView.reloadData()
tableView.reloadData()
}
}

private extension HomeView {

func setupViews() {

self.backgroundColor = .white

self.configureSubviews()
self.configureSubviewsConstraints()
extension HomeView: ViewCode {
func setupSubviews() {
addSubview(addressView)
addSubview(tableView)
}

func configureSubviews() {

self.addSubview(self.tableView)
func setupConstraints() {
setupTableViewConstraints()
setupAddressViewConstraints()
}

func configureSubviewsConstraints() {


func setupExtraConfiguration() {
backgroundColor = .white
}

private func setupTableViewConstraints() {
NSLayoutConstraint.activate([

self.tableView.leadingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.leadingAnchor),
self.tableView.trailingAnchor.constraint(equalTo: self.safeAreaLayoutGuide.trailingAnchor),
self.tableView.topAnchor.constraint(equalTo: self.safeAreaLayoutGuide.topAnchor),
self.tableView.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor)
tableView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
tableView.topAnchor.constraint(equalTo: addressView.bottomAnchor),
tableView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
])
}

private func setupAddressViewConstraints() {
NSLayoutConstraint.activate([
addressView.leadingAnchor.constraint(equalTo: safeAreaLayoutGuide.leadingAnchor),
addressView.trailingAnchor.constraint(equalTo: safeAreaLayoutGuide.trailingAnchor),
addressView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
])
}
}

extension HomeView: UITableViewDataSource {

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return self.restaurants.count
return restaurants.count
}

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

let cell = tableView.dequeueReusableCell(withIdentifier: self.restaurantCellIdentifier)!
cell.textLabel?.text = self.restaurants[indexPath.row].name
let cell = tableView.dequeueReusableCell(withIdentifier: restaurantCellIdentifier)!
cell.textLabel?.text = restaurants[indexPath.row].name
return cell
}
}
Expand Down