Skip to content

Commit f33f965

Browse files
Update BBTableView reloadRows
1 parent 4f4df2b commit f33f965

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

BBSwiftUIKit/BBSwiftUIKit/BBTableView.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public extension BBTableView {
1919
return view
2020
}
2121

22-
func bb_reloadRows(_ reloadRows: Binding<[Int]>) -> Self {
22+
func bb_reloadRows(_ rows: Binding<[Int]>, animation: UITableView.RowAnimation) -> Self {
2323
var view = self
24-
view._reloadRows = reloadRows
24+
view._reloadRows = rows
25+
view.reloadRowsAnimation = animation
2526
return view
2627
}
2728

@@ -83,7 +84,9 @@ public struct BBTableView<Data, Content>: UIViewControllerRepresentable, BBUIScr
8384
let content: (Data.Element) -> Content
8485

8586
@Binding public var reloadData: Bool
87+
8688
@Binding public var reloadRows: [Int]
89+
public var reloadRowsAnimation: UITableView.RowAnimation = .automatic
8790

8891
@Binding public var scrollToRow: Int?
8992
public var scrollToRowPosition: UITableView.ScrollPosition = .none
@@ -204,7 +207,7 @@ private class _BBTableViewController<Data, Content>: UIViewController, UITableVi
204207
}
205208

206209
if !representable.reloadRows.isEmpty {
207-
tableView.reloadRows(at: representable.reloadRows.map { IndexPath(row: $0, section: 0) }, with: .automatic)
210+
tableView.reloadRows(at: representable.reloadRows.map { IndexPath(row: $0, section: 0) }, with: representable.reloadRowsAnimation)
208211

209212
DispatchQueue.main.async { [weak self] in
210213
guard let self = self else { return }

BBSwiftUIKitDemo/BBSwiftUIKitDemo/TableViewExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct TableViewExample: View {
3838
}
3939
}
4040
.bb_reloadData($reloadData)
41-
.bb_reloadRows($reloadRows)
41+
.bb_reloadRows($reloadRows, animation: .automatic)
4242
.bb_scrollToRow($scrollToRow, position: .none, animated: true)
4343
.bb_contentOffset($contentOffset)
4444
.bb_contentOffsetToScrollAnimated($contentOffsetToScrollAnimated)

0 commit comments

Comments
 (0)