Skip to content

Commit 7ffd09a

Browse files
author
golson
committed
Update accessibility, crumbs from AI, etc
1 parent 61a244c commit 7ffd09a

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

WMFComponents/Sources/WMFComponents/Extensions/Navigation Bar/WMFNavigationBarHiding.swift

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

Wikipedia/Code/ExploreViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class ExploreViewController: ColumnarCollectionViewController, ExploreCardViewCo
169169

170170
private func configureNavigationBar() {
171171

172-
let titleConfig: WMFNavigationBarTitleConfig = WMFNavigationBarTitleConfig(title: CommonStrings.exploreTabTitle, customView: titleView, alignment: .leadingCompact)
172+
let titleConfig: WMFNavigationBarTitleConfig = WMFNavigationBarTitleConfig(title: CommonStrings.exploreTabTitle, customView: nil, alignment: .leadingCompact)
173173

174174
let profileButtonConfig = profileButtonConfig(target: self, action: #selector(userDidTapProfile), dataStore: dataStore, yirDataController: yirDataController, leadingBarButtonItem: nil)
175175

@@ -195,14 +195,16 @@ class ExploreViewController: ColumnarCollectionViewController, ExploreCardViewCo
195195
searchBarPlaceholder: CommonStrings.searchBarPlaceholder,
196196
showsScopeBar: false, scopeButtonTitles: nil)
197197

198-
199198
configureNavigationBar(titleConfig: titleConfig, closeButtonConfig: nil, profileButtonConfig: profileButtonConfig, tabsButtonConfig: tabsButtonConfig, searchBarConfig: searchConfig, hideNavigationBarOnScroll: !presentingSearchResults)
200-
201-
// Need to override this so that "" does not appear as back button title.
199+
202200
navigationItem.backButtonTitle = CommonStrings.exploreTabTitle
203201

204202
// Set up logo as left bar button item
203+
205204
let logoBarButtonItem = UIBarButtonItem(image: UIImage(named: "wikipedia"), style: .plain, target: self, action: #selector(titleBarButtonPressed(_:)))
205+
logoBarButtonItem.accessibilityLabel = titleButton.accessibilityLabel
206+
logoBarButtonItem.accessibilityHint = titleButton.accessibilityHint
207+
logoBarButtonItem.accessibilityIdentifier = titleButton.accessibilityIdentifier
206208
navigationItem.leftBarButtonItem = logoBarButtonItem
207209
}
208210

0 commit comments

Comments
 (0)