Skip to content

Commit 2100c83

Browse files
committed
Prevents app from crashing when performing updates on UITable/CollectionView that is not in view hierarchy.
1 parent 21f48d7 commit 2100c83

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Sources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ open class RxCollectionViewSectionedAnimatedDataSource<S: AnimatableSectionModel
5757
UIBindingObserver(UIElement: self) { dataSource, newSections in
5858
let oldSections = dataSource.sectionModels
5959
do {
60+
// if view is not in view hierarchy, performing batch updates will crash the app
61+
if collectionView.window == nil {
62+
collectionView.reloadData()
63+
return
64+
}
6065
let differences = try differencesForSectionedView(initialSections: oldSections, finalSections: newSections)
6166

6267
for difference in differences {

Sources/DataSources+Rx/RxTableViewSectionedAnimatedDataSource.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ open class RxTableViewSectionedAnimatedDataSource<S: AnimatableSectionModelType>
3838
}
3939
else {
4040
DispatchQueue.main.async {
41+
// if view is not in view hierarchy, performing batch updates will crash the app
42+
if tableView.window == nil {
43+
tableView.reloadData()
44+
return
45+
}
4146
let oldSections = dataSource.sectionModels
4247
do {
4348
let differences = try differencesForSectionedView(initialSections: oldSections, finalSections: newSections)

0 commit comments

Comments
 (0)