Merge pull request #521 from j-f1/compose-a11y

Improve accessibility of the compose view
This commit is contained in:
CMK 2022-11-14 19:54:08 +08:00 committed by GitHub
commit 099ad41d69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 106 additions and 2 deletions

View File

@ -68,6 +68,28 @@
<string>%ld characters</string> <string>%ld characters</string>
</dict> </dict>
</dict> </dict>
<key>a11y.plural.count.characters_left</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@character_count@ left</string>
<key>character_count</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>ld</string>
<key>zero</key>
<string>no characters</string>
<key>one</key>
<string>1 character</string>
<key>few</key>
<string>%ld characters</string>
<key>many</key>
<string>%ld characters</string>
<key>other</key>
<string>%ld characters</string>
</dict>
</dict>
<key>plural.count.followed_by_and_mutual</key> <key>plural.count.followed_by_and_mutual</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>

View File

@ -50,6 +50,28 @@
<string>%ld characters</string> <string>%ld characters</string>
</dict> </dict>
</dict> </dict>
<key>a11y.plural.count.characters_left</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@character_count@ left</string>
<key>character_count</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>ld</string>
<key>zero</key>
<string>no characters</string>
<key>one</key>
<string>1 character</string>
<key>few</key>
<string>%ld characters</string>
<key>many</key>
<string>%ld characters</string>
<key>other</key>
<string>%ld characters</string>
</dict>
</dict>
<key>plural.count.followed_by_and_mutual</key> <key>plural.count.followed_by_and_mutual</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>

View File

@ -413,7 +413,9 @@
"custom_emoji_picker": "Custom Emoji Picker", "custom_emoji_picker": "Custom Emoji Picker",
"enable_content_warning": "Enable Content Warning", "enable_content_warning": "Enable Content Warning",
"disable_content_warning": "Disable Content Warning", "disable_content_warning": "Disable Content Warning",
"post_visibility_menu": "Post Visibility Menu" "post_visibility_menu": "Post Visibility Menu",
"post_options": "Post Options",
"posting_as": "Posting as %s"
}, },
"keyboard": { "keyboard": {
"discard_post": "Discard Post", "discard_post": "Discard Post",

View File

@ -417,7 +417,9 @@
"custom_emoji_picker": "Custom Emoji Picker", "custom_emoji_picker": "Custom Emoji Picker",
"enable_content_warning": "Enable Content Warning", "enable_content_warning": "Enable Content Warning",
"disable_content_warning": "Disable Content Warning", "disable_content_warning": "Disable Content Warning",
"post_visibility_menu": "Post Visibility Menu" "post_visibility_menu": "Post Visibility Menu",
"post_options": "Post Options",
"posting_as": "Posting as %s"
}, },
"keyboard": { "keyboard": {
"discard_post": "Discard Post", "discard_post": "Discard Post",

View File

@ -449,6 +449,12 @@ public enum L10n {
public static let disableContentWarning = L10n.tr("Localizable", "Scene.Compose.Accessibility.DisableContentWarning") public static let disableContentWarning = L10n.tr("Localizable", "Scene.Compose.Accessibility.DisableContentWarning")
/// Enable Content Warning /// Enable Content Warning
public static let enableContentWarning = L10n.tr("Localizable", "Scene.Compose.Accessibility.EnableContentWarning") public static let enableContentWarning = L10n.tr("Localizable", "Scene.Compose.Accessibility.EnableContentWarning")
/// Posting as %@
public static func postingAs(_ p1: Any) -> String {
return L10n.tr("Localizable", "Scene.Compose.Accessibility.PostingAs", String(describing: p1))
}
/// Post Options
public static let postOptions = L10n.tr("Localizable", "Scene.Compose.Accessibility.PostOptions")
/// Post Visibility Menu /// Post Visibility Menu
public static let postVisibilityMenu = L10n.tr("Localizable", "Scene.Compose.Accessibility.PostVisibilityMenu") public static let postVisibilityMenu = L10n.tr("Localizable", "Scene.Compose.Accessibility.PostVisibilityMenu")
/// Remove Poll /// Remove Poll
@ -1276,6 +1282,10 @@ public enum L10n {
public enum A11y { public enum A11y {
public enum Plural { public enum Plural {
public enum Count { public enum Count {
/// Plural format key: "%#@character_count@ left"
public static func charactersLeft(_ p1: Int) -> String {
return L10n.tr("Localizable", "a11y.plural.count.characters_left", p1)
}
/// Plural format key: "Input limit exceeds %#@character_count@" /// Plural format key: "Input limit exceeds %#@character_count@"
public static func inputLimitExceeds(_ p1: Int) -> String { public static func inputLimitExceeds(_ p1: Int) -> String {
return L10n.tr("Localizable", "a11y.plural.count.input_limit_exceeds", p1) return L10n.tr("Localizable", "a11y.plural.count.input_limit_exceeds", p1)

View File

@ -161,7 +161,9 @@ Your profile looks like this to them.";
"Scene.Compose.Accessibility.CustomEmojiPicker" = "Custom Emoji Picker"; "Scene.Compose.Accessibility.CustomEmojiPicker" = "Custom Emoji Picker";
"Scene.Compose.Accessibility.DisableContentWarning" = "Disable Content Warning"; "Scene.Compose.Accessibility.DisableContentWarning" = "Disable Content Warning";
"Scene.Compose.Accessibility.EnableContentWarning" = "Enable Content Warning"; "Scene.Compose.Accessibility.EnableContentWarning" = "Enable Content Warning";
"Scene.Compose.Accessibility.PostOptions" = "Post Options";
"Scene.Compose.Accessibility.PostVisibilityMenu" = "Post Visibility Menu"; "Scene.Compose.Accessibility.PostVisibilityMenu" = "Post Visibility Menu";
"Scene.Compose.Accessibility.PostingAs" = "Posting as %@";
"Scene.Compose.Accessibility.RemovePoll" = "Remove Poll"; "Scene.Compose.Accessibility.RemovePoll" = "Remove Poll";
"Scene.Compose.Attachment.AttachmentBroken" = "This %@ is broken and cant be "Scene.Compose.Attachment.AttachmentBroken" = "This %@ is broken and cant be
uploaded to Mastodon."; uploaded to Mastodon.";

View File

@ -50,6 +50,28 @@
<string>%ld characters</string> <string>%ld characters</string>
</dict> </dict>
</dict> </dict>
<key>a11y.plural.count.characters_left</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@character_count@ left</string>
<key>character_count</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>ld</string>
<key>zero</key>
<string>no characters</string>
<key>one</key>
<string>1 character</string>
<key>few</key>
<string>%ld characters</string>
<key>many</key>
<string>%ld characters</string>
<key>other</key>
<string>%ld characters</string>
</dict>
</dict>
<key>plural.count.followed_by_and_mutual</key> <key>plural.count.followed_by_and_mutual</key>
<dict> <dict>
<key>NSStringLocalizedFormatKey</key> <key>NSStringLocalizedFormatKey</key>

View File

@ -123,4 +123,19 @@ extension ComposeContentToolbarView.ViewModel {
return action.inactiveImage return action.inactiveImage
} }
} }
func label(for action: Action) -> String {
switch action {
case .attachment:
return L10n.Scene.Compose.Accessibility.appendAttachment
case .poll:
return isPollActive ? L10n.Scene.Compose.Accessibility.removePoll : L10n.Scene.Compose.Accessibility.appendPoll
case .emoji:
return L10n.Scene.Compose.Accessibility.customEmojiPicker
case .contentWarning:
return isContentWarningActive ? L10n.Scene.Compose.Accessibility.disableContentWarning : L10n.Scene.Compose.Accessibility.enableContentWarning
case .visibility:
return L10n.Scene.Compose.Accessibility.postVisibilityMenu
}
}
} }

View File

@ -63,6 +63,7 @@ struct ComposeContentToolbarView: View {
} }
} label: { } label: {
label(for: viewModel.visibility.image) label(for: viewModel.visibility.image)
.accessibilityLabel(L10n.Scene.Compose.Keyboard.selectVisibilityEntry(viewModel.visibility.title))
} }
.frame(width: 48, height: 48) .frame(width: 48, height: 48)
case .poll: case .poll:
@ -98,11 +99,14 @@ struct ComposeContentToolbarView: View {
Text("\(remains)") Text("\(remains)")
.foregroundColor(Color(isOverflow ? UIColor.systemRed : UIColor.secondaryLabel)) .foregroundColor(Color(isOverflow ? UIColor.systemRed : UIColor.secondaryLabel))
.font(.system(size: isOverflow ? 18 : 16, weight: isOverflow ? .medium : .regular)) .font(.system(size: isOverflow ? 18 : 16, weight: isOverflow ? .medium : .regular))
.accessibilityLabel(L10n.A11y.Plural.Count.charactersLeft(remains))
} }
.padding(.leading, 4) // 4 + 12 = 16 .padding(.leading, 4) // 4 + 12 = 16
.padding(.trailing, 16) .padding(.trailing, 16)
.frame(height: ComposeContentToolbarView.toolbarHeight) .frame(height: ComposeContentToolbarView.toolbarHeight)
.background(Color(viewModel.backgroundColor)) .background(Color(viewModel.backgroundColor))
.accessibilityElement(children: .contain)
.accessibilityLabel(L10n.Scene.Compose.Accessibility.postOptions)
} }
} }
@ -112,6 +116,7 @@ extension ComposeContentToolbarView {
Image(uiImage: viewModel.image(for: action)) Image(uiImage: viewModel.image(for: action))
.foregroundColor(Color(Asset.Scene.Compose.buttonTint.color)) .foregroundColor(Color(Asset.Scene.Compose.buttonTint.color))
.frame(width: 24, height: 24, alignment: .center) .frame(width: 24, height: 24, alignment: .center)
.accessibilityLabel(viewModel.label(for: action))
} }
func label(for image: UIImage) -> some View { func label(for image: UIImage) -> some View {

View File

@ -167,6 +167,8 @@ extension ComposeContentView {
} }
Spacer() Spacer()
} }
.accessibilityElement(children: .ignore)
.accessibilityLabel(L10n.Scene.Compose.Accessibility.postingAs([viewModel.name.string, viewModel.username].joined(separator: ", ")))
} }
} }