Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Site Dashboard: keep collection view position after an update #18245

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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