Skip to content

Commit 6ddd16e

Browse files
authored
Merge pull request #5883 from woocommerce/fix/5843-dashboard-scroll-glitch
My store tab: fix glitch when scrolling up the dashboard with certain content height
2 parents 124ece6 + eb72cf7 commit 6ddd16e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ final class DashboardViewController: UIViewController {
8888
return view
8989
}()
9090

91-
private var cancellables = Set<AnyCancellable>()
91+
private var subscriptions = Set<AnyCancellable>()
9292

9393
// MARK: View Lifecycle
9494

@@ -111,6 +111,7 @@ final class DashboardViewController: UIViewController {
111111
configureBottomJetpackBenefitsBanner()
112112
observeSiteForUIUpdates()
113113
observeBottomJetpackBenefitsBannerVisibilityUpdates()
114+
observeNavigationBarHeightForStoreNameLabelVisibility()
114115
}
115116

116117
override func viewWillAppear(_ animated: Bool) {
@@ -294,22 +295,6 @@ private extension DashboardViewController {
294295
extension DashboardViewController: DashboardUIScrollDelegate {
295296
func dashboardUIScrollViewDidScroll(_ scrollView: UIScrollView) {
296297
hiddenScrollView.updateFromScrollViewDidScrollEventForLargeTitleWorkaround(scrollView)
297-
showOrHideSubtitle(offset: scrollView.contentOffset.y)
298-
}
299-
300-
private func showOrHideSubtitle(offset: CGFloat) {
301-
guard shouldShowStoreNameAsSubtitle else {
302-
return
303-
}
304-
storeNameLabel.isHidden = offset > headerStackView.frame.height
305-
if offset < -headerStackView.frame.height {
306-
UIView.transition(with: storeNameLabel, duration: Constants.animationDuration,
307-
options: .showHideTransitionViews,
308-
animations: { [weak self] in
309-
guard let self = self else { return }
310-
self.storeNameLabel.isHidden = false
311-
})
312-
}
313298
}
314299
}
315300

@@ -438,7 +423,7 @@ private extension DashboardViewController {
438423
guard let self = self else { return }
439424
self.updateUI(site: site)
440425
self.reloadData(forced: true)
441-
}.store(in: &cancellables)
426+
}.store(in: &subscriptions)
442427
}
443428

444429
func observeBottomJetpackBenefitsBannerVisibilityUpdates() {
@@ -462,7 +447,22 @@ private extension DashboardViewController {
462447
self.updateJetpackBenefitsBannerVisibility(isBannerVisible: shouldShowJetpackBenefitsBanner, contentView: contentView)
463448
}
464449
ServiceLocator.stores.dispatch(action)
465-
}.store(in: &cancellables)
450+
}.store(in: &subscriptions)
451+
}
452+
453+
func observeNavigationBarHeightForStoreNameLabelVisibility() {
454+
navigationController?.navigationBar.publisher(for: \.frame, options: [.initial, .new])
455+
.map { $0.height }
456+
.removeDuplicates()
457+
.sink(receiveValue: { [weak self] navigationBarHeight in
458+
guard let self = self else { return }
459+
460+
guard self.shouldShowStoreNameAsSubtitle else {
461+
return
462+
}
463+
self.storeNameLabel.isHidden = navigationBarHeight <= Constants.collapsedNavigationBarHeight
464+
})
465+
.store(in: &subscriptions)
466466
}
467467
}
468468

@@ -476,8 +476,8 @@ private extension DashboardViewController {
476476
}
477477

478478
enum Constants {
479-
static let animationDuration = 0.2
480479
static let bannerBottomMargin = CGFloat(8)
481480
static let horizontalMargin = CGFloat(20)
481+
static let collapsedNavigationBarHeight = CGFloat(44)
482482
}
483483
}

0 commit comments

Comments
 (0)