Skip to content

Commit f6b6828

Browse files
author
Momo Ozawa
committed
Refactor: scroll to top for site title / site icon quick start
1 parent 329f1ef commit f6b6828

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

WordPress/Classes/Extensions/UIScrollView+Helpers.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension UIScrollView {
2121
height: safeAreaLayoutGuide.layoutFrame.height)
2222
scrollRectToVisible(targetRect, animated: animated)
2323
} else {
24-
scrollToBottom()
24+
scrollToBottom(animated: true)
2525
}
2626

2727
// This ensures scrolling to the correct position, especially when there are layout changes
@@ -32,10 +32,15 @@ extension UIScrollView {
3232
}
3333
}
3434

35-
@objc func scrollToBottom() {
35+
@objc func scrollToTop(animated: Bool) {
36+
let topOffset = CGPoint(x: 0, y: -adjustedContentInset.top)
37+
setContentOffset(topOffset, animated: animated)
38+
}
39+
40+
@objc func scrollToBottom(animated: Bool) {
3641
let bottomOffset = CGPoint(x: 0, y: contentSize.height - bounds.size.height + adjustedContentInset.bottom)
3742
if bottomOffset.y > 0 {
38-
setContentOffset(bottomOffset, animated: true)
43+
setContentOffset(bottomOffset, animated: animated)
3944
}
4045
}
4146

WordPress/Classes/ViewRelated/Blog/Site Picker/SitePickerViewController+QuickStart.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ extension SitePickerViewController {
2222
if let info = notification.userInfo?[QuickStartTourGuide.notificationElementKey] as? QuickStartTourElement {
2323
switch info {
2424
case .noSuchElement:
25-
self?.additionalSafeAreaInsets = UIEdgeInsets.zero
25+
self?.additionalSafeAreaInsets = .zero
2626
case .siteIcon, .siteTitle:
2727
// handles the padding in case the element is not in the table view
2828
guard let parentVC = self?.parent as? MySiteViewController else {
2929
return
3030
}
31-
parentVC.additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: BlogDetailsViewController.bottomPaddingForQuickStartNotices, right: 0)
31+
parentVC.additionalSafeAreaInsets = UIEdgeInsets(top: 0, left: 0, bottom: Constants.bottomPaddingForQuickStartNotices, right: 0)
32+
parentVC.scrollView.scrollToTop(animated: true)
3233
default:
3334
break
3435
}
@@ -61,4 +62,8 @@ extension SitePickerViewController {
6162
QuickStartTourGuide.shared.suggest(tourToSuggest, for: blog)
6263
}
6364
}
65+
66+
private enum Constants {
67+
static let bottomPaddingForQuickStartNotices: CGFloat = 80.0
68+
}
6469
}

0 commit comments

Comments
 (0)