Skip to content

Commit f82f3d8

Browse files
Using the safer performBatchUpdates(_:changes:completion:) function.
1 parent d21666e commit f82f3d8

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

ListableUI/Sources/ListView/ListView.CollectionViewChanges.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,12 @@ internal extension ListView
8686
self.movedItems += $0.itemChanges.moved
8787
}
8888
}
89+
90+
private init() {}
91+
92+
/// Returns an instance of `CollectionViewChanges` containing no changes.
93+
static var empty: CollectionViewChanges {
94+
CollectionViewChanges()
95+
}
8996
}
9097
}

ListableUI/Sources/ListView/ListView.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ public final class ListView : UIView
13031303
/// asynchronously update the underlying `contentSize` as part of the initial layout,
13041304
/// moments after this method is executed. The list's `contentSize` is overridden to
13051305
/// keep the offset anchored to the bottom when using `VerticalLayoutGravity.bottom`.
1306-
collectionView.performBatchUpdates(nil)
1306+
performEmptyBatchUpdates()
13071307
}
13081308

13091309
guard self.scrollTo(item: destination, position: info.position, animated: animated) else { return }
@@ -1316,7 +1316,7 @@ public final class ListView : UIView
13161316
/// `prepare()` function will synchronously execute before calling `didPerform`. Otherwise,
13171317
/// the list's `visibleContent` and the resulting `scrollPositionInfo.visibleItems` will
13181318
/// be stale.
1319-
collectionView.performBatchUpdates(nil)
1319+
performEmptyBatchUpdates()
13201320
info.didPerform(scrollPositionInfo)
13211321
}
13221322
}
@@ -1409,6 +1409,16 @@ public final class ListView : UIView
14091409
return true
14101410
}
14111411

1412+
/// This is similar to calling `collectionView.performBatchUpdates(nil)`, but
1413+
/// it also includes workarounds for first responder bugs on iOS 16.4 and 17.0.
1414+
private func performEmptyBatchUpdates() {
1415+
collectionView.performBatchUpdates(
1416+
{},
1417+
changes: CollectionViewChanges.empty,
1418+
completion: { _ in }
1419+
)
1420+
}
1421+
14121422
private func performBatchUpdates(
14131423
with diff : SectionedDiff<Section, AnyIdentifier, AnyItem, AnyIdentifier>,
14141424
animated: Bool,

0 commit comments

Comments
 (0)