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

View File

@ -33,9 +33,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
public var indicatorTouchAction: ((CarouselPageControlProtocol) -> ())?
open override var isEnabled: Bool {
didSet {
isUserInteractionEnabled = isEnabled
}
didSet { isUserInteractionEnabled = isEnabled }
}
//--------------------------------------------------
@ -52,8 +50,12 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
previousIndex = _currentIndex
_currentIndex = newIndex
performAction()
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
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 {
return carouselIndicatorModel?.disabledIndicatorColor.uiColor ?? .mvmCoolGray3
get { return _disabledIndicatorColor }
set (newDisabledColor) {
_disabledIndicatorColor = newDisabledColor
carouselIndicatorModel?.disabledIndicatorColor = Color(uiColor: newDisabledColor)
}
}
private(set) var _indicatorColor: UIColor = .black
@ -84,6 +95,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
public var indicatorColor: UIColor {
get { return _indicatorColor }
set (newColor) {
_indicatorColor = newColor
carouselIndicatorModel?.indicatorColor = Color(uiColor: newColor)
}
}
@ -196,6 +208,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
guard let model = model as? CarouselIndicatorModel else { return }
indicatorColor = model.indicatorColor.uiColor
disabledIndicatorColor = model.disabledIndicatorColor.uiColor
currentIndex = model.currentIndex
isEnabled = model.isEnabled

View File

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

View File

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