commented code
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
069cc8c06a
commit
6f7a43d15e
@ -7,9 +7,17 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
|
/// This is the Cell used in the EmployeesTableViewController to show
|
||||||
|
/// the properties of an Employee model.
|
||||||
public class EmployeeTableViewCell: UITableViewCell {
|
public class EmployeeTableViewCell: UITableViewCell {
|
||||||
static let identifier = "EmployeeTableViewCell"
|
|
||||||
|
|
||||||
|
/// Used in the TableView registration
|
||||||
|
static let identifier = "EmployeeTableViewCell"
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
|
||||||
|
/// UI Elements
|
||||||
private let photoImageView = UIImageView()
|
private let photoImageView = UIImageView()
|
||||||
private let nameLabel = UILabel()
|
private let nameLabel = UILabel()
|
||||||
private let emailLabel = UILabel()
|
private let emailLabel = UILabel()
|
||||||
@ -19,7 +27,10 @@ public class EmployeeTableViewCell: UITableViewCell {
|
|||||||
private let bioLabel = UILabel()
|
private let bioLabel = UILabel()
|
||||||
private let stackView = UIStackView()
|
private let stackView = UIStackView()
|
||||||
|
|
||||||
private var cancellable: AnyCancellable?
|
/// Used for grabbing the photo
|
||||||
|
private var smallPhotoSubscriber: AnyCancellable?
|
||||||
|
|
||||||
|
// MARK: - Initializer
|
||||||
|
|
||||||
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
||||||
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
||||||
@ -30,6 +41,8 @@ public class EmployeeTableViewCell: UITableViewCell {
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Private Methods
|
||||||
|
|
||||||
private func setupUI() {
|
private func setupUI() {
|
||||||
// Configure photoImageView
|
// Configure photoImageView
|
||||||
photoImageView.contentMode = .scaleAspectFill
|
photoImageView.contentMode = .scaleAspectFill
|
||||||
@ -93,9 +106,13 @@ public class EmployeeTableViewCell: UITableViewCell {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Public Methods
|
||||||
|
|
||||||
|
|
||||||
|
/// Override for setting back to a default state
|
||||||
public override func prepareForReuse() {
|
public override func prepareForReuse() {
|
||||||
super.prepareForReuse()
|
super.prepareForReuse()
|
||||||
cancellable = nil
|
smallPhotoSubscriber = nil
|
||||||
photoImageView.image = UIImage(systemName: "person.crop.circle")
|
photoImageView.image = UIImage(systemName: "person.crop.circle")
|
||||||
nameLabel.text = nil
|
nameLabel.text = nil
|
||||||
emailLabel.text = nil
|
emailLabel.text = nil
|
||||||
@ -105,10 +122,12 @@ public class EmployeeTableViewCell: UITableViewCell {
|
|||||||
bioLabel.text = nil
|
bioLabel.text = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configures the UI Elements with the properties of the EmployeeCellViewModel.
|
||||||
|
/// - Parameter viewModel: Employee Model wrapped for Cell.
|
||||||
public func configure(with viewModel: EmployeeCellViewModel) {
|
public func configure(with viewModel: EmployeeCellViewModel) {
|
||||||
|
|
||||||
// Bind the image to the photoImageView
|
// Bind the image to the photoImageView
|
||||||
cancellable = viewModel.$smallPhoto
|
smallPhotoSubscriber = viewModel.$smallPhoto
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] image in
|
.sink { [weak self] image in
|
||||||
self?.photoImageView.image = image
|
self?.photoImageView.image = image
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user