Skip to content

Commit

Permalink
Merge pull request #4730 from wikimedia/native-editor-finalize-voice-…
Browse files Browse the repository at this point in the history
…over

Native Editor - Finalize VoiceOver labels
  • Loading branch information
mazevedofs authored Jan 30, 2024
2 parents c9d3461 + d035bc1 commit 95be67f
Show file tree
Hide file tree
Showing 35 changed files with 636 additions and 615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,71 +81,70 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView {
stackView.addArrangedSubview(primaryContainerView)
}

expandButton.isAccessibilityElement = false
expandButton.setImage(WKSFSymbolIcon.for(symbol: .chevronRightCircle), for: .normal)
expandButton.addTarget(self, action: #selector(tappedExpand), for: .touchUpInside)
expandButton.isAccessibilityElement = false
expandButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarExpandButtonAccessibility
updateExpandButtonVisibility()

formatTextButton.setImage(WKSFSymbolIcon.for(symbol: .textFormat))
formatTextButton.addTarget(self, action: #selector(tappedFormatText), for: .touchUpInside)
formatTextButton.accessibilityIdentifier = WKSourceEditorAccessibilityIdentifiers.current?.formatTextButton
formatTextButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonFormatText
formatTextButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarOpenTextFormatMenuButtonAccessibility

referenceButton.setImage(WKSFSymbolIcon.for(symbol: .quoteOpening))
referenceButton.addTarget(self, action: #selector(tappedReference), for: .touchUpInside)
referenceButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonCitation
referenceButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarReferenceButtonAccessibility

linkButton.setImage(WKSFSymbolIcon.for(symbol: .link))
linkButton.addTarget(self, action: #selector(tappedLink), for: .touchUpInside)
linkButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonLink
linkButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarLinkButtonAccessibility

templateButton.setImage(WKSFSymbolIcon.for(symbol: .curlybraces))
templateButton.addTarget(self, action: #selector(tappedTemplate), for: .touchUpInside)
templateButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonTemplate
templateButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarTemplateButtonAccessibility

imageButton.setImage(WKSFSymbolIcon.for(symbol: .photo))
imageButton.addTarget(self, action: #selector(tappedMedia), for: .touchUpInside)
imageButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonMedia
imageButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarImageButtonAccessibility

findInPageButton.setImage(WKSFSymbolIcon.for(symbol: .docTextMagnifyingGlass))
findInPageButton.addTarget(self, action: #selector(tappedFindInPage), for: .touchUpInside)
findInPageButton.accessibilityIdentifier = WKSourceEditorAccessibilityIdentifiers.current?.findButton
findInPageButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonFind
findInPageButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarFindButtonAccessibility

unorderedListButton.setImage(WKSFSymbolIcon.for(symbol: .listBullet))
unorderedListButton.addTarget(self, action: #selector(tappedUnorderedList), for: .touchUpInside)
unorderedListButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonListUnordered
unorderedListButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarListUnorderedButtonAccessibility

orderedListButton.setImage(WKSFSymbolIcon.for(symbol: .listNumber))
orderedListButton.addTarget(self, action: #selector(tappedOrderedList), for: .touchUpInside)
orderedListButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonListOrdered
orderedListButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarListOrderedButtonAccessibility

decreaseIndentionButton.setImage(WKSFSymbolIcon.for(symbol: .decreaseIndent))
decreaseIndentionButton.addTarget(self, action: #selector(tappedDecreaseIndentation), for: .touchUpInside)
decreaseIndentionButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonDecreaseIndent
decreaseIndentionButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarIndentDecreaseButtonAccessibility
decreaseIndentionButton.isEnabled = false

increaseIndentionButton.setImage(WKSFSymbolIcon.for(symbol: .increaseIndent))
increaseIndentionButton.addTarget(self, action: #selector(tappedIncreaseIndentation), for: .touchUpInside)
increaseIndentionButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonInceaseIndent
increaseIndentionButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarIndentIncreaseButtonAccessibility
increaseIndentionButton.isEnabled = false

cursorUpButton.setImage(WKSFSymbolIcon.for(symbol: .chevronUp))
cursorUpButton.addTarget(self, action: #selector(tappedCursorUp), for: .touchUpInside)
cursorUpButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonCursorUp
cursorUpButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarCursorUpButtonAccessibility

cursorDownButton.setImage(WKSFSymbolIcon.for(symbol: .chevronDown))
cursorDownButton.addTarget(self, action: #selector(tappedCursorDown), for: .touchUpInside)
cursorDownButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonCursorDown
cursorDownButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarCursorDownButtonAccessibility

cursorLeftButton.setImage(WKSFSymbolIcon.for(symbol: .chevronBackward))
cursorLeftButton.addTarget(self, action: #selector(tappedCursorLeft), for: .touchUpInside)
cursorLeftButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonCursorLeft
cursorLeftButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarCursorPreviousButtonAccessibility

cursorRightButton.setImage(WKSFSymbolIcon.for(symbol: .chevronForward))
cursorRightButton.addTarget(self, action: #selector(tappedCursorRight), for: .touchUpInside)
cursorRightButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonCursorRight
cursorRightButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.toolbarCursorNextButtonAccessibility

NotificationCenter.default.addObserver(self, selector: #selector(updateButtonSelectionState(_:)), name: Notification.WKSourceEditorSelectionState, object: nil)
}
Expand Down Expand Up @@ -187,8 +186,6 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView {
} else {
increaseIndentionButton.isEnabled = false
}

cursorRightButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelButtonCursorRight
}

// MARK: - Button Actions
Expand Down Expand Up @@ -225,6 +222,9 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView {

let buttonAnimator = UIViewPropertyAnimator(duration: 0.4, dampingRatio: 0.7, animations: buttonTransform)
let scrollViewAnimator = UIViewPropertyAnimator(duration: 0.2, curve: .easeInOut, animations: scrollViewContentOffsetChange)
scrollViewAnimator.addCompletion { [weak self] _ in
self?.updateExpandButtonVisibility()
}

buttonAnimator.startAnimation()
scrollViewAnimator.startAnimation()
Expand All @@ -233,9 +233,6 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView {
@objc private func tappedFormatText() {
delegate?.toolbarExpandingViewDidTapFormatText(toolbarView: self)
}

@objc private func tappedFormatHeading() {
}

@objc private func tappedReference() {
delegate?.toolbarExpandingViewDidTapReference(toolbarView: self, isSelected: referenceButton.isSelected)
Expand Down Expand Up @@ -293,6 +290,19 @@ class WKEditorToolbarExpandingView: WKEditorToolbarView {

private func updateExpandButtonVisibility() {
expandButton.isHidden = traitCollection.horizontalSizeClass == .regular

if expandButton.isHidden {
accessibilityElements = [formatTextButton as Any, referenceButton as Any, linkButton as Any, templateButton as Any, imageButton as Any, findInPageButton as Any, unorderedListButton as Any, orderedListButton as Any, decreaseIndentionButton as Any, increaseIndentionButton as Any, cursorUpButton as Any, cursorDownButton as Any, cursorLeftButton as Any, cursorRightButton as Any]
UIAccessibility.post(notification: .screenChanged, argument: formatTextButton)
} else {
if scrollView.contentOffset.x == 0 {
accessibilityElements = [formatTextButton as Any, referenceButton as Any, linkButton as Any, templateButton as Any, imageButton as Any, findInPageButton as Any, expandButton as Any]
UIAccessibility.post(notification: .screenChanged, argument: formatTextButton)
} else {
accessibilityElements = [unorderedListButton as Any, orderedListButton as Any, decreaseIndentionButton as Any, increaseIndentionButton as Any, cursorUpButton as Any, cursorDownButton as Any, cursorLeftButton as Any, cursorRightButton as Any, expandButton as Any]
UIAccessibility.post(notification: .screenChanged, argument: unorderedListButton)
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ class WKFindAndReplaceView: WKComponentView {
maximumContentSizeCategory = .accessibilityLarge

closeButton.setImage(WKSFSymbolIcon.for(symbol: .close), for: .normal)
closeButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelFindButtonClose
closeButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.findCloseButtonAccessibility
previousButton.setImage(WKSFSymbolIcon.for(symbol: .chevronUp), for: .normal)
previousButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelFindButtonPrevious
previousButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.findPreviousButtonAccessibility
previousButton.imageView?.contentMode = .center
nextButton.setImage(WKSFSymbolIcon.for(symbol: .chevronDown), for: .normal)
nextButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelFindButtonNext
nextButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.findNextButtonAccessibility
nextButton.imageView?.contentMode = .center

replaceButton.setImage(WKIcon.replace, for: .normal)
replaceButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceButtonPerformFormat, WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceTypeSingle)
replaceButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.replaceButtonAccessibilityFormat, WKSourceEditorLocalizedStrings.current.replaceTypeSingleAccessibility)

replaceButton.imageView?.contentMode = .center
replaceSwitchButton.setImage(WKSFSymbolIcon.for(symbol: .ellipsis), for: .normal)
replaceSwitchButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceButtonSwitchFormat, WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceTypeSingle)
replaceSwitchButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.replaceTypeButtonAccessibilityFormat, WKSourceEditorLocalizedStrings.current.replaceTypeSingleAccessibility)
replaceSwitchButton.imageView?.contentMode = .center

replaceSwitchButton.showsMenuAsPrimaryAction = true
Expand All @@ -82,22 +83,22 @@ class WKFindAndReplaceView: WKComponentView {
pencilImageView.contentMode = .center

findClearButton.setImage(WKSFSymbolIcon.for(symbol: .multiplyCircleFill), for: .normal)
findClearButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelFindButtonClear
findClearButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.findClearButtonAccessibility
findClearButton.imageView?.contentMode = .center
replaceClearButton.setImage(WKSFSymbolIcon.for(symbol: .multiplyCircleFill), for: .normal)
replaceClearButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceButtonClear
replaceClearButton.accessibilityLabel = WKSourceEditorLocalizedStrings.current.replaceClearButtonAccessibility
replaceClearButton.imageView?.contentMode = .center

findTextField.adjustsFontForContentSizeCategory = true
findTextField.font = WKFont.for(.caption1, compatibleWith: appEnvironment.traitCollection)
findTextField.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelFindTextField
findTextField.accessibilityLabel = WKSourceEditorLocalizedStrings.current.findTextFieldAccessibility
findTextField.autocorrectionType = .yes
findTextField.spellCheckingType = .yes
findTextField.delegate = self

replaceTextField.adjustsFontForContentSizeCategory = true
replaceTextField.font = WKFont.for(.caption1, compatibleWith: appEnvironment.traitCollection)
replaceTextField.accessibilityLabel = WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceTextField
replaceTextField.accessibilityLabel = WKSourceEditorLocalizedStrings.current.replaceTextFieldAccessibility
replaceTextField.autocorrectionType = .yes
replaceTextField.spellCheckingType = .yes
replaceTextField.delegate = self
Expand All @@ -107,12 +108,12 @@ class WKFindAndReplaceView: WKComponentView {

replaceTypeLabel.adjustsFontForContentSizeCategory = true
replaceTypeLabel.font = WKFont.for(.caption1, compatibleWith: appEnvironment.traitCollection)
replaceTypeLabel.text = WKSourceEditorLocalizedStrings.current.findReplaceTypeSingle
replaceTypeLabel.text = WKSourceEditorLocalizedStrings.current.replaceTypeSingle
replaceTypeLabel.isAccessibilityElement = false

replacePlaceholderLabel.adjustsFontForContentSizeCategory = true
replacePlaceholderLabel.font = WKFont.for(.caption1, compatibleWith: appEnvironment.traitCollection)
replacePlaceholderLabel.text = WKSourceEditorLocalizedStrings.current.findReplaceWith
replacePlaceholderLabel.text = WKSourceEditorLocalizedStrings.current.replaceTextfieldPlaceholder
replacePlaceholderLabel.isAccessibilityElement = false

updateColors()
Expand All @@ -136,6 +137,12 @@ class WKFindAndReplaceView: WKComponentView {
} else {
currentMatchInfoLabel.text = nil
}

if let currentMatchInfoAccessibility = viewModel.currentMatchInfoAccessibility {
currentMatchInfoLabel.accessibilityLabel = currentMatchInfoAccessibility
} else {
currentMatchInfoLabel.accessibilityLabel = currentMatchInfoLabel.text
}

nextButton.isEnabled = viewModel.nextPrevButtonsAreEnabled
previousButton.isEnabled = viewModel.nextPrevButtonsAreEnabled
Expand Down Expand Up @@ -286,19 +293,25 @@ class WKFindAndReplaceView: WKComponentView {
}

private func replaceSwitchButtonMenu() -> UIMenu {
let replace = UIAction(title: WKSourceEditorLocalizedStrings.current.findReplaceTypeSingle) { [weak self] _ in
let replace = UIAction(title: WKSourceEditorLocalizedStrings.current.replaceTypeSingle) { [weak self] _ in
self?.replaceType = .single
self?.replaceTypeLabel.text = WKSourceEditorLocalizedStrings.current.findReplaceTypeSingle
self?.replaceSwitchButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceButtonSwitchFormat, WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceTypeSingle)
self?.replaceTypeLabel.text = WKSourceEditorLocalizedStrings.current.replaceTypeSingle

self?.replaceButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.replaceButtonAccessibilityFormat, WKSourceEditorLocalizedStrings.current.replaceTypeSingleAccessibility)

self?.replaceSwitchButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.replaceTypeButtonAccessibilityFormat, WKSourceEditorLocalizedStrings.current.replaceTypeSingleAccessibility)
}

let replaceAll = UIAction(title: WKSourceEditorLocalizedStrings.current.findReplaceTypeAll) { [weak self] _ in
let replaceAll = UIAction(title: WKSourceEditorLocalizedStrings.current.replaceTypeAll) { [weak self] _ in
self?.replaceType = .all
self?.replaceTypeLabel.text = WKSourceEditorLocalizedStrings.current.findReplaceTypeAll
self?.replaceSwitchButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceButtonSwitchFormat, WKSourceEditorLocalizedStrings.current.accessibilityLabelReplaceTypeAll)
self?.replaceTypeLabel.text = WKSourceEditorLocalizedStrings.current.replaceTypeAll

self?.replaceButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.replaceButtonAccessibilityFormat, WKSourceEditorLocalizedStrings.current.replaceTypeAll)

self?.replaceSwitchButton.accessibilityLabel = String.localizedStringWithFormat(WKSourceEditorLocalizedStrings.current.replaceTypeButtonAccessibilityFormat, WKSourceEditorLocalizedStrings.current.replaceTypeAllAccessibility)
}

return UIMenu(title: WKSourceEditorLocalizedStrings.current.findReplaceTypeMenuTitle, children: [replace, replaceAll])
return UIMenu(title: WKSourceEditorLocalizedStrings.current.findAndReplaceTitle, children: [replace, replaceAll])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct WKFindAndReplaceViewModel {
}

var currentMatchInfo: String?
var currentMatchInfoAccessibility: String?
var matchCount: Int = 0
var nextPrevButtonsAreEnabled: Bool = false
var replaceButtonIsEnabled: Bool = false
Expand All @@ -16,6 +17,7 @@ struct WKFindAndReplaceViewModel {

mutating func reset() {
currentMatchInfo = nil
currentMatchInfoAccessibility = nil
nextPrevButtonsAreEnabled = false
}
}
Loading

0 comments on commit 95be67f

Please sign in to comment.