From a4abfdb616fe20ca6e8d2f9fc38e42f40ccb5293 Mon Sep 17 00:00:00 2001 From: Des Marks Date: Tue, 5 Nov 2024 15:18:01 -0800 Subject: [PATCH] [A11y][VoiceOver] Set accessibility value for the sheet expansion state (#2101) * Set accessibility value for the sheet expansion state. * PR Cleanup --------- Co-authored-by: Des Marks --- .../Bottom Sheet/BottomSheetController.swift | 23 +++++++++++-------- .../Localization/en.lproj/Localizable.strings | 4 ++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Sources/FluentUI_iOS/Components/Bottom Sheet/BottomSheetController.swift b/Sources/FluentUI_iOS/Components/Bottom Sheet/BottomSheetController.swift index 00a08e2c75..a0161c5e02 100644 --- a/Sources/FluentUI_iOS/Components/Bottom Sheet/BottomSheetController.swift +++ b/Sources/FluentUI_iOS/Components/Bottom Sheet/BottomSheetController.swift @@ -174,7 +174,7 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr /// The message should convey the "Expand" action and will be used when the bottom sheet is collapsed. @objc public var handleExpandCustomAccessibilityLabel: String? { didSet { - updateResizingHandleViewAccessibility() + updateResizingHandleViewAccessibility(for: currentExpansionState) } } @@ -182,7 +182,7 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr /// The message should convey the "Collapse" action and will be used when the bottom sheet is expanded. @objc public var handleCollapseCustomAccessibilityLabel: String? { didSet { - updateResizingHandleViewAccessibility() + updateResizingHandleViewAccessibility(for: currentExpansionState) } } @@ -496,6 +496,8 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr super.viewDidAppear(animated) tokenSet.update(fluentTheme) + + updateResizingHandleViewAccessibility(for: currentExpansionState) } public override func viewDidLayoutSubviews() { @@ -523,6 +525,7 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr collapsedHeightInSafeArea = view.safeAreaLayoutGuide.layoutFrame.maxY - offset(for: .collapsed) updateAppearance() + super.viewDidLayoutSubviews() } @@ -667,13 +670,15 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr move(to: isExpanded ? .collapsed : .expanded, interaction: .resizingHandleTap) } - private func updateResizingHandleViewAccessibility() { - if currentExpansionState == .expanded { + private func updateResizingHandleViewAccessibility(for state: BottomSheetExpansionState) { + if state == .expanded { resizingHandleView.accessibilityLabel = handleCollapseCustomAccessibilityLabel ?? "Accessibility.Drawer.ResizingHandle.Label.Collapse".localized resizingHandleView.accessibilityHint = "Accessibility.Drawer.ResizingHandle.Hint.Collapse".localized - } else { + resizingHandleView.accessibilityValue = "Accessibility.Drawer.ResizingHandle.Value.Expanded".localized + } else if state == .collapsed { resizingHandleView.accessibilityLabel = handleExpandCustomAccessibilityLabel ?? "Accessibility.Drawer.ResizingHandle.Label.Expand".localized resizingHandleView.accessibilityHint = "Accessibility.Drawer.ResizingHandle.Hint.Expand".localized + resizingHandleView.accessibilityValue = "Accessibility.Drawer.ResizingHandle.Value.Collapsed".localized } } @@ -933,6 +938,8 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr completeAnimationsIfNeeded() + updateResizingHandleViewAccessibility(for: targetExpansionState) + if currentSheetVerticalOffset != offset(for: targetExpansionState) { delegate?.bottomSheetController?(self, willMoveTo: targetExpansionState, interaction: interaction) @@ -1173,11 +1180,7 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr private var currentStateChangeAnimator: UIViewPropertyAnimator? - private var currentExpansionState: BottomSheetExpansionState = .collapsed { - didSet { - updateResizingHandleViewAccessibility() - } - } + private var currentExpansionState: BottomSheetExpansionState = .collapsed private var targetExpansionState: BottomSheetExpansionState? diff --git a/Sources/FluentUI_iOS/Resources/Localization/en.lproj/Localizable.strings b/Sources/FluentUI_iOS/Resources/Localization/en.lproj/Localizable.strings index d74480ba92..e3d54c67d0 100644 --- a/Sources/FluentUI_iOS/Resources/Localization/en.lproj/Localizable.strings +++ b/Sources/FluentUI_iOS/Resources/Localization/en.lproj/Localizable.strings @@ -82,10 +82,14 @@ "Accessibility.Drawer.ResizingHandle.Label.Expand" = "Expand"; /* Accessibility hint for drawer's resizing handle when it has expand action */ "Accessibility.Drawer.ResizingHandle.Hint.Expand" = "Double tap to expand"; +/* Accessibility value for drawer's resizing handle when the sheet is in a collapsed state */ +"Accessibility.Drawer.ResizingHandle.Value.Collapsed" = "Collapsed"; /* Accessibility label for drawer's resizing handle when it has collapse action */ "Accessibility.Drawer.ResizingHandle.Label.Collapse" = "Collapse"; /* Accessibility hint for drawer's resizing handle when it has collapse action */ "Accessibility.Drawer.ResizingHandle.Hint.Collapse" = "Double tap to collapse"; +/* Accessibility value for drawer's resizing handle when the sheet is in a expanded state */ +"Accessibility.Drawer.ResizingHandle.Value.Expanded" = "Expanded"; /* Accessibility label for when a task under progress has finished */ "Accessibility.HUD.Done" = "Done";