-
Notifications
You must be signed in to change notification settings - Fork 43
Created the ActivityDetailsView screen #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
24ba059
7d252ad
3c3f397
f67fa1a
94ff6c1
c6a6e0e
c61d9bd
7637e58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// BaseViewHierarchy.swift | ||
// FinanceApp | ||
// | ||
// Created by Kleiton Mendes on 12/12/22. | ||
// | ||
|
||
import UIKit | ||
|
||
struct BaseViewHierarchy { | ||
let parentView: UIView | ||
let subViews: [UIView] | ||
|
||
init(parentView: UIView, subViews: [UIView]) { | ||
self.parentView = parentView | ||
self.subViews = subViews | ||
} | ||
|
||
func makeHierarchy() { | ||
if let stackView = parentView as? UIStackView { | ||
for view in subViews { | ||
stackView.addArrangedSubview(view) | ||
} | ||
} else { | ||
for view in subViews { | ||
parentView.addSubview(view) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "mall.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,135 @@ | ||
// | ||
// ActivityDetailsView.swift | ||
// FinanceApp | ||
// | ||
// Created by Rodrigo Borges on 30/12/21. | ||
// | ||
|
||
import UIKit | ||
|
||
class ActivityDetailsView: UIView { | ||
|
||
final class ActivityDetailsView: BaseView { | ||
|
||
// MARK: - Private Properties UI | ||
|
||
private lazy var mainStack: UIStackView = { | ||
let stack = UIStackView() | ||
stack.axis = .vertical | ||
stack.distribution = .fillEqually | ||
stack.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return stack | ||
}() | ||
|
||
private lazy var productView: UIView = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dá pra resumir com uma inicialização simples |
||
let view = UIView() | ||
|
||
return view | ||
}() | ||
|
||
private lazy var productValueView: UIView = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mesma coisa |
||
let view = UIView() | ||
|
||
return view | ||
}() | ||
|
||
private lazy var productImage: UIImageView = { | ||
let imageView = UIImageView() | ||
imageView.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return imageView | ||
}() | ||
|
||
private lazy var productNameLabel: UILabel = { | ||
let label = UILabel() | ||
label.textAlignment = .center | ||
label.font = UIFont.boldSystemFont(ofSize: 17) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dá pra salvar o tamanho da fonte numa constante There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outra coisa: Se a label comportar conteúdo grande, bom setar o número de linhas como zero. |
||
label.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return label | ||
}() | ||
|
||
private lazy var categoryNameLabel: UILabel = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mesma coisa aqui |
||
let label = UILabel() | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return label | ||
}() | ||
|
||
private lazy var productValue: UILabel = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renomear pra |
||
let label = UILabel() | ||
label.font = UIFont.boldSystemFont(ofSize: 34) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Salvar em constantes |
||
label.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return label | ||
}() | ||
|
||
private lazy var purchaseTime: UILabel = { | ||
let label = UILabel() | ||
label.textAlignment = .center | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return label | ||
}() | ||
|
||
private lazy var reportButton: UIButton = { | ||
let button = UIButton() | ||
button.layer.cornerRadius = 14 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Salvar em |
||
button.backgroundColor = .systemBlue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acho que seria bom usar a classe de botão que o Thyago criou. |
||
button.setTitle("Report a issue", for: .normal) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Salvar a string numa constante |
||
button.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
return button | ||
}() | ||
|
||
override var hierarchies: [BaseViewHierarchy] { | ||
return [BaseViewHierarchy.init(parentView: self, subViews: [mainStack, reportButton]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OBS: Não precisa do |
||
BaseViewHierarchy.init(parentView: mainStack, subViews: [productView, productValueView]), | ||
BaseViewHierarchy.init(parentView: productView, subViews: [productImage, productNameLabel,categoryNameLabel]), | ||
BaseViewHierarchy.init(parentView: productValueView, subViews: [productValue, purchaseTime])] | ||
} | ||
|
||
override var constraints: [NSLayoutConstraint] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Salvar as constantes das constraints em There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pular linha e deixar um comentário pra cada componente que adiciona constraints. |
||
[ | ||
mainStack.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor), | ||
mainStack.leadingAnchor.constraint(equalTo: leadingAnchor), | ||
mainStack.trailingAnchor.constraint(equalTo: trailingAnchor), | ||
mainStack.bottomAnchor.constraint(equalTo: reportButton.topAnchor, constant: -50), | ||
|
||
productImage.centerXAnchor.constraint(equalTo: centerXAnchor), | ||
|
||
productNameLabel.centerXAnchor.constraint(equalTo: centerXAnchor), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sempre é bom colocar além do centro da label os limites. |
||
productNameLabel.topAnchor.constraint(equalTo: productImage.bottomAnchor, constant: 8), | ||
|
||
categoryNameLabel.centerXAnchor.constraint(equalTo: centerXAnchor), | ||
categoryNameLabel.topAnchor.constraint(equalTo: productNameLabel.bottomAnchor, constant: 8), | ||
|
||
productValue.centerXAnchor.constraint(equalTo: centerXAnchor), | ||
purchaseTime.centerXAnchor.constraint(equalTo: centerXAnchor), | ||
purchaseTime.topAnchor.constraint(equalTo: productValue.bottomAnchor, constant: 8), | ||
|
||
reportButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20), | ||
reportButton.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -15), | ||
reportButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20), | ||
reportButton.heightAnchor.constraint(equalToConstant: 56) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O botão poderia ter um |
||
] | ||
} | ||
|
||
private let viewModel: ActivityDetailsViewModel | ||
|
||
// MARK: - Init | ||
|
||
init(viewModel: ActivityDetailsViewModel) { | ||
self.viewModel = viewModel | ||
super.init(frame: .zero) | ||
setupExtra() | ||
} | ||
|
||
@available(*, unavailable) | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Private Methods | ||
|
||
private func setupExtra() { | ||
backgroundColor = .systemBackground | ||
productImage.image = viewModel.image | ||
productNameLabel.text = viewModel.name | ||
categoryNameLabel.text = viewModel.category | ||
productValue.text = viewModel.value | ||
purchaseTime.text = viewModel.purchaseTime | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
// | ||
// ActivityDetailsViewController.swift | ||
// FinanceApp | ||
// | ||
// Created by Rodrigo Borges on 30/12/21. | ||
// | ||
|
||
import UIKit | ||
|
||
class ActivityDetailsViewController: UIViewController { | ||
final class ActivityDetailsViewController: UIViewController { | ||
|
||
// MARK: - Life Cycle | ||
|
||
override func loadView() { | ||
self.view = ActivityDetailsView() | ||
view = ActivityDetailsView(viewModel: ActivityDetailsViewModel(image: UIImage(named: "mall"), | ||
name: "Mall", | ||
category: "Shopping", | ||
value: "$1000.0", | ||
purchaseTime: "8:40")) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import UIKit | ||
|
||
struct ActivityDetailsViewModel { | ||
let image: UIImage? | ||
let name: String | ||
let category: String | ||
let value: String | ||
let purchaseTime: String | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// BaseView.swift | ||
// FinanceApp | ||
// | ||
// Created by Kleiton Mendes on 12/12/22. | ||
// | ||
|
||
import UIKit | ||
|
||
class BaseView: UIView { | ||
open var hierarchies: [BaseViewHierarchy] { [] } | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setupView() | ||
setupConstraints() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setupConstraints() { | ||
NSLayoutConstraint.activate(constraints) | ||
} | ||
|
||
private func setupView() { | ||
for relation in hierarchies { | ||
relation.makeHierarchy() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aqui dá pra remover já que os componentes tem
instrinsicContentSize