Conversation
This allows for mutating `self.data` without redrawing the entire table view for example, and is a working point to being able to mutate `data` and only reload certain rows
| public func replace<T: Row & Equatable>(row: T, with otherRow: Row, reloading additionalReloadIndexPaths: [IndexPath] = [], animation: UITableView.RowAnimation = .none) { | ||
|
|
||
| guard let indexPath = indexPathFor(row: row) else { return } | ||
| guard let tableSection = data[indexPath.section] as? TableSection else { return } |
There was a problem hiding this comment.
Is TableSection required? Or just Section
There was a problem hiding this comment.
TableSection currently... I didn't want to make changes to Section to require rows to be { get set }, but may be okay to do so now?
| /// - otherRow: The row that is replacing the original row. | ||
| /// - additionalReloadIndexPaths: Additional index paths that should be reloaded at the same time. | ||
| /// - animation: The animation to use when reloading the rows | ||
| public func replace<T: Row & Equatable>(row: T, with otherRow: Row, reloading additionalReloadIndexPaths: [IndexPath] = [], animation: UITableView.RowAnimation = .none) { |
There was a problem hiding this comment.
Could do fancy setters on subscripts here! But let's leave that for now 😄. Bit OTT
| } | ||
|
|
||
| var indexPaths = [indexPath] | ||
| indexPaths.append(contentsOf: additionalReloadIndexPaths) |
There was a problem hiding this comment.
Happy to leave, but user's could wrap additionalReloadIndexPaths logic into a tableView.beginUpdates() so it doesn't need to go via this method. But let's leave for now
| /// A function which allows for mutation of `data` without causing the tableView to reload. | ||
| /// | ||
| /// - Parameter closure: Code to be run without reloading the table view. | ||
| public func withoutRedrawing(_ closure: () -> Void) { |
There was a problem hiding this comment.
executeWithoutReloadingData ? Happy to leave
| /// The last available indexPath in the tableView | ||
| public var lastIndexPath: IndexPath? { | ||
| guard let lastSection = data.last(where: { !$0.rows.isEmpty }) else { return nil } | ||
| return IndexPath(row: lastSection.rows.count - 1, section: data.count - 1) |
There was a problem hiding this comment.
If there's rows.isEmpty then data.count-1 wouldn't be the correct section
There was a problem hiding this comment.
Ooooh yikes yep this needs more consideration!
| public func redraw<T: Row & Equatable>(row: T, with animation: UITableView.RowAnimation = .none) { | ||
|
|
||
| guard let indexPath = indexPathFor(row: row) else { return } | ||
| tableView.reloadRows(at: [indexPath], with: animation) |
There was a problem hiding this comment.
If we are using animation shouldn't we wrap in a tableView.beginUpdates - tableView.endUpdates? May be wrong there
| /// - otherRow: The row that is replacing the original row. | ||
| /// - additionalReloadIndexPaths: Additional index paths that should be reloaded at the same time. | ||
| /// - animation: The animation to use when reloading the rows | ||
| public func replace<T: Row & Equatable>(row: T, with otherRow: Row, reloading additionalReloadIndexPaths: [IndexPath] = [], animation: UITableView.RowAnimation = .none) { |
There was a problem hiding this comment.
Would be nice to reuse the array option below if we can, save code duplication - happy to leave ofc
|
|
||
| replacement.forEach { (index, indexPath) in | ||
|
|
||
| guard let tableSection = data[indexPath.section] as? TableSection else { return } |
There was a problem hiding this comment.
Again do we need TableSection ?
Adds ability to perform partial reloading and comparison of rows within
data