From bcb861a61b642bb1c93f4e5951b78eb4923e1b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Sat, 28 Dec 2024 23:48:23 +0900 Subject: [PATCH] Improve accessibility of EditPictureControl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- damus/Views/Profile/EditPictureControl.swift | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/damus/Views/Profile/EditPictureControl.swift b/damus/Views/Profile/EditPictureControl.swift index c891b327..0289c163 100644 --- 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 {