Add a11y labels/hints to post list and settings

This commit is contained in:
Angelo Stavrow 2020-12-29 16:52:26 -05:00
parent 1d1d4927b3
commit 03a568cfdc
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
4 changed files with 54 additions and 29 deletions

View File

@ -20,33 +20,44 @@ struct PostListView: View {
) )
.toolbar { .toolbar {
ToolbarItem(placement: .primaryAction) { ToolbarItem(placement: .primaryAction) {
Button(action: { // We have to add a Spacer as a sibling view to the Button in some kind of Stack, so that any a11y
let managedPost = WFAPost(context: self.managedObjectContext) // modifiers are applied as expected: bug report filed as FB8956392.
managedPost.createdDate = Date() ZStack {
managedPost.title = "" Spacer()
managedPost.body = "" Button(action: {
managedPost.status = PostStatus.local.rawValue let managedPost = WFAPost(context: self.managedObjectContext)
managedPost.collectionAlias = nil managedPost.createdDate = Date()
switch model.preferences.font { managedPost.title = ""
case 1: managedPost.body = ""
managedPost.appearance = "sans" managedPost.status = PostStatus.local.rawValue
case 2: managedPost.collectionAlias = nil
managedPost.appearance = "wrap" switch model.preferences.font {
default: case 1:
managedPost.appearance = "serif" managedPost.appearance = "sans"
} case 2:
if let languageCode = Locale.current.languageCode { managedPost.appearance = "wrap"
managedPost.language = languageCode default:
managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft managedPost.appearance = "serif"
} }
withAnimation { if let languageCode = Locale.current.languageCode {
self.selectedCollection = nil managedPost.language = languageCode
self.showAllPosts = false managedPost.rtl = Locale.characterDirection(forLanguage: languageCode) == .rightToLeft
self.model.selectedPost = managedPost }
} withAnimation {
}, label: { self.selectedCollection = nil
Image(systemName: "square.and.pencil") self.showAllPosts = false
}) self.model.selectedPost = managedPost
}
}, label: {
Image(systemName: "square.and.pencil")
.scaleEffect(1.25) // These modifiers compensate for the resizing
.padding(.vertical, 12) // done to the Image (and the button tap target)
.padding(.leading, 12) // by the SwiftUI layout system from adding a
.padding(.trailing, 8) // Spacer in this ZStack (FB8956392).
})
.accessibilityLabel(Text("Compose"))
.accessibilityHint(Text("Compose a new local draft"))
}
} }
ToolbarItem(placement: .bottomBar) { ToolbarItem(placement: .bottomBar) {
HStack { HStack {
@ -55,6 +66,8 @@ struct PostListView: View {
}, label: { }, label: {
Image(systemName: "gear") Image(systemName: "gear")
}) })
.accessibilityLabel(Text("Settings"))
.accessibilityHint(Text("Open the Settings sheet"))
Spacer() Spacer()
Text(postCount == 1 ? "\(postCount) post" : "\(postCount) posts") Text(postCount == 1 ? "\(postCount) post" : "\(postCount) posts")
.foregroundColor(.secondary) .foregroundColor(.secondary)
@ -70,6 +83,8 @@ struct PostListView: View {
}, label: { }, label: {
Image(systemName: "arrow.clockwise") Image(systemName: "arrow.clockwise")
}) })
.accessibilityLabel(Text("Refresh Posts"))
.accessibilityHint(Text("Fetch changes from the server"))
.disabled(!model.account.isLoggedIn) .disabled(!model.account.isLoggedIn)
} }
} }

View File

@ -7,12 +7,12 @@
<key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key> <key>WriteFreely-MultiPlatform (iOS).xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>0</integer> <integer>1</integer>
</dict> </dict>
<key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key> <key>WriteFreely-MultiPlatform (macOS).xcscheme_^#shared#^_</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>1</integer> <integer>0</integer>
</dict> </dict>
</dict> </dict>
</dict> </dict>

View File

@ -9,6 +9,8 @@ struct RemoteChangePromptView: View {
@Environment(\.horizontalSizeClass) var horizontalSizeClass @Environment(\.horizontalSizeClass) var horizontalSizeClass
@State private var promptText: String = "This is placeholder prompt text. Replace it?" @State private var promptText: String = "This is placeholder prompt text. Replace it?"
@State private var promptIcon: Image = Image(systemName: "questionmark.square.dashed") @State private var promptIcon: Image = Image(systemName: "questionmark.square.dashed")
@State private var accessibilityLabel: String = "Replace"
@State private var accessibilityHint: String = "Replace this text with an accessibility hint"
@State var remoteChangeType: RemotePostChangeType @State var remoteChangeType: RemotePostChangeType
@State var buttonHandler: () -> Void @State var buttonHandler: () -> Void
@ -18,6 +20,8 @@ struct RemoteChangePromptView: View {
.font(horizontalSizeClass == .compact ? .caption : .body) .font(horizontalSizeClass == .compact ? .caption : .body)
.foregroundColor(.secondary) .foregroundColor(.secondary)
Button(action: buttonHandler, label: { promptIcon }) Button(action: buttonHandler, label: { promptIcon })
.accessibilityLabel(Text(accessibilityLabel))
.accessibilityHint(Text(accessibilityHint))
} }
.padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20)) .padding(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
.background(Color(UIColor.secondarySystemBackground)) .background(Color(UIColor.secondarySystemBackground))
@ -28,9 +32,13 @@ struct RemoteChangePromptView: View {
case .remoteCopyUpdated: case .remoteCopyUpdated:
promptText = "Newer copy on server. Replace local copy?" promptText = "Newer copy on server. Replace local copy?"
promptIcon = Image(systemName: "square.and.arrow.down") promptIcon = Image(systemName: "square.and.arrow.down")
accessibilityLabel = "Update post"
accessibilityHint = "Replace this post with the server version"
case .remoteCopyDeleted: case .remoteCopyDeleted:
promptText = "Post deleted from server. Delete local copy?" promptText = "Post deleted from server. Delete local copy?"
promptIcon = Image(systemName: "trash") promptIcon = Image(systemName: "trash")
accessibilityLabel = "Delete"
accessibilityHint = "Delete this post from your device"
} }
}) })
} }

View File

@ -15,6 +15,8 @@ struct SettingsHeaderView: View {
}, label: { }, label: {
Image(systemName: "xmark.circle") Image(systemName: "xmark.circle")
}) })
.accessibilityLabel(Text("Close"))
.accessibilityHint(Text("Dismiss the Settings sheet"))
} }
Text("WriteFreely v\(Bundle.main.appMarketingVersion) (build \(Bundle.main.appBuildVersion))") Text("WriteFreely v\(Bundle.main.appMarketingVersion) (build \(Bundle.main.appBuildVersion))")
.font(.caption) .font(.caption)