Skip to content

Commit

Permalink
Merge pull request #18245 from wordpress-mobile/issue/18195_keep_coll…
Browse files Browse the repository at this point in the history
…ection_view_position_after_update

My Site Dashboard: keep collection view position after an update
  • Loading branch information
leandroalonso authored Mar 31, 2022
2 parents ec43a9a + 4d64eb9 commit dde7abc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ final class BlogDashboardViewController: UIViewController {
return collectionView
}()

/// The "My Site" main scroll view
var mySiteScrollView: UIScrollView? {
return view.superview?.superview as? UIScrollView
}

@objc init(blog: Blog) {
self.blog = blog
super.init(nibName: nil, bundle: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,22 @@ class BlogDashboardViewModel {
private extension BlogDashboardViewModel {

func apply(snapshot: DashboardSnapshot) {
dataSource?.apply(snapshot, animatingDifferences: false)
let scrollView = viewController?.mySiteScrollView
let position = scrollView?.contentOffset

dataSource?.apply(snapshot, animatingDifferences: false) { [weak self] in
guard let scrollView = scrollView, let position = position else {
return
}

self?.scroll(scrollView, to: position)
}
}

func scroll(_ scrollView: UIScrollView, to position: CGPoint) {
if position.y > 0 {
scrollView.setContentOffset(position, animated: false)
}
}
}

Expand Down

0 comments on commit dde7abc

Please sign in to comment.