converted to use real time rotor

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-08-25 14:35:20 -05:00
parent 3b9f43d1fd
commit de2171aedb

View File

@ -23,41 +23,12 @@ extension CustomRotorable {
accessibilityCustomRotors = (accessibilityCustomRotors ?? []).filter { $0.name != name }
//create new rotor
let newRotor = AccessibilityCustomRotor(with: name, for: trait, rootView: self.view)
//append rotor
accessibilityCustomRotors?.append(newRotor)
}
/// Loads all of the custom rotors for the screen.
public func loadCustomRotors() {
customRotors.forEach { addCustomRotor(with: $0.name, for: $0.trait) }
}
}
private class AccessibilityCustomRotor: UIAccessibilityCustomRotor {
var views: [UIView]?
var trait: UIAccessibilityTraits
weak var rootView: UIView?
init (with name: String, for trait: UIAccessibilityTraits, rootView: UIView){
self.rootView = rootView
self.trait = trait
super.init(name: name, itemSearch: { _ in return nil })
self.updateSearch()
}
func updateSearch() {
itemSearchBlock = { [weak self] predicate in
let newRotor = UIAccessibilityCustomRotor(name: name) { [weak self] predicate in
guard let self else { return nil }
guard let self, let rootView = self.rootView else { return nil }
let views = self.view.accessibleElements(with: trait)
//create the view accessibleElements cache if it doesn't exist
if self.views == nil {
self.views = rootView.accessibleElements(with: trait)
}
guard let views = self.views, !views.isEmpty else { return nil }
guard !views.isEmpty else { return nil }
let currentIndex = views.firstIndex(where: { $0 === predicate.currentItem.targetElement })
let count = views.count
@ -88,6 +59,14 @@ private class AccessibilityCustomRotor: UIAccessibilityCustomRotor {
return UIAccessibilityCustomRotorItemResult(targetElement: views[nextIndex], targetRange: nil)
}
//append rotor
accessibilityCustomRotors?.append(newRotor)
}
/// Loads all of the custom rotors for the screen.
public func loadCustomRotors() {
customRotors.forEach { addCustomRotor(with: $0.name, for: $0.trait) }
}
}