diff --git a/MVMCoreUI/Accessibility/AccessibilityHandler.swift b/MVMCoreUI/Accessibility/AccessibilityHandler.swift index 987eca37..0ed3348b 100644 --- a/MVMCoreUI/Accessibility/AccessibilityHandler.swift +++ b/MVMCoreUI/Accessibility/AccessibilityHandler.swift @@ -171,12 +171,17 @@ open class AccessibilityHandler { open func canPostAccessbilityNotification(for viewController: UIViewController) -> Bool { true } func getPreDefinedFocusedElementIfAny() -> UIView? { - guard let accessibilityId, let models: [any Identifiable] = (delegate?.delegateObject?() as? MVMCoreUIDelegateObject)?.moleculeDelegate?.getRootMolecules().allMoleculesOfType() else { return nil } - guard !models.isEmpty, - let model = (models.filter { ($0.id as? String) == accessibilityId }).first else { return nil } + guard let accessibilityId else { return nil } + var modelElement: MoleculeModelProtocol? + ((delegate?.delegateObject?() as? MVMCoreUIDelegateObject)?.moleculeDelegate)?.getRootMolecules().depthFirstTraverse(options: .leafNodesOnly, depth: 0) { index, model, stop in + if model.id == accessibilityId { + modelElement = model + stop = true + } + } return (delegate as? UIViewController)?.view?.getMoleculeViews { (subView: MoleculeViewProtocol) in - guard let moleculeModel = (subView as? MoleculeViewModelProtocol)?.moleculeModel as? (any Identifiable), - (moleculeModel.id as? String) == (model.id as? String) else { + guard let modelElement, let moleculeModel = (subView as? MoleculeViewModelProtocol)?.moleculeModel, + moleculeModel.id == modelElement.id else { return false } return true