Skip to content

Commit a24b722

Browse files
authored
Merge pull request #180 from allanweir/master
Allow for explicit setting of the accessibility label, hint and identifier.
2 parents 6510afb + b1081a5 commit a24b722

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Sources/ESTabBar.swift

+22-11
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ internal extension ESTabBar /* Actions */ {
276276
}
277277
}
278278

279+
self.updateAccessibilityLabels()
279280
self.setNeedsLayout()
280281
}
281282

@@ -407,20 +408,30 @@ internal extension ESTabBar /* Actions */ {
407408

408409
for (idx, item) in tabBarItems.enumerated() {
409410
let container = self.containers[idx]
410-
var accessibilityTitle = ""
411+
container.accessibilityIdentifier = item.accessibilityIdentifier
412+
container.accessibilityTraits = item.accessibilityTraits
411413

412-
if let item = item as? ESTabBarItem {
413-
accessibilityTitle = item.accessibilityLabel ?? item.title ?? ""
414-
}
415-
if self.isMoreItem(idx) {
416-
accessibilityTitle = NSLocalizedString("More_TabBarItem", bundle: Bundle(for:ESTabBarController.self), comment: "")
414+
if item == selectedItem {
415+
container.accessibilityTraits = container.accessibilityTraits.union(.selected)
417416
}
418417

419-
let formatString = NSLocalizedString(item == selectedItem ? "TabBarItem_Selected_AccessibilityLabel" : "TabBarItem_AccessibilityLabel",
420-
bundle: Bundle(for: ESTabBarController.self),
421-
comment: "")
422-
container.accessibilityIdentifier = item.accessibilityIdentifier
423-
container.accessibilityLabel = String(format: formatString, accessibilityTitle, idx + 1, tabBarItems.count)
418+
if let explicitLabel = item.accessibilityLabel {
419+
container.accessibilityLabel = explicitLabel
420+
container.accessibilityHint = item.accessibilityHint ?? container.accessibilityHint
421+
} else {
422+
var accessibilityTitle = ""
423+
if let item = item as? ESTabBarItem {
424+
accessibilityTitle = item.accessibilityLabel ?? item.title ?? ""
425+
}
426+
if self.isMoreItem(idx) {
427+
accessibilityTitle = NSLocalizedString("More_TabBarItem", bundle: Bundle(for:ESTabBarController.self), comment: "")
428+
}
429+
430+
let formatString = NSLocalizedString(item == selectedItem ? "TabBarItem_Selected_AccessibilityLabel" : "TabBarItem_AccessibilityLabel",
431+
bundle: Bundle(for: ESTabBarController.self),
432+
comment: "")
433+
container.accessibilityLabel = String(format: formatString, accessibilityTitle, idx + 1, tabBarItems.count)
434+
}
424435

425436
}
426437
}

0 commit comments

Comments
 (0)