refactored code
This commit is contained in:
parent
00427f9e77
commit
6b2e29ae62
@ -179,11 +179,12 @@ open class AccessibilityHandler {
|
||||
stop = true
|
||||
}
|
||||
}
|
||||
return (delegate as? UIViewController)?.view?.getMoleculeViews { (subView: MoleculeViewProtocol) in
|
||||
return (delegate as? UIViewController)?.view?.getMoleculeViews { (subView: MoleculeViewProtocol, stop: inout Bool) in
|
||||
guard let modelElement, let moleculeModel = (subView as? MoleculeViewModelProtocol)?.moleculeModel,
|
||||
moleculeModel.id == modelElement.id else {
|
||||
return false
|
||||
}
|
||||
stop = true
|
||||
return true
|
||||
}.first
|
||||
}
|
||||
@ -242,9 +243,9 @@ open class AccessibilityHandlerBehavior: PageVisibilityBehavior {
|
||||
private func identifyAndPrepareRotors() {
|
||||
var rotorElements: [UIAccessibilityCustomRotor] = []
|
||||
let currentViewController = ((delegateObj?.moleculeDelegate as? MVMCoreViewManagerViewControllerProtocol)?.manager as? SubNavManagerController) ?? (delegateObj?.moleculeDelegate as? ViewController)
|
||||
for element in RotorType.allCases {
|
||||
if let elements = getTraitMappedElements(template: currentViewController, type: element),
|
||||
let rotor = createRotor(elements, for: element) {
|
||||
for type in RotorType.allCases {
|
||||
if let elements = getTraitMappedElements(template: currentViewController, type: type),
|
||||
let rotor = createRotor(elements, for: type) {
|
||||
rotorElements.append(rotor)
|
||||
}
|
||||
}
|
||||
@ -289,23 +290,23 @@ open class AccessibilityHandlerBehavior: PageVisibilityBehavior {
|
||||
return result
|
||||
})
|
||||
|
||||
let headerViewElements = currentViewController.tableView.tableHeaderView?.getMoleculeViews {
|
||||
(subView: MoleculeViewProtocol) in subView.accessibilityTraits.contains(type.trait)
|
||||
let headerViewElements = currentViewController.tableView.tableHeaderView?.getMoleculeViews { (subView: MoleculeViewProtocol, _) in
|
||||
subView.accessibilityTraits.contains(type.trait)
|
||||
} as? [Any] ?? []
|
||||
|
||||
let footerViewElements = currentViewController.tableView.tableFooterView?.getMoleculeViews {
|
||||
(subView: MoleculeViewProtocol) in subView.accessibilityTraits.contains(type.trait)
|
||||
let footerViewElements = currentViewController.tableView.tableFooterView?.getMoleculeViews { (subView: MoleculeViewProtocol, _) in
|
||||
subView.accessibilityTraits.contains(type.trait)
|
||||
} as? [Any] ?? []
|
||||
|
||||
let otherInteractiveElements = currentViewController.view?.getMoleculeViews(excludedViews: [tableView, tableView.tableFooterView, tableView.tableHeaderView]
|
||||
.compactMap { $0 }) { (subView: MoleculeViewProtocol) in
|
||||
.compactMap { $0 }) { (subView: MoleculeViewProtocol, _) in
|
||||
subView.accessibilityTraits.contains(type.trait)
|
||||
} as? [Any] ?? []
|
||||
|
||||
return headerViewElements + otherInteractiveElements + (rotorElements as [Any]) + footerViewElements
|
||||
} else if let currentViewController = template as? MoleculeStackTemplate { //Stack templates
|
||||
return currentViewController.view?.getMoleculeViews {
|
||||
(subView: MoleculeViewProtocol) in subView.accessibilityTraits.contains(type.trait)
|
||||
return currentViewController.view?.getMoleculeViews { (subView: MoleculeViewProtocol, _) in
|
||||
subView.accessibilityTraits.contains(type.trait)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -329,10 +330,10 @@ open class AccessibilityHandlerBehavior: PageVisibilityBehavior {
|
||||
var rotorElement = elements[self.currentRotorIndex - 1]
|
||||
if let element = rotorElement as? (model: MoleculeModelProtocol, indexPath: IndexPath) {
|
||||
tableView.scrollToRow(at: element.indexPath, at: .middle, animated: false)
|
||||
rotorElement = tableView.cellForRow(at: element.indexPath)?.getMoleculeViews {
|
||||
(subView: MoleculeViewProtocol) in subView.accessibilityTraits.contains(type.trait)
|
||||
}.filter {
|
||||
($0 as? MoleculeViewModelProtocol)?.moleculeModel?.id == element.model.id
|
||||
rotorElement = tableView.cellForRow(at: element.indexPath)?.getMoleculeViews { (subView: MoleculeViewProtocol, stop: inout Bool) in
|
||||
guard subView.accessibilityTraits.contains(type.trait), (subView as? MoleculeViewModelProtocol)?.moleculeModel?.id == element.model.id else { return false }
|
||||
stop = true
|
||||
return true
|
||||
}.first as Any
|
||||
}
|
||||
UIAccessibility.post(notification: .layoutChanged, argument: rotorElement)
|
||||
@ -369,9 +370,17 @@ extension UIView {
|
||||
}
|
||||
}
|
||||
|
||||
func getMoleculeViews<T>(excludedViews: [UIView]? = nil, filter: ((T) -> Bool)) -> [T] {
|
||||
return getNestedSubviews(excludedViews: excludedViews).compactMap {
|
||||
filter($0) ? $0 : nil
|
||||
func getMoleculeViews<T>(excludedViews: [UIView]? = nil, filter: ((T, inout Bool) -> Bool)) -> [T] {
|
||||
var stop = false
|
||||
var results: [T] = []
|
||||
for element: T in getNestedSubviews(excludedViews: excludedViews) {
|
||||
if filter(element, &stop) {
|
||||
results.append(element)
|
||||
}
|
||||
if stop {
|
||||
break
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user