Add accessibility labels to markdown bar operations (#1030)

This commit is contained in:
Bas Broek
2017-11-21 21:00:46 +01:00
committed by Ryan Nystrom
parent 8723664af4
commit 14bed98d0f
2 changed files with 60 additions and 13 deletions

View File

@@ -44,6 +44,19 @@ final class IssueTextActionsCell: SelectableCell {
imageView.frame = contentView.bounds
}
func configure(operation: IssueTextActionOperation) {
imageView.image = operation.icon
imageView.accessibilityLabel = operation.name
}
override var accessibilityLabel: String? {
get {
return contentView.subviews
.flatMap { $0.accessibilityLabel }
.reduce("", { "\($0 ?? "").\n\($1)" }) }
set { }
}
}
protocol IssueTextActionsViewDelegate: class {
@@ -61,6 +74,7 @@ struct IssueTextActionOperation {
let icon: UIImage?
let operation: Operation
let name: String
}
@@ -113,7 +127,7 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as? IssueTextActionsCell
else { fatalError("Wrong cell type") }
cell.imageView.image = operations[indexPath.item].icon
cell.configure(operation: operations[indexPath.item])
return cell
}

View File

@@ -19,23 +19,56 @@ extension IssueTextActionsView {
supportsImageUpload: Bool
) -> IssueTextActionsView {
var operations: [IssueTextActionOperation] = [
IssueTextActionOperation(icon: UIImage(named: "bar-eye"), operation: .execute({ [weak viewController] in
IssueTextActionOperation(
icon: UIImage(named: "bar-eye"),
operation: .execute({ [weak viewController] in
let controller = IssuePreviewViewController(markdown: getMarkdownBlock(), owner: owner, repo: repo)
viewController?.navigationController?.pushViewController(controller, animated: true)
})),
IssueTextActionOperation(icon: UIImage(named: "bar-bold"), operation: .wrap("**", "**")),
IssueTextActionOperation(icon: UIImage(named: "bar-italic"), operation: .wrap("_", "_")),
IssueTextActionOperation(icon: UIImage(named: "bar-code"), operation: .wrap("`", "`")),
IssueTextActionOperation(icon: UIImage(named: "bar-code-block"), operation: .wrap("```\n", "\n```")),
IssueTextActionOperation(icon: UIImage(named: "bar-strikethrough"), operation: .wrap("~~", "~~")),
IssueTextActionOperation(icon: UIImage(named: "bar-header"), operation: .line("#")),
IssueTextActionOperation(icon: UIImage(named: "bar-ul"), operation: .line("- ")),
IssueTextActionOperation(icon: UIImage(named: "bar-indent"), operation: .line(" ")),
IssueTextActionOperation(icon: UIImage(named: "bar-link"), operation: .wrap("[", "](\(UITextView.cursorToken))"))
}),
name: NSLocalizedString("Message Preview", comment: "The name of the action for previewing a message from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-bold"),
operation: .wrap("**", "**"),
name: NSLocalizedString("Make text bold", comment: "The name of the action for making text bold from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-italic"),
operation: .wrap("_", "_"),
name: NSLocalizedString("Make text italic", comment: "The name of the action for making text italic from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-code"),
operation: .wrap("`", "`"),
name: NSLocalizedString("Make text monospaced", comment: "The name of the action for making text monospaced / appear as code from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-code-block"),
operation: .wrap("```\n", "\n```"),
name: NSLocalizedString("Make text appear as code", comment: "The name of the action for making text appear as code from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-strikethrough"),
operation: .wrap("~~", "~~"),
name: NSLocalizedString("Strikethrough text", comment: "The name of the action for making text strikethrough from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-header"),
operation: .line("#"),
name: NSLocalizedString("Add header to text", comment: "The name of the action for making text a header from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-ul"),
operation: .line("- "),
name: NSLocalizedString("Make text a list item", comment: "The name of the action for making text a list item from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-indent"),
operation: .line(" "),
name: NSLocalizedString("Make text indented", comment: "The name of the action for making text indented from the markdown actions bar")),
IssueTextActionOperation(
icon: UIImage(named: "bar-link"),
operation: .wrap("[", "](\(UITextView.cursorToken))"),
name: NSLocalizedString("Wrap text as URL", comment: "The name of the action to wrap text in a markdown URL from the markdown actions bar"))
]
if supportsImageUpload {
operations.append(IssueTextActionOperation(icon: UIImage(named: "bar-upload"), operation: .uploadImage))
operations.append(IssueTextActionOperation(
icon: UIImage(named: "bar-upload"),
operation: .uploadImage,
name: NSLocalizedString("Upload Image", comment: "The name of the action to upload an image from the markdown actions bar")))
}
let actions = IssueTextActionsView(operations: operations)