-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AttributedLabel Accessibility Links (#537)
This PR migrates `AttributedLabel`'s link rotor from a stateful to functional pattern, eliminating the need for two variables and preventing voiceover from getting out of sync. I also fixed a bug in `links(at location: CGPoint)` that could cause a crash if the `AttributedString` lacked a specified `NSTextAlignment`.
- Loading branch information
1 parent
8d51726
commit a70cf54
Showing
4 changed files
with
136 additions
and
38 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
BlueprintUI/Sources/Extensions/BidirectionalCollection+Blueprint.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import UIKit | ||
|
||
extension BidirectionalCollection where Element: Equatable & NSObjectProtocol { | ||
|
||
/// Returns a UIAccessibilityCustomRotor with the provided system type which cycles through the contained elements. | ||
public func accessibilityRotor(systemType type: UIAccessibilityCustomRotor.SystemRotorType) -> UIAccessibilityCustomRotor { | ||
UIAccessibilityCustomRotor(systemType: type) { itemSearch($0) } | ||
} | ||
|
||
private func itemSearch(_ predicate: UIAccessibilityCustomRotorSearchPredicate) -> UIAccessibilityCustomRotorItemResult? { | ||
guard let first else { return nil } | ||
guard let currentItem = predicate.currentItem.targetElement as? Element, | ||
let currentIndex = firstIndex(of: currentItem), | ||
predicate.searchDirection == .previous || predicate.searchDirection == .next | ||
else { | ||
return UIAccessibilityCustomRotorItemResult(targetElement: first, targetRange: nil) | ||
} | ||
let newIndex = (predicate.searchDirection == .next ? index(after: currentIndex) : index(before: currentIndex)) | ||
guard newIndex >= startIndex, newIndex < endIndex else { return nil } | ||
return .init(targetElement: self[newIndex], targetRange: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters