more logos and accessibility

This commit is contained in:
Kevin G Christiano 2020-03-31 16:28:25 -04:00
parent 2037cbba82
commit 0b0aaefe99
4 changed files with 38 additions and 11 deletions

View File

@ -17,6 +17,7 @@ open class BarsIndicatorView: CarouselIndicator {
public let stackView: UIStackView = { public let stackView: UIStackView = {
let stackView = UIStackView() let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.isAccessibilityElement = false
stackView.axis = .horizontal stackView.axis = .horizontal
stackView.alignment = .bottom stackView.alignment = .bottom
stackView.distribution = .equalSpacing stackView.distribution = .equalSpacing
@ -83,6 +84,7 @@ open class BarsIndicatorView: CarouselIndicator {
addSubview(stackView) addSubview(stackView)
isUserInteractionEnabled = false isUserInteractionEnabled = false
isAccessibilityElement = false
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
stackView.heightAnchor.constraint(equalToConstant: 4), stackView.heightAnchor.constraint(equalToConstant: 4),
@ -105,6 +107,7 @@ open class BarsIndicatorView: CarouselIndicator {
for i in 0..<numberOfPages { for i in 0..<numberOfPages {
let bar = View() let bar = View()
bar.isAccessibilityElement = true
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
@ -115,6 +118,7 @@ open class BarsIndicatorView: CarouselIndicator {
bars.append((bar, heightConstraint)) bars.append((bar, heightConstraint))
} }
accessibilityElements = stackView.arrangedSubviews
barReferences = bars barReferences = bars
} }

View File

@ -33,9 +33,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())? public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())?
open override var isEnabled: Bool { open override var isEnabled: Bool {
didSet { didSet { isUserInteractionEnabled = isEnabled }
isUserInteractionEnabled = isEnabled
}
} }
//-------------------------------------------------- //--------------------------------------------------
@ -52,8 +50,12 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
previousIndex = _currentIndex previousIndex = _currentIndex
_currentIndex = newIndex _currentIndex = newIndex
performAction() performAction()
if previousIndex != newIndex { if previousIndex != newIndex {
updateUI(previousIndex: previousIndex, newIndex: newIndex, totalCount: numberOfPages, isAnimated: carouselIndicatorModel?.isAnimated ?? true) updateUI(previousIndex: previousIndex,
newIndex: newIndex,
totalCount: numberOfPages,
isAnimated: carouselIndicatorModel?.isAnimated ?? true)
} }
} }
} }
@ -71,12 +73,21 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
_numberOfPages = newTotal _numberOfPages = newTotal
isHidden = carouselIndicatorModel?.hidesForSinglePage ?? false && newTotal <= 1 isHidden = carouselIndicatorModel?.hidesForSinglePage ?? false && newTotal <= 1
updateUI(previousIndex: previousIndex, newIndex: currentIndex, totalCount: newTotal, isAnimated: carouselIndicatorModel?.isAnimated ?? true) updateUI(previousIndex: previousIndex,
newIndex: currentIndex,
totalCount: newTotal,
isAnimated: carouselIndicatorModel?.isAnimated ?? true)
} }
} }
private(set) var _disabledIndicatorColor: UIColor = .mvmCoolGray3
public var disabledIndicatorColor: UIColor { public var disabledIndicatorColor: UIColor {
return carouselIndicatorModel?.disabledIndicatorColor.uiColor ?? .mvmCoolGray3 get { return _disabledIndicatorColor }
set (newDisabledColor) {
_disabledIndicatorColor = newDisabledColor
carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newDisabledColor)
}
} }
private(set) var _indicatorColor: UIColor = .black private(set) var _indicatorColor: UIColor = .black
@ -84,6 +95,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
public var indicatorColor: UIColor { public var indicatorColor: UIColor {
get { return _indicatorColor } get { return _indicatorColor }
set (newColor) { set (newColor) {
_indicatorColor = newColor
carouselIndicatorModel?.indicatorColor = Color(uiColor: newColor) carouselIndicatorModel?.indicatorColor = Color(uiColor: newColor)
} }
} }
@ -196,6 +208,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
guard let model = model as? CarouselIndicatorModel else { return } guard let model = model as? CarouselIndicatorModel else { return }
indicatorColor = model.indicatorColor.uiColor indicatorColor = model.indicatorColor.uiColor
disabledIndicatorColor = model.disabledIndicatorColor.uiColor
currentIndex = model.currentIndex currentIndex = model.currentIndex
isEnabled = model.isEnabled isEnabled = model.isEnabled

View File

@ -18,18 +18,25 @@ open class NumericIndicatorView: CarouselIndicator {
open var pageCount: Label = { open var pageCount: Label = {
let label = Label.commonLabelB2(true) let label = Label.commonLabelB2(true)
label.setContentCompressionResistancePriority(.required, for: .vertical) label.setContentCompressionResistancePriority(.required, for: .vertical)
label.accessibilityLabel = "Page Count"
label.textAlignment = .center label.textAlignment = .center
return label return label
}() }()
let leftArrow: Arrow = { let leftArrow: Arrow = {
let arrow = Arrow(model: ArrowModel(), degrees: 180) let arrow = Arrow(model: ArrowModel(), degrees: 180)
arrow.isAccessibilityElement = true
arrow.accessibilityLabel = "Left arrow"
arrow.accessibilityHint = "Double tap to swipe carousel left"
arrow.pinHeightAndWidth() arrow.pinHeightAndWidth()
return arrow return arrow
}() }()
let rightArrow: Arrow = { let rightArrow: Arrow = {
let arrow = Arrow(model: ArrowModel()) let arrow = Arrow(model: ArrowModel())
arrow.isAccessibilityElement = true
arrow.accessibilityLabel = "Right arrow"
arrow.accessibilityHint = "Double tap to swipe carousel right"
arrow.pinHeightAndWidth() arrow.pinHeightAndWidth()
return arrow return arrow
}() }()
@ -54,8 +61,8 @@ open class NumericIndicatorView: CarouselIndicator {
if isEnabled { if isEnabled {
pageCount.textColor = newColor pageCount.textColor = newColor
leftArrow.tintColor = newColor leftArrow.arrowModel?.color = Color(uiColor: newColor)
rightArrow.tintColor = newColor rightArrow.arrowModel?.color = Color(uiColor: newColor)
} }
} }
} }
@ -77,6 +84,7 @@ open class NumericIndicatorView: CarouselIndicator {
super.setupView() super.setupView()
isUserInteractionEnabled = false isUserInteractionEnabled = false
isAccessibilityElement = false
addSubview(pageCount) addSubview(pageCount)
addSubview(leftArrow) addSubview(leftArrow)
addSubview(rightArrow) addSubview(rightArrow)
@ -92,6 +100,8 @@ open class NumericIndicatorView: CarouselIndicator {
rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: PaddingOne), rightArrow.leadingAnchor.constraint(equalTo: pageCount.trailingAnchor, constant: PaddingOne),
trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor) trailingAnchor.constraint(equalTo: rightArrow.trailingAnchor)
]) ])
accessibilityElements = [leftArrow, pageCount, rightArrow]
} }
public override func assessTouchOf(_ touchPoint_X: CGFloat) { public override func assessTouchOf(_ touchPoint_X: CGFloat) {
@ -110,6 +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)"
layoutIfNeeded() layoutIfNeeded()
} }
} }

View File

@ -260,9 +260,8 @@ open class Carousel: View {
} }
public func setAccessiblity(_ cell: UICollectionViewCell?, index: Int) { public func setAccessiblity(_ cell: UICollectionViewCell?, index: Int) {
guard let cell = cell else { guard let cell = cell else { return }
return
}
if index == currentIndex { if index == currentIndex {
cell.accessibilityElementsHidden = false cell.accessibilityElementsHidden = false
var array = cell.accessibilityElements var array = cell.accessibilityElements