@@ -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 {
294295extension 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