updated animation
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
6280aa42cb
commit
fa5f782968
@ -109,9 +109,14 @@ class EmployeesViewController: UIViewController {
|
||||
private func bindViewModel() {
|
||||
viewModel.$employees
|
||||
.receive(on: RunLoop.main)
|
||||
.sink { [weak self] _ in
|
||||
self?.updateFooter()
|
||||
self?.tableView.reloadData()
|
||||
.sink { [weak self] newEmployees in
|
||||
guard let self = self else { return }
|
||||
|
||||
let oldEmployees = self.viewModel.oldEmployees // Keep track of the previous state
|
||||
self.animateEmployeeChanges(from: oldEmployees, to: newEmployees)
|
||||
|
||||
// Update footer and other UI elements as needed
|
||||
self.updateFooter()
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@ -135,6 +140,26 @@ class EmployeesViewController: UIViewController {
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func animateEmployeeChanges(from oldEmployees: [Employee], to newEmployees: [Employee]) {
|
||||
let oldCount = oldEmployees.count
|
||||
let newCount = newEmployees.count
|
||||
|
||||
// Case: Removing all employees
|
||||
if oldCount > 0 && newCount == 0 {
|
||||
let indexPaths = (0..<oldCount).map { IndexPath(row: $0, section: 0) }
|
||||
tableView.performBatchUpdates {
|
||||
tableView.deleteRows(at: indexPaths, with: .fade)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Case: Resetting with new data (or switching modes)
|
||||
if newCount > 0 {
|
||||
tableView.reloadData()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/// Show state in specific use-cases for the EmployeesViewModel
|
||||
private func updateFooter() {
|
||||
var footerMessage: String?
|
||||
|
||||
Loading…
Reference in New Issue
Block a user