@@ -111,6 +111,7 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
111
111
// MARK: Private tracking variables
112
112
113
113
private var hasDoneInitialSetup = false
114
+ private var shouldAnimateScrollPositionSet = false
114
115
115
116
typealias Cell = ASTableViewCell
116
117
@@ -146,8 +147,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
146
147
assignIfChanged ( tableView, \. showsVerticalScrollIndicator, newValue: parent. scrollIndicatorEnabled)
147
148
assignIfChanged ( tableView, \. showsHorizontalScrollIndicator, newValue: parent. scrollIndicatorEnabled)
148
149
assignIfChanged ( tableView, \. keyboardDismissMode, newValue: . interactive)
149
-
150
- updateTableViewContentInsets ( tableView)
150
+
151
+ updateTableViewContentInsets ( tableView)
151
152
152
153
assignIfChanged ( tableView, \. allowsSelection, newValue: true )
153
154
assignIfChanged ( tableView, \. allowsMultipleSelectionDuringEditing, newValue: true )
@@ -203,7 +204,6 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
203
204
cell. isSelected = self . isIndexPathSelected ( indexPath)
204
205
205
206
cell. setContent ( itemID: itemID, content: section. dataSource. content ( forItemID: itemID, isSelected: cell. isSelected, isHighlighted: cell. isHighlighted) )
206
- // cell.skipNextRefresh = true // Avoid setting this again when we refresh old cells in a moment
207
207
208
208
cell. disableSwiftUIDropInteraction = section. dataSource. dropEnabled
209
209
cell. disableSwiftUIDragInteraction = section. dataSource. dragEnabled
@@ -251,6 +251,7 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
251
251
)
252
252
253
253
dataSource? . applySnapshot ( snapshot, animated: animated)
254
+ shouldAnimateScrollPositionSet = animated
254
255
255
256
tableViewController. map { updateSelectionBindings ( $0. tableView) }
256
257
refreshVisibleCells ( transaction: transaction, updateAll: false )
@@ -306,27 +307,28 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
306
307
{
307
308
tableViewController? . tableView. scrollToRow ( at: indexPath, at: position, animated: true )
308
309
}
309
-
310
- func applyScrollPosition( animated: Bool ) {
311
- if let scrollPositionToSet = self . parent. scrollPositionSetter? . wrappedValue
312
- {
313
- switch scrollPositionToSet
314
- {
315
- case let . indexPath( indexPath) :
316
- self . tableViewController? . tableView. scrollToRow ( at: indexPath, at: . none, animated: animated)
317
- case . top:
318
- let contentInsets = self . tableViewController? . tableView. contentInset ?? . zero
319
- self . tableViewController? . tableView. setContentOffset ( CGPoint ( x: 0 , y: contentInsets. top) , animated: animated)
320
- case . bottom:
321
- let contentSize = self . tableViewController? . tableView. contentSizePlusInsets ?? . zero
322
- let visibleHeight = self . tableViewController? . tableView. frame. height ?? . zero
323
- self . tableViewController? . tableView. setContentOffset ( CGPoint ( x: 0 , y: contentSize. height - visibleHeight) , animated: animated)
324
- }
325
- DispatchQueue . main. async {
326
- self . parent. scrollPositionSetter? . wrappedValue = nil
327
- }
328
- }
329
- }
310
+
311
+ func applyScrollPosition( animated: Bool )
312
+ {
313
+ if let scrollPositionToSet = parent. scrollPositionSetter? . wrappedValue
314
+ {
315
+ switch scrollPositionToSet
316
+ {
317
+ case let . indexPath( indexPath) :
318
+ tableViewController? . tableView. scrollToRow ( at: indexPath, at: . none, animated: animated)
319
+ case . top:
320
+ let contentInsets = tableViewController? . tableView. contentInset ?? . zero
321
+ tableViewController? . tableView. setContentOffset ( CGPoint ( x: 0 , y: contentInsets. top) , animated: animated)
322
+ case . bottom:
323
+ let contentSize = tableViewController? . tableView. contentSizePlusInsets ?? . zero
324
+ let visibleHeight = tableViewController? . tableView. frame. height ?? . zero
325
+ tableViewController? . tableView. setContentOffset ( CGPoint ( x: 0 , y: contentSize. height - visibleHeight) , animated: animated)
326
+ }
327
+ DispatchQueue . main. async {
328
+ self . parent. scrollPositionSetter? . wrappedValue = nil
329
+ }
330
+ }
331
+ }
330
332
331
333
func onMoveToParent( )
332
334
{
@@ -355,9 +357,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
355
357
DispatchQueue . main. async {
356
358
self . parent. invalidateParentCellLayout ? ( !firstSize)
357
359
}
358
-
359
- applyScrollPosition ( animated: false )
360
- #warning("TODO: get animation state")
360
+
361
+ applyScrollPosition ( animated: shouldAnimateScrollPositionSet)
361
362
}
362
363
363
364
func configureRefreshControl( for tv: UITableView )
@@ -399,24 +400,16 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
399
400
}
400
401
401
402
public func tableView( _ tableView: UITableView , willDisplayHeaderView view: UIView , forSection section: Int )
402
- {
403
- // guard let view = (view as? ASTableViewSupplementaryView) else { return }
404
- }
403
+ { }
405
404
406
405
public func tableView( _ tableView: UITableView , didEndDisplayingHeaderView view: UIView , forSection section: Int )
407
- {
408
- // guard let view = (view as? ASTableViewSupplementaryView) else { return }
409
- }
406
+ { }
410
407
411
408
public func tableView( _ tableView: UITableView , willDisplayFooterView view: UIView , forSection section: Int )
412
- {
413
- // guard let view = (view as? ASTableViewSupplementaryView) else { return }
414
- }
409
+ { }
415
410
416
411
public func tableView( _ tableView: UITableView , didEndDisplayingFooterView view: UIView , forSection section: Int )
417
- {
418
- // guard let view = (view as? ASTableViewSupplementaryView) else { return }
419
- }
412
+ { }
420
413
421
414
public func tableView( _ tableView: UITableView , prefetchRowsAt indexPaths: [ IndexPath ] )
422
415
{
0 commit comments