Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created December 7, 2019 08:35
Show Gist options
  • Save SergLam/b69ac98588c1a53a4b048d87b26ddc8c to your computer and use it in GitHub Desktop.
Save SergLam/b69ac98588c1a53a4b048d87b26ddc8c to your computer and use it in GitHub Desktop.
Easy XCUITest + Voice over setup using protocol, extension and Rswift
import Foundation
import Rswift // pod 'R.swift'
typealias Localizable = R.string.localizable
// NOTE: Contains accesibility identifiers (XCUITest) + accesibility labels (Voice over support)
struct Accessibility {
// MARK: Chat navigation bar
static let chatNavigationUserProfileImageId = "ChatNavigationBar.chatOpponentAvatar"
static func chatNavigationUserProfileImageLabel(_ name: String) -> String {
return Localizable.chatNavigationOtherUserImageAccesibility(name)
}
static func chatNavigationUserProfileImageHint(_ name: String) -> String {
return Localizable.chatNavigationOtherUserImageAccesibilityHint(name)
}
}
import UIKit
protocol AccessibilitySetupable: class {
func setupAccessibility()
}
extension UIView {
func setAccessibility(_ identifier: String?, _ label: String?, _ hint: String?) {
// NOTE: Important to enable user intaraction for view
// to make it interactable while Voice Over is enabled
self.isUserInteractionEnabled = label != nil
self.isAccessibilityElement = label != nil
self.accessibilityIdentifier = identifier
self.accessibilityLabel = label
self.accessibilityHint = hint
}
}
// MARK: - AccessibilitySetupable
extension ChatNavigationBar: AccessibilitySetupable {
func setupAccessibility() {
let label = Accessibility.chatNavigationUserProfileImageLabel(userNameLabel.text ?? "")
let hint = Accessibility.chatNavigationUserProfileImageHint(userNameLabel.text ?? "")
chatOpponentAvatar.setAccessibility(Accessibility.chatNavigationUserProfileImageId, label, hint)
}
}
// MARK: - Chat navigation bar
"chat-navigation.other-user-image.accesibility" = "%@ user image";
"chat-navigation.other-user-image.accesibility-hint" = "Double Tap to view %@ profile";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment