-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add utilities for highlighting hit test regions #119
Conversation
...a/xcbaselines/607FACE41AFB9204008FA782.xcbaseline/0ADA261E-8CFD-4310-97E4-144F678F7C59.plist
Outdated
Show resolved
Hide resolved
ec833a8
to
403fd06
Compare
403fd06
to
c668896
Compare
0a2c426
to
cff0bb8
Compare
<key>com.apple.XCTPerformanceMetric_WallClockTime</key> | ||
<dict> | ||
<key>baselineAverage</key> | ||
<real>48.792810</real> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now this is very slow, but I have some plans for speeding it up (with the trade-off of potentially missing very small touch targets). I wanted to land this version first so we have a baseline for the extremely accurate version and can iterate from here.
4631461
to
9f7f45b
Compare
88581fb
to
85ffea5
Compare
This adds new snapshotting methods for drawing the snapshotted view with hit test regions highlighted.
85ffea5
to
907e743
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
@@ -786,161 +785,6 @@ private extension AccessibilitySnapshotView { | |||
|
|||
// MARK: - | |||
|
|||
private extension UIView { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for other reviewers: these methods are just being moved (without any edits) to new files
var lastHit: (CGFloat, UIView?)? = nil | ||
|
||
// Step through every pixel along the X axis. | ||
for x in stride(from: bounds.minX, to: bounds.maxX, by: pixelWidth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine this nested loop is a factor in the slow performance you commented on above. If we knew beforehand that all of the hit targets in question were rectangular, we could probably optimize this to just look for the overall width/height of the target, but this scanning seems necessary for anything non-rectangular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...sure enough, this is addressed in #177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, exactly. Guaranteed rectangular hit targets would make this way easier, but given how flexible the hit test APIs are, this is the only way I can think of to ensure we always get it correct.
|
||
private func monochromeSnapshot(for snapshot: UIImage) throws -> UIImage? { | ||
if ProcessInfo().operatingSystemVersion.majorVersion == 13 { | ||
// On iOS 13, the image filter silently fails for large images, "successfully" producing a blank output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotta love when xcode fails successfully
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't even understand why it has to here. It could just return a nil outputImage, but nope 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it!
This introduces new snapshotting methods for snapshotting a view with its hit targets highlighted.