accessibility changes
This commit is contained in:
parent
f4fae9255b
commit
3347f4a0af
@ -105,9 +105,12 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
|
|
||||||
for i in 0..<numberOfPages {
|
for i in 0..<numberOfPages {
|
||||||
let bar = View()
|
let bar = View()
|
||||||
|
bar.accessibilityTraits = .button
|
||||||
bar.isAccessibilityElement = true
|
bar.isAccessibilityElement = true
|
||||||
let accessibleLabel = ordinalFormatter.string(from: NSNumber(value: i + 1)) ?? ""
|
if let accessibleValueFormat = accessibilityValueFormat, let accessibleIndex = ordinalFormatter.string(from: NSNumber(value: i + 1)) {
|
||||||
bar.accessibilityLabel = "\(accessibleLabel) page of \(numberOfPages) page"
|
bar.accessibilityLabel = String(format: accessibleValueFormat, accessibleIndex, numberOfPages)
|
||||||
|
}
|
||||||
|
bar.accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "AccTabHint")
|
||||||
bar.widthAnchor.constraint(equalToConstant: BarsIndicatorView.indicatorBarWidth).isActive = true
|
bar.widthAnchor.constraint(equalToConstant: BarsIndicatorView.indicatorBarWidth).isActive = true
|
||||||
bar.backgroundColor = isEnabled ? (i == currentIndex ? currentIndicatorColor : indicatorColor) : disabledIndicatorColor
|
bar.backgroundColor = isEnabled ? (i == currentIndex ? currentIndicatorColor : indicatorColor) : disabledIndicatorColor
|
||||||
let barHeight = i == currentIndex ? BarsIndicatorView.indicatorBarHeight.selected : BarsIndicatorView.indicatorBarHeight.unselected
|
let barHeight = i == currentIndex ? BarsIndicatorView.indicatorBarHeight.selected : BarsIndicatorView.indicatorBarHeight.unselected
|
||||||
|
|||||||
@ -85,6 +85,10 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
set { carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue) }
|
set { carouselIndicatorModel?.indicatorColor = Color(uiColor: newValue) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var accessibilityValueFormat: String? {
|
||||||
|
return MVMCoreUIUtility.hardcodedString(withKey: (carouselIndicatorModel?.accessibilityHasSlidesInsteadOfPage ?? false) ? "MVMCoreUIPageControlslides_currentpage_index" : "MVMCoreUIPageControl_currentpage_index")
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -192,7 +196,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
currentIndex = model.currentIndex
|
currentIndex = model.currentIndex
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
|
|
||||||
|
adjustAccessibilityValue(of: currentIndex + 1, total: numberOfPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -209,11 +213,21 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
accessibilityAdjust(toPage: currentIndex - 1)
|
accessibilityAdjust(toPage: currentIndex - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func adjustAccessibilityValue(of index: Int, total: Int) {
|
||||||
|
|
||||||
|
let ordinalFormatter = NumberFormatter()
|
||||||
|
ordinalFormatter.numberStyle = .ordinal
|
||||||
|
|
||||||
|
guard let accessibleFormat = accessibilityValueFormat,
|
||||||
|
let accessibleIndex = ordinalFormatter.string(from: NSNumber(value: index))
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
accessibilityValue = String(format: accessibleFormat, accessibleIndex, total)
|
||||||
|
}
|
||||||
|
|
||||||
func accessibilityAdjust(toPage index: Int) {
|
func accessibilityAdjust(toPage index: Int) {
|
||||||
|
|
||||||
if let accessibleValue = MVMCoreUIUtility.hardcodedString(withKey: (carouselIndicatorModel?.accessibilityHasSlidesInsteadOfPage ?? false) ? "MVMCoreUIPageControlslides_currentpage_index" : "MVMCoreUIPageControl_currentpage_index") {
|
adjustAccessibilityValue(of: index, total: numberOfPages)
|
||||||
accessibilityValue = String(format: accessibleValue, currentIndex + 1, numberOfPages)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index < numberOfPages && index >= 0) || carouselIndicatorModel?.alwaysSendAction ?? false {
|
if (index < numberOfPages && index >= 0) || carouselIndicatorModel?.alwaysSendAction ?? false {
|
||||||
carouselIndicatorModel?.animated = false
|
carouselIndicatorModel?.animated = false
|
||||||
|
|||||||
@ -17,6 +17,7 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
/// Text to display the current count of total pages for viewing.
|
/// Text to display the current count of total pages for viewing.
|
||||||
open var pageCount: Label = {
|
open var pageCount: Label = {
|
||||||
let label = Label.commonLabelB2(true)
|
let label = Label.commonLabelB2(true)
|
||||||
|
label.isAccessibilityElement = false
|
||||||
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
label.setContentCompressionResistancePriority(.required, for: .vertical)
|
||||||
label.textAlignment = .center
|
label.textAlignment = .center
|
||||||
return label
|
return label
|
||||||
@ -77,8 +78,6 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
isAccessibilityElement = true
|
|
||||||
accessibilityTraits = .adjustable
|
|
||||||
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "swipe_to_select_with_action_hint")
|
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "swipe_to_select_with_action_hint")
|
||||||
addSubview(pageCount)
|
addSubview(pageCount)
|
||||||
addSubview(leftArrow)
|
addSubview(leftArrow)
|
||||||
@ -121,15 +120,7 @@ open class NumericIndicatorView: CarouselIndicator {
|
|||||||
open override func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) {
|
open override func updateUI(previousIndex oldIndex: Int, newIndex: Int, totalCount: Int, isAnimated: Bool) {
|
||||||
|
|
||||||
pageCount.text = "\(newIndex + 1)/\(totalCount)"
|
pageCount.text = "\(newIndex + 1)/\(totalCount)"
|
||||||
pageCount.accessibilityValue = "Page \(newIndex + 1) of \(totalCount)"
|
adjustAccessibilityValue(of: newIndex + 1, total: totalCount)
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
// open override func accessibilityIncrement() {
|
|
||||||
// incrementCurrentIndex()
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// open override func accessibilityDecrement() {
|
|
||||||
// decrementCurrentIndex()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,8 +68,8 @@
|
|||||||
|
|
||||||
|
|
||||||
// MARK: Carousel
|
// MARK: Carousel
|
||||||
"MVMCoreUIPageControl_currentpage_index" = "page %ld of %ld";
|
"MVMCoreUIPageControl_currentpage_index" = "page %@ of %d";
|
||||||
"MVMCoreUIPageControlslides_currentpage_index" = "slide %ld of %ld";
|
"MVMCoreUIPageControlslides_currentpage_index" = "slide %@ of %d";
|
||||||
|
|
||||||
|
|
||||||
// MARK: Styler
|
// MARK: Styler
|
||||||
|
|||||||
@ -48,8 +48,8 @@
|
|||||||
"AccOff" = "apagado";
|
"AccOff" = "apagado";
|
||||||
"AccToggleHint" = "toca dos veces para alternar";
|
"AccToggleHint" = "toca dos veces para alternar";
|
||||||
// Carousel
|
// Carousel
|
||||||
"MVMCoreUIPageControl_currentpage_index" = "página %ld de %ld";
|
"MVMCoreUIPageControl_currentpage_index" = "página %@ de %d";
|
||||||
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %ld of %ld";
|
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %@ of %d";
|
||||||
//Styler
|
//Styler
|
||||||
"CountDownDay" = " día";
|
"CountDownDay" = " día";
|
||||||
"CountDownHour" = " hora";
|
"CountDownHour" = " hora";
|
||||||
|
|||||||
@ -50,8 +50,8 @@
|
|||||||
"AccOff" = "apagado";
|
"AccOff" = "apagado";
|
||||||
"AccToggleHint" = "toca dos veces para alternar";
|
"AccToggleHint" = "toca dos veces para alternar";
|
||||||
// Carousel
|
// Carousel
|
||||||
"MVMCoreUIPageControl_currentpage_index" = "página %ld de %ld";
|
"MVMCoreUIPageControl_currentpage_index" = "página %@ de %d";
|
||||||
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %ld of %ld";
|
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %@ of %d";
|
||||||
//Styler
|
//Styler
|
||||||
"CountDownDay" = " día";
|
"CountDownDay" = " día";
|
||||||
"CountDownHour" = " hora";
|
"CountDownHour" = " hora";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user