Compare commits

...

2 Commits

Author SHA1 Message Date
Shadowfacts 60c88ded5e Require iOS 15 for Disable Infinite Scrolling 2021-06-27 17:17:39 -04:00
Shadowfacts 1e7a6af0bf Fix TimelineTableVC item hash including status state
Fixes crash when refreshing on iOS 14
2021-06-27 15:52:22 -04:00
2 changed files with 29 additions and 5 deletions

View File

@ -16,8 +16,10 @@ struct WellnessPrefsView: View {
showFavAndReblogCount showFavAndReblogCount
notificationsMode notificationsMode
grayscaleImages grayscaleImages
if #available(iOS 15.0, *) {
disableInfiniteScrolling disableInfiniteScrolling
} }
}
.listStyle(InsetGroupedListStyle()) .listStyle(InsetGroupedListStyle())
.navigationBarTitle(Text("Digital Wellness")) .navigationBarTitle(Text("Digital Wellness"))
} }

View File

@ -123,7 +123,8 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
return return
} }
guard !Preferences.shared.disableInfiniteScrolling || didConfirmLoadMore else { if #available(iOS 15.0, *),
Preferences.shared.disableInfiniteScrolling && !didConfirmLoadMore {
guard !currentSnapshot.itemIdentifiers(inSection: .footer).contains(.confirmLoadMore) else { guard !currentSnapshot.itemIdentifiers(inSection: .footer).contains(.confirmLoadMore) else {
// todo: need something more accurate than "success"/"failure" // todo: need something more accurate than "success"/"failure"
completion(.success(currentSnapshot)) completion(.success(currentSnapshot))
@ -177,11 +178,11 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
self.mastodonController.persistentContainer.addAll(statuses: statuses) { self.mastodonController.persistentContainer.addAll(statuses: statuses) {
var snapshot = currentSnapshot var snapshot = currentSnapshot
let identifiers = statuses.map { Item.status(id: $0.id, state: .unknown) } let newIdentifiers = statuses.map { Item.status(id: $0.id, state: .unknown) }
if let first = snapshot.itemIdentifiers(inSection: .statuses).first { if let first = snapshot.itemIdentifiers(inSection: .statuses).first {
snapshot.insertItems(identifiers, beforeItem: first) snapshot.insertItems(newIdentifiers, beforeItem: first)
} else { } else {
snapshot.appendItems(identifiers, toSection: .statuses) snapshot.appendItems(newIdentifiers, toSection: .statuses)
} }
completion(.success(snapshot)) completion(.success(snapshot))
} }
@ -205,6 +206,27 @@ extension TimelineTableViewController {
enum Item: Hashable { enum Item: Hashable {
case status(id: String, state: StatusState) case status(id: String, state: StatusState)
case confirmLoadMore case confirmLoadMore
static func ==(lhs: Item, rhs: Item) -> Bool {
switch (lhs, rhs) {
case let (.status(id: a, state: _), .status(id: b, state: _)):
return a == b
case (.confirmLoadMore, .confirmLoadMore):
return true
default:
return false
}
}
func hash(into hasher: inout Hasher) {
switch self {
case let .status(id: id, state: _):
hasher.combine(0)
hasher.combine(id)
case .confirmLoadMore:
hasher.combine(1)
}
}
} }
} }