Remove notifications from the bottom when scrolling up notifications list
This commit is contained in:
parent
6d8c5f632c
commit
98529ca5af
|
@ -127,6 +127,33 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
||||||
// MARK: - Table view delegate
|
// MARK: - Table view delegate
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
|
||||||
|
// see TimelineTableViewController.tableView(_:willDisplay:forRowAt:)
|
||||||
|
if !isCurrentlyScrollingToTop, scrollViewDirection < 0 {
|
||||||
|
let pageSize = 20
|
||||||
|
if groups.count > 2 * pageSize,
|
||||||
|
indexPath.row < groups.count - (2 * pageSize) {
|
||||||
|
let groupsToRemove = groups[groups.count - pageSize..<groups.count]
|
||||||
|
for group in groupsToRemove {
|
||||||
|
for notification in group.notifications {
|
||||||
|
// todo: reference count accounts
|
||||||
|
// mastodonController.persistentContainer.account(for: notification.account.id)?.decrementReferenceCount()
|
||||||
|
if let id = notification.status?.id {
|
||||||
|
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let removedIndexPaths = (groups.count - 20..<groups.count).map { IndexPath(row: $0, section: 0) }
|
||||||
|
|
||||||
|
groups.removeLast(pageSize)
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
UIView.performWithoutAnimation {
|
||||||
|
tableView.deleteRows(at: removedIndexPaths, with: .none)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if indexPath.row == groups.count - 1 {
|
if indexPath.row == groups.count - 1 {
|
||||||
guard let older = older else { return }
|
guard let older = older else { return }
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,6 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
var newer: RequestRange?
|
var newer: RequestRange?
|
||||||
var older: RequestRange?
|
var older: RequestRange?
|
||||||
|
|
||||||
private var prevScrollViewContentOffset: CGPoint?
|
|
||||||
private var scrollViewDirection: CGFloat = 0
|
|
||||||
|
|
||||||
init(for timeline: Timeline, mastodonController: MastodonController) {
|
init(for timeline: Timeline, mastodonController: MastodonController) {
|
||||||
self.timeline = timeline
|
self.timeline = timeline
|
||||||
self.mastodonController = mastodonController
|
self.mastodonController = mastodonController
|
||||||
|
@ -143,7 +140,7 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
for (id, _) in statusesToRemove {
|
for (id, _) in statusesToRemove {
|
||||||
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
|
mastodonController.persistentContainer.status(for: id)?.decrementReferenceCount()
|
||||||
}
|
}
|
||||||
timelineSegments[timelineSegments.count - 1].removeLast(20)
|
timelineSegments[timelineSegments.count - 1].removeLast(pageSize)
|
||||||
|
|
||||||
let removedIndexPaths = (lastSection.count - 20..<lastSection.count).map { IndexPath(row: $0, section: timelineSegments.count - 1) }
|
let removedIndexPaths = (lastSection.count - 20..<lastSection.count).map { IndexPath(row: $0, section: timelineSegments.count - 1) }
|
||||||
// Removing this DispatchQueue.main.async call causes things to break when scrolling
|
// Removing this DispatchQueue.main.async call causes things to break when scrolling
|
||||||
|
@ -197,6 +194,8 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
return (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration()
|
return (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: Interaction
|
||||||
|
|
||||||
@objc func refreshStatuses(_ sender: Any) {
|
@objc func refreshStatuses(_ sender: Any) {
|
||||||
guard let newer = newer else { return }
|
guard let newer = newer else { return }
|
||||||
|
|
||||||
|
@ -228,15 +227,6 @@ class TimelineTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark: Scroll View Delegate
|
|
||||||
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
|
||||||
if let prev = prevScrollViewContentOffset {
|
|
||||||
scrollViewDirection = scrollView.contentOffset.y - prev.y
|
|
||||||
}
|
|
||||||
prevScrollViewContentOffset = scrollView.contentOffset
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@objc func composePressed(_ sender: Any) {
|
@objc func composePressed(_ sender: Any) {
|
||||||
compose()
|
compose()
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,10 @@ class EnhancedTableViewController: UITableViewController {
|
||||||
|
|
||||||
private var prevScrollToTopOffset: CGPoint? = nil
|
private var prevScrollToTopOffset: CGPoint? = nil
|
||||||
private(set) var isCurrentlyScrollingToTop = false
|
private(set) var isCurrentlyScrollingToTop = false
|
||||||
|
private var prevScrollViewContentOffset: CGPoint?
|
||||||
|
private(set) var scrollViewDirection: CGFloat = 0
|
||||||
|
|
||||||
|
// MARK: Scroll View Delegate
|
||||||
|
|
||||||
override func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
|
override func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
|
||||||
if let offset = prevScrollToTopOffset {
|
if let offset = prevScrollToTopOffset {
|
||||||
|
@ -37,6 +41,14 @@ class EnhancedTableViewController: UITableViewController {
|
||||||
prevScrollToTopOffset = nil
|
prevScrollToTopOffset = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
|
if let prev = prevScrollViewContentOffset {
|
||||||
|
scrollViewDirection = scrollView.contentOffset.y - prev.y
|
||||||
|
}
|
||||||
|
prevScrollViewContentOffset = scrollView.contentOffset
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Table View Delegate
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
if let cell = tableView.cellForRow(at: indexPath) as? SelectableTableViewCell {
|
if let cell = tableView.cellForRow(at: indexPath) as? SelectableTableViewCell {
|
||||||
|
|
Loading…
Reference in New Issue