diff options
| author | Nikolay Davydov <nik.davidov@gmail.com> | 2022-08-11 21:55:06 +0400 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-08-16 10:54:15 +0200 |
| commit | bab4c7a70f65c4bdcb0b106f46a42d6eb396b35a (patch) | |
| tree | 252de4410f4b52bd5cfe12ed996a4f87a974c581 /ios | |
| parent | 270ae785e8629f7888475ed5314f77846858b242 (diff) | |
| download | mullvadvpn-bab4c7a70f65c4bdcb0b106f46a42d6eb396b35a.tar.xz mullvadvpn-bab4c7a70f65c4bdcb0b106f46a42d6eb396b35a.zip | |
Scroll to inserted locations
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN/LocationDataSource.swift | 21 |
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?() } |
