commit bcb861a61b642bb1c93f4e5951b78eb4923e1b65
parent bb0ad18913c9aa28adb4b39b653e355917f5aa74
Author: Daniel D’Aquino <daniel@daquino.me>
Date: Sat, 28 Dec 2024 23:48:23 +0900
Improve accessibility of EditPictureControl
This commit improves accessibility of EditPictureControl, by adding
better accessibility labels and hints.
Changelog-Added: Minor accessibility improvements around picture editing and onboarding
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Diffstat:
1 file changed, 51 insertions(+), 0 deletions(-)
diff --git a/damus/Views/Profile/EditPictureControl.swift b/damus/Views/Profile/EditPictureControl.swift
@@ -74,6 +74,9 @@ struct EditPictureControl: View {
self.default_view
}
}
+ .accessibilityLabel(self.accessibility_label)
+ .accessibilityHint(self.accessibility_hint)
+ .maybeAccessibilityValue(self.accessibility_value)
.sheet(isPresented: self.model.show_camera) {
CameraController(uploader: model.uploader, mode: .handle_image(handler: { image in
self.model.request_upload_authorization(PreUploadedMedia.uiimage(image))
@@ -265,6 +268,46 @@ struct EditPictureControl: View {
})
}
}
+
+
+ // MARK: Accesibility helpers
+
+ var accessibility_label: String {
+ switch self.model.context {
+ case .normal:
+ return NSLocalizedString("Edit Image", comment: "Accessibility label for a button that edits an image")
+ case .profile_picture:
+ return NSLocalizedString("Edit profile picture", comment: "Accessibility label for a button that edits a profile picture")
+ }
+ }
+
+ var accessibility_hint: String {
+ return NSLocalizedString("Shows options to edit the image", comment: "Accessibility hint for a button that edits an image")
+ }
+
+ var accessibility_value: String? {
+ if style.first_time_setup {
+ if let current_image_url = model.current_image_url {
+ switch self.model.context {
+ case .normal:
+ return NSLocalizedString("Image is setup", comment: "Accessibility value on image control")
+ case .profile_picture:
+ return NSLocalizedString("Profile picture is setup", comment: "Accessibility value on profile picture image control")
+ }
+ }
+ else {
+ switch self.model.context {
+ case .normal:
+ return NSLocalizedString("No image is currently setup", comment: "Accessibility value on image control")
+ case .profile_picture:
+ return NSLocalizedString("No profile picture is currently setup", comment: "Accessibility value on profile picture image control")
+ }
+ }
+ }
+ else {
+ return nil // Image is shown outside this control and will have its accessibility defined outside this view.
+ }
+ }
}
@@ -693,6 +736,14 @@ fileprivate extension UIImage {
}
}
+fileprivate extension View {
+ func maybeAccessibilityValue(_ value: String?) -> some View {
+ Group {
+ if let value { self.accessibilityValue(value) } else { self }
+ }
+ }
+}
+
// MARK: - Previews
struct EditPictureControl_Previews: PreviewProvider {