summaryrefslogtreecommitdiffhomepage
path: root/ios
diff options
context:
space:
mode:
authorNikolay Davydov <nik.davidov@gmail.com>2022-08-11 21:55:06 +0400
committerAndrej Mihajlov <and@mullvad.net>2022-08-16 10:54:15 +0200
commitbab4c7a70f65c4bdcb0b106f46a42d6eb396b35a (patch)
tree252de4410f4b52bd5cfe12ed996a4f87a974c581 /ios
parent270ae785e8629f7888475ed5314f77846858b242 (diff)
downloadmullvadvpn-bab4c7a70f65c4bdcb0b106f46a42d6eb396b35a.tar.xz
mullvadvpn-bab4c7a70f65c4bdcb0b106f46a42d6eb396b35a.zip
Scroll to inserted locations
Diffstat (limited to 'ios')
-rw-r--r--ios/MullvadVPN/LocationDataSource.swift21
1 files changed, 21 insertions, 0 deletions
diff --git a/ios/MullvadVPN/LocationDataSource.swift b/ios/MullvadVPN/LocationDataSource.swift
index b835e4ad6d..4269eaefc7 100644
--- a/ios/MullvadVPN/LocationDataSource.swift
+++ b/ios/MullvadVPN/LocationDataSource.swift
@@ -344,6 +344,26 @@ class LocationDataSource: NSObject, UITableViewDataSource {
}
}
+ let scrollToInsertedIndexPaths = { [weak tableView] (changeSet: ChangeSet) in
+ guard let lastInsertedIndexPath = changeSet.insertIndexPaths.last,
+ let lastUpdatedIndexPath = changeSet.updateIndexPaths.last,
+ let visibleIndexPaths = tableView?.indexPathsForVisibleRows,
+ let lastVisibleIndexPath = visibleIndexPaths.last,
+ lastInsertedIndexPath >= lastVisibleIndexPath
+ else {
+ return
+ }
+ if changeSet.insertIndexPaths.count >= visibleIndexPaths.count {
+ tableView?.scrollToRow(at: lastUpdatedIndexPath, at: .top, animated: true)
+ } else {
+ tableView?.scrollToRow(
+ at: lastInsertedIndexPath,
+ at: .bottom,
+ animated: true
+ )
+ }
+ }
+
if animated {
guard let changeSet = applyChanges() else { return }
tableView.performBatchUpdates {
@@ -357,6 +377,7 @@ class LocationDataSource: NSObject, UITableViewDataSource {
cellUpdater(tableView, indexPath, item)
}
} completion: { finished in
+ scrollToInsertedIndexPaths(changeSet)
restoreSelection()
completion?()
}