updated rotor logic
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
a528dc291b
commit
883f9fffb4
@ -9,7 +9,6 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol CustomRotorable: UIViewController {
|
public protocol CustomRotorable: UIViewController {
|
||||||
var customRotorCache: [String: [UIView]] { get set }
|
|
||||||
var customRotors: [CustomRotorType] { get set }
|
var customRotors: [CustomRotorType] { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,15 +23,41 @@ extension CustomRotorable {
|
|||||||
accessibilityCustomRotors = (accessibilityCustomRotors ?? []).filter { $0.name != name }
|
accessibilityCustomRotors = (accessibilityCustomRotors ?? []).filter { $0.name != name }
|
||||||
|
|
||||||
//create new rotor
|
//create new rotor
|
||||||
let newRotor = UIAccessibilityCustomRotor(name: name) { [weak self] predicate in
|
let newRotor = AccessibilityCustomRotor(with: name, for: trait, rootView: self.view)
|
||||||
guard let self else { return 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) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
guard let self, let rootView = self.rootView else { return nil }
|
||||||
|
|
||||||
//create the view accessibleElements cache if it doesn't exist
|
//create the view accessibleElements cache if it doesn't exist
|
||||||
if self.customRotorCache[name] == nil {
|
if self.views == nil {
|
||||||
self.customRotorCache[name] = self.view.accessibleElements(with: trait)
|
self.views = rootView.accessibleElements(with: trait)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let views = self.customRotorCache[name], !views.isEmpty else { return nil }
|
guard let views = self.views, !views.isEmpty else { return nil }
|
||||||
|
|
||||||
let currentIndex = views.firstIndex(where: { $0 === predicate.currentItem.targetElement })
|
let currentIndex = views.firstIndex(where: { $0 === predicate.currentItem.targetElement })
|
||||||
let count = views.count
|
let count = views.count
|
||||||
@ -63,16 +88,6 @@ extension CustomRotorable {
|
|||||||
|
|
||||||
return UIAccessibilityCustomRotorItemResult(targetElement: views[nextIndex], targetRange: nil)
|
return UIAccessibilityCustomRotorItemResult(targetElement: views[nextIndex], targetRange: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
//append rotor
|
|
||||||
accessibilityCustomRotors?.append(newRotor)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Loads all of the custom rotors for the screen.
|
|
||||||
public func loadCustomRotors() {
|
|
||||||
customRotorCache.removeAll()
|
|
||||||
UIAccessibility.post(notification: .screenChanged, argument: nil)
|
|
||||||
customRotors.forEach { addCustomRotor(with: $0.name, for: $0.trait) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,6 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable ,
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var subscribers = Set<AnyCancellable>()
|
public var subscribers = Set<AnyCancellable>()
|
||||||
|
|
||||||
public var customRotorCache: [String: [UIView]] = [:]
|
|
||||||
public var customRotors: [CustomRotorType] = [
|
public var customRotors: [CustomRotorType] = [
|
||||||
CustomRotorType(name: "Links", trait: .link),
|
CustomRotorType(name: "Links", trait: .link),
|
||||||
CustomRotorType(name: "Buttons", trait: .button)
|
CustomRotorType(name: "Buttons", trait: .button)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user