Skip to content

Commit

Permalink
#222 fix accessibility for buttons. #294 set accessibilityViewIsModal…
Browse files Browse the repository at this point in the history
… for EKWindow instance
  • Loading branch information
huri000 committed Sep 1, 2020
1 parent bcb8fdd commit ed78457
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
42 changes: 26 additions & 16 deletions Example/SwiftEntryKit/Presets/PresetsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ class PresetsViewController: UIViewController {
color: titleColor,
alignment: .center,
displayMode: displayMode
)
),
accessibilityIdentifier: "title"
)
let description = EKProperty.LabelContent(
text: description,
Expand All @@ -553,7 +554,8 @@ class PresetsViewController: UIViewController {
color: descriptionColor,
alignment: .center,
displayMode: displayMode
)
),
accessibilityIdentifier: "description"
)
let button = EKProperty.ButtonContent(
label: .init(
Expand All @@ -566,7 +568,8 @@ class PresetsViewController: UIViewController {
),
backgroundColor: buttonBackgroundColor,
highlightedBackgroundColor: buttonTitleColor.with(alpha: 0.05),
displayMode: displayMode
displayMode: displayMode,
accessibilityIdentifier: "button"
)
let message = EKPopUpMessage(
themeImage: themeImage,
Expand All @@ -586,21 +589,24 @@ class PresetsViewController: UIViewController {
font: MainFont.medium.with(size: 15),
color: .black,
displayMode: displayMode
)
),
accessibilityIdentifier: "title"
)
let description = EKProperty.LabelContent(
text: "Get your coupon for a free book now",
style: .init(
font: MainFont.light.with(size: 13),
color: .black,
displayMode: displayMode
)
),
accessibilityIdentifier: "description"
)
let image = EKProperty.ImageContent(
imageName: "ic_books",
displayMode: displayMode,
size: CGSize(width: 35, height: 35),
contentMode: .scaleAspectFit
contentMode: .scaleAspectFit,
accessibilityIdentifier: "image"
)
let simpleMessage = EKSimpleMessage(
image: image,
Expand All @@ -620,7 +626,8 @@ class PresetsViewController: UIViewController {
let closeButton = EKProperty.ButtonContent(
label: closeButtonLabel,
backgroundColor: .clear,
highlightedBackgroundColor: Color.Gray.a800.with(alpha: 0.05)) {
highlightedBackgroundColor: Color.Gray.a800.with(alpha: 0.05),
accessibilityIdentifier: "close-button") {
SwiftEntryKit.dismiss()
}
let okButtonLabelStyle = EKProperty.LabelStyle(
Expand All @@ -636,7 +643,8 @@ class PresetsViewController: UIViewController {
label: okButtonLabel,
backgroundColor: .clear,
highlightedBackgroundColor: Color.Teal.a600.with(alpha: 0.05),
displayMode: displayMode) { [unowned self] in
displayMode: displayMode,
accessibilityIdentifier: "ok-button") { [unowned self] in
var attributes = self.dataSource.bottomAlertAttributes
attributes.entryBackground = .color(color: Color.Teal.a600)
attributes.entranceAnimation = .init(
Expand All @@ -645,14 +653,16 @@ class PresetsViewController: UIViewController {
let image = UIImage(named: "ic_success")!
let title = "Congratz!"
let description = "Your book coupon is 5w1ft3ntr1k1t"
self.showPopupMessage(attributes: attributes,
title: title,
titleColor: .white,
description: description,
descriptionColor: .white,
buttonTitleColor: .subText,
buttonBackgroundColor: .white,
image: image)
self.showPopupMessage(
attributes: attributes,
title: title,
titleColor: .white,
description: description,
descriptionColor: .white,
buttonTitleColor: .subText,
buttonBackgroundColor: .white,
image: image
)
}
let buttonsBarContent = EKProperty.ButtonBarContent(
with: closeButton, okButton,
Expand Down
1 change: 1 addition & 0 deletions Source/Extensions/UIView+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension UIButton {
setTitle(newValue.label.text, for: .normal)
setTitleColor(newValue.label.style.color(for: traitCollection), for: .normal)
titleLabel?.font = newValue.label.style.font
accessibilityIdentifier = newValue.accessibilityIdentifier
backgroundColor = newValue.backgroundColor.color(
for: traitCollection,
mode: newValue.displayMode
Expand Down
1 change: 1 addition & 0 deletions Source/Infra/EKWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class EKWindow: UIWindow {
}
backgroundColor = .clear
rootViewController = rootVC
accessibilityViewIsModal = true
}

required init?(coder aDecoder: NSCoder) {
Expand Down
8 changes: 4 additions & 4 deletions Source/MessageViews/MessagesUtils/EKButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ final class EKButtonView: UIView {
}

private func setupAcceessibility() {
isAccessibilityElement = true
accessibilityIdentifier = content.accessibilityIdentifier
accessibilityLabel = content.label.text
accessibilityTraits = [.button]
isAccessibilityElement = false
button.isAccessibilityElement = true
button.accessibilityIdentifier = content.accessibilityIdentifier
button.accessibilityLabel = content.label.text
}

private func setupButton() {
Expand Down

0 comments on commit ed78457

Please sign in to comment.