@@ -50,43 +50,37 @@ public extension WMFNavigationBarHiding where Self:UIViewController {
5050 let statusBarHeight = UIApplication . shared. statusBarFrame. height
5151 topSafeAreaOverlayHeightConstraint? . constant = statusBarHeight
5252 }
53-
54- /// Call from a UIViewController's scrollViewDidScroll method to unstick a hidden navigation bar when scrolled to the top.
53+
5554 func calculateNavigationBarHiddenState( scrollView: UIScrollView ) {
5655 let finalOffset = scrollView. contentOffset. y + scrollView. safeAreaInsets. top
5756 if finalOffset < 5 && ( navigationController? . navigationBar. isHidden ?? true ) {
5857 navigationController? . setNavigationBarHidden ( false , animated: true )
5958 }
6059 }
61-
60+
6261 func updateLogoImageOnScroll( scrollView: UIScrollView ) {
6362 let finalOffset = scrollView. contentOffset. y + scrollView. safeAreaInsets. top
6463 let isCompactMode = finalOffset > 75
65-
66- // Get stored state using associated object
67- let key = UnsafeRawPointer ( bitPattern: " logoCompactModeKey " . hashValue) !
68- let currentState = objc_getAssociatedObject ( self , key) as? NSNumber
69- let wasCompactMode = currentState? . boolValue ?? false
70-
71- // Only update if state changed
72- if isCompactMode != wasCompactMode {
73- objc_setAssociatedObject ( self , key, NSNumber ( value: isCompactMode) , . OBJC_ASSOCIATION_RETAIN_NONATOMIC)
74-
75- if isCompactMode {
76- swapLogoToCompact ( )
77- } else {
78- swapLogoToFull ( )
79- }
64+
65+ guard isCompactMode != WMFNavigationBarHidingLogoState . isCompact else { return }
66+ WMFNavigationBarHidingLogoState . isCompact = isCompactMode
67+
68+ if isCompactMode {
69+ swapLogoToCompact ( )
70+ } else {
71+ swapLogoToFull ( )
8072 }
8173 }
82-
83- /// Swap logo to the compact W icon
74+
8475 private func swapLogoToCompact( ) {
8576 navigationItem. leftBarButtonItem? . image = UIImage ( named: " W " )
8677 }
8778
88- /// Swap logo back to the full Wikipedia logo
8979 private func swapLogoToFull( ) {
9080 navigationItem. leftBarButtonItem? . image = UIImage ( named: " wikipedia " )
9181 }
9282}
83+
84+ private enum WMFNavigationBarHidingLogoState {
85+ static var isCompact : Bool = false
86+ }
0 commit comments