Skip to content

Commit

Permalink
GH-20 Empty state improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ivancr committed Oct 2, 2018
1 parent bd50214 commit 567c2d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
26 changes: 14 additions & 12 deletions TodoList/View Controllers/TodoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,37 @@ final class TodoTableViewController: UITableViewController {

// MARK: - Helpers
private func setupUI() {

tableView.register(cellType: ItemTableViewCell.self)
tableView.keyboardDismissMode = .interactive
}

private func setState(isEmpty: Bool) {
tableView.backgroundView = isEmpty ? emptyView : nil
UIView.animate(withDuration: 0.3) {
self.tableView.backgroundView = isEmpty ? self.emptyView : nil
}
}

private func completedDate(from item: Item) -> String? {

if let completionDate = item.completionDate {
return dateFormatter.string(from: completionDate)
}
return nil
}

// MARK: - TableView dataSource Delegate
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
UIView.animate(withDuration: 0.3) {
self.setState(isEmpty: self.dataSource.isEmpty)
}

setState(isEmpty: self.dataSource.isEmpty)
return dataSource.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: ItemTableViewCell = tableView.dequeueReusableCell(for: indexPath)

let cell: ItemTableViewCell = tableView.dequeueReusableCell(for: indexPath)
let item = dataSource[indexPath.row]
var date: String?
if let completionDate = item.completionDate {
date = dateFormatter.string(from: completionDate)
}

cell.set(title: item.title,
subtitle: date,
subtitle: completedDate(from: item),
isCompleted: item.isComplete)

return cell
Expand Down
4 changes: 3 additions & 1 deletion TodoList/Views/EmptyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ final class EmptyView: UIView {
label.text = NSLocalizedString("It's all a big black nothing", comment: "")
label.font = UIFont.preferredFont(forTextStyle: .largeTitle)
label.textColor = .black
label.numberOfLines = 0
label.adjustsFontForContentSizeCategory = true
label.textAlignment = .center
}
}

@IBOutlet var iconImage: UIImageView!


override func awakeFromNib() {
super.awakeFromNib()

Expand Down
2 changes: 2 additions & 0 deletions TodoList/Views/EmptyView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="Sy5-Ny-CkD" secondAttribute="trailing" constant="16" id="ENr-4a-vLR"/>
<constraint firstItem="Sy5-Ny-CkD" firstAttribute="centerY" secondItem="vUN-kp-3ea" secondAttribute="centerY" id="FkQ-7X-U2O"/>
<constraint firstItem="Sy5-Ny-CkD" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="vUN-kp-3ea" secondAttribute="leading" constant="16" id="YlT-92-YoY"/>
<constraint firstItem="Sy5-Ny-CkD" firstAttribute="centerX" secondItem="vUN-kp-3ea" secondAttribute="centerX" id="uU0-uH-LiR"/>
</constraints>
<nil key="simulatedTopBarMetrics"/>
Expand Down

0 comments on commit 567c2d9

Please sign in to comment.