Skip to content

Commit

Permalink
UIKitExtension: add completion callback for reload
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSB committed Dec 1, 2020
1 parent f8c8d1e commit 0f2256a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/Extensions/UIKitExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public extension UITableView {
using stagedChangeset: StagedChangeset<C>,
with animation: @autoclosure () -> RowAnimation,
interrupt: ((Changeset<C>) -> Bool)? = nil,
setData: (C) -> Void
setData: (C) -> Void,
completion: ((Bool) -> Void)? = nil
) {
reload(
using: stagedChangeset,
Expand All @@ -30,7 +31,8 @@ public extension UITableView {
insertRowsAnimation: animation(),
reloadRowsAnimation: animation(),
interrupt: interrupt,
setData: setData
setData: setData,
completion: completion
)
}

Expand Down Expand Up @@ -61,7 +63,8 @@ public extension UITableView {
insertRowsAnimation: @autoclosure () -> RowAnimation,
reloadRowsAnimation: @autoclosure () -> RowAnimation,
interrupt: ((Changeset<C>) -> Bool)? = nil,
setData: (C) -> Void
setData: (C) -> Void,
completion: ((Bool) -> Void)? = nil
) {
if case .none = window, let data = stagedChangeset.last?.data {
setData(data)
Expand Down Expand Up @@ -112,14 +115,15 @@ public extension UITableView {
}
}

private func _performBatchUpdates(_ updates: () -> Void) {
private func _performBatchUpdates(_ updates: () -> Void, completion: ((Bool) -> Void)? = nil) {
if #available(iOS 11.0, tvOS 11.0, *) {
performBatchUpdates(updates)
performBatchUpdates(updates, completion: completion)
}
else {
beginUpdates()
updates()
endUpdates()
completion(true)
}
}
}
Expand Down

0 comments on commit 0f2256a

Please sign in to comment.