-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '250-add-redacted-rotor' into 'release/22.5'
Resolve "Add "redacted" rotor" Closes #250 See merge request highlighter/app!222
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Created by Geoff Pado on 7/1/22. | ||
// Copyright © 2022 Cocoatype, LLC. All rights reserved. | ||
|
||
import UIKit | ||
|
||
class RedactedWordObservationRotor: UIAccessibilityCustomRotor { | ||
init(accessibilityElements: [WordObservationAccessibilityElement]?) { | ||
super.init(name: Self.name) { predicate in | ||
guard let accessibilityElements = accessibilityElements, | ||
let currentItem = Result(result: predicate.currentItem), | ||
let currentItemIndex = accessibilityElements.firstIndex(of: currentItem.element) | ||
else { return nil } | ||
|
||
switch predicate.searchDirection { | ||
case .previous: | ||
return accessibilityElements[0..<currentItemIndex] | ||
.reversed() | ||
.first(where: \.isRedacted) | ||
.map(Result.init(element:)) | ||
case .next where currentItemIndex == accessibilityElements.endIndex - 1: | ||
return nil | ||
case .next: | ||
return accessibilityElements[(currentItemIndex + 1)..<accessibilityElements.endIndex] | ||
.first(where: \.isRedacted) | ||
.map(Result.init(element:)) | ||
@unknown default: | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
class Result: UIAccessibilityCustomRotorItemResult { | ||
let element: WordObservationAccessibilityElement | ||
init(element: WordObservationAccessibilityElement) { | ||
self.element = element | ||
super.init(targetElement: element, targetRange: nil) | ||
} | ||
|
||
convenience init?(result: UIAccessibilityCustomRotorItemResult) { | ||
guard let element = result.targetElement as? WordObservationAccessibilityElement | ||
else { return nil } | ||
|
||
self.init(element: element) | ||
} | ||
} | ||
|
||
private static let name = NSLocalizedString("RedactedWordObservationRotor.name", comment: "Name for the redacted words custom accessibility rotor") | ||
} |
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