Skip to content

Commit

Permalink
Merge pull request #517 from dive/Cover_all_generic_components_with_a…
Browse files Browse the repository at this point in the history
…ccessibility_identifiers

Cover all possible generic components with accessibility identifiers
AntonPalich authored Sep 24, 2018
2 parents 3e29fb1 + cd7374b commit aa67bac
Showing 11 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@ public protocol PhotoMessageViewModelProtocol: DecoratedMessageViewModelProtocol
var transferStatus: Observable<TransferStatus> { get set }
var image: Observable<UIImage?> { get set }
var imageSize: CGSize { get }
var cellAccessibilityIdentifier: String { get }
var bubbleAccessibilityIdentifier: String { get }
}

open class PhotoMessageViewModel<PhotoMessageModelT: PhotoMessageModelProtocol>: PhotoMessageViewModelProtocol {
@@ -56,6 +58,8 @@ open class PhotoMessageViewModel<PhotoMessageModelT: PhotoMessageModelProtocol>:
open var imageSize: CGSize {
return self.photoMessage.imageSize
}
public let cellAccessibilityIdentifier = "chatto.message.photo.cell"
public let bubbleAccessibilityIdentifier = "chatto.message.photo.bubble"
public let messageViewModel: MessageViewModelProtocol
open var isShowingFailedIcon: Bool {
return self.messageViewModel.isShowingFailedIcon || self.transferStatus.value == .failed
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ open class PhotoBubbleView: UIView, MaximumLayoutWidthSpecificable, BackgroundSi

public var photoMessageViewModel: PhotoMessageViewModelProtocol! {
didSet {
self.accessibilityIdentifier = self.photoMessageViewModel.bubbleAccessibilityIdentifier
self.updateViews()
}
}
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ public final class PhotoMessageCollectionViewCell: BaseMessageCollectionViewCell

public var photoMessageViewModel: PhotoMessageViewModelProtocol! {
didSet {
self.accessibilityIdentifier = self.photoMessageViewModel.cellAccessibilityIdentifier
self.messageViewModel = self.photoMessageViewModel
self.bubbleView.photoMessageViewModel = self.photoMessageViewModel
}
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ import Foundation

public protocol TextMessageViewModelProtocol: DecoratedMessageViewModelProtocol {
var text: String { get }
var cellAccessibilityIdentifier: String { get }
var bubbleAccessibilityIdentifier: String { get }
}

open class TextMessageViewModel<TextMessageModelT: TextMessageModelProtocol>: TextMessageViewModelProtocol {
@@ -34,6 +36,8 @@ open class TextMessageViewModel<TextMessageModelT: TextMessageModelProtocol>: Te
}
public let textMessage: TextMessageModelT
public let messageViewModel: MessageViewModelProtocol
public let cellAccessibilityIdentifier = "chatto.message.text.cell"
public let bubbleAccessibilityIdentifier = "chatto.message.text.bubble"

public init(textMessage: TextMessageModelT, messageViewModel: MessageViewModelProtocol) {
self.textMessage = textMessage
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ public final class TextBubbleView: UIView, MaximumLayoutWidthSpecificable, Backg

public var textMessageViewModel: TextMessageViewModelProtocol! {
didSet {
self.accessibilityIdentifier = self.textMessageViewModel.bubbleAccessibilityIdentifier
self.updateViews()
}
}
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ public final class TextMessageCollectionViewCell: BaseMessageCollectionViewCell<

public var textMessageViewModel: TextMessageViewModelProtocol! {
didSet {
self.accessibilityIdentifier = self.textMessageViewModel.cellAccessibilityIdentifier
self.messageViewModel = self.textMessageViewModel
self.bubbleView.textMessageViewModel = self.textMessageViewModel
}
2 changes: 2 additions & 0 deletions ChattoAdditions/Source/Input/ChatInputBar.swift
Original file line number Diff line number Diff line change
@@ -220,6 +220,7 @@ extension ChatInputBar {
self.textView.placeholderText = appearance.textInputAppearance.placeholderText
self.textView.layer.borderColor = appearance.textInputAppearance.borderColor.cgColor
self.textView.layer.borderWidth = appearance.textInputAppearance.borderWidth
self.textView.accessibilityIdentifier = appearance.textInputAppearance.accessibilityIdentifier
self.tabBarInterItemSpacing = appearance.tabBarAppearance.interItemSpacing
self.tabBarContentInsets = appearance.tabBarAppearance.contentInsets
self.sendButton.contentEdgeInsets = appearance.sendButtonAppearance.insets
@@ -228,6 +229,7 @@ extension ChatInputBar {
self.sendButton.setTitleColor(color, for: state.controlState)
}
self.sendButton.titleLabel?.font = appearance.sendButtonAppearance.font
self.sendButton.accessibilityIdentifier = appearance.sendButtonAppearance.accessibilityIdentifier
self.tabBarContainerHeightConstraint.constant = appearance.tabBarAppearance.height
}
}
2 changes: 2 additions & 0 deletions ChattoAdditions/Source/Input/ChatInputBarAppearance.swift
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ public struct ChatInputBarAppearance {
UIControlStateWrapper(state: .normal): UIColor.bma_color(rgb: 0x007AFF),
UIControlStateWrapper(state: .highlighted): UIColor.bma_color(rgb: 0x007AFF).bma_blendWithColor(UIColor.white.withAlphaComponent(0.4))
]
public let accessibilityIdentifier = "chatto.inputbar.button.send"
}

public struct TabBarAppearance {
@@ -50,6 +51,7 @@ public struct ChatInputBarAppearance {
public var placeholderColor = UIColor.gray
public var placeholderText = ""
public var textInsets = UIEdgeInsets(top: 8, left: 0, bottom: 8, right: 0)
public let accessibilityIdentifier = "chatto.inputbar.inputfield.text"
}

public var sendButtonAppearance = SendButtonAppearance()
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ public struct LiveCameraCellAppearance {
public var backgroundColor: UIColor
public var cameraImageProvider: () -> UIImage?
public var cameraLockImageProvider: () -> UIImage?
public let accessibilityIdentifier = "chatto.inputbar.photos.cell.livecamera"

public init(backgroundColor: UIColor,
cameraImage: @autoclosure @escaping () -> UIImage?,
@@ -116,6 +117,7 @@ class LiveCameraCell: UICollectionViewCell {

private func updateAppearance() {
self.contentView.backgroundColor = self.appearance.backgroundColor
self.accessibilityIdentifier = self.appearance.accessibilityIdentifier
self.updateIcon()
}

Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ final class PhotosInputCell: UICollectionViewCell {
static let loadingIndicatorBackgoroundColor = UIColor.black.withAlphaComponent(0.70)
static let loadingIndicatorProgressColor = UIColor.white
static let loadingIncicatorProgressWidth: CGFloat = 1
static let accessibilityIdentifier = "chatto.inputbar.photos.cell.photo"
}

override init(frame: CGRect) {
@@ -50,6 +51,7 @@ final class PhotosInputCell: UICollectionViewCell {
self.imageView.contentMode = .scaleAspectFill
self.contentView.addSubview(self.imageView)
self.contentView.backgroundColor = Constants.backgroundColor
self.accessibilityIdentifier = Constants.accessibilityIdentifier
}

override func layoutSubviews() {
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ final class PhotosInputPlaceholderCell: UICollectionViewCell {
private struct Constants {
static let backgroundColor = UIColor(red: 231.0/255.0, green: 236.0/255.0, blue: 242.0/255.0, alpha: 1)
static let imageName = "lock"
static let accessibilityIdentifier = "chatto.inputbar.photos.cell.placeholder"
}

override init(frame: CGRect) {
@@ -48,6 +49,7 @@ final class PhotosInputPlaceholderCell: UICollectionViewCell {
self.imageView.image = UIImage(named: Constants.imageName, in: Bundle(for: PhotosInputPlaceholderCell.self), compatibleWith: nil)
self.contentView.addSubview(self.imageView)
self.contentView.backgroundColor = Constants.backgroundColor
self.accessibilityIdentifier = Constants.accessibilityIdentifier
}

override func layoutSubviews() {

0 comments on commit aa67bac

Please sign in to comment.