Skip to content

Commit

Permalink
[A11y][VoiceOver] Set accessibility value for the sheet expansion sta…
Browse files Browse the repository at this point in the history
…te (#2101)

* Set accessibility value for the sheet expansion state.

* PR Cleanup

---------

Co-authored-by: Des Marks <[email protected]>
  • Loading branch information
nodes11 and Des Marks authored Nov 5, 2024
1 parent 71df35b commit a4abfdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ 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)
}
}

/// A string to optionally customize the accessibility label of the bottom sheet handle.
/// 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)
}
}

Expand Down Expand Up @@ -496,6 +496,8 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr
super.viewDidAppear(animated)

tokenSet.update(fluentTheme)

updateResizingHandleViewAccessibility(for: currentExpansionState)
}

public override func viewDidLayoutSubviews() {
Expand Down Expand Up @@ -523,6 +525,7 @@ public class BottomSheetController: UIViewController, Shadowable, TokenizedContr
collapsedHeightInSafeArea = view.safeAreaLayoutGuide.layoutFrame.maxY - offset(for: .collapsed)

updateAppearance()

super.viewDidLayoutSubviews()
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit a4abfdb

Please sign in to comment.