-
Notifications
You must be signed in to change notification settings - Fork 43
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
chore: screenshot masking #146
Conversation
let redactedImage = UIGraphicsImageRenderer(size: image.size, format: .init(for: .init(displayScale: 1))).image { context in | ||
context.cgContext.interpolationQuality = .none | ||
image.draw(at: .zero) | ||
|
||
for rect in maskableWidgets { | ||
let path = UIBezierPath(roundedRect: rect, cornerRadius: 10) | ||
UIColor.black.setFill() | ||
path.fill() | ||
} | ||
} | ||
wireframe.base64 = imageToBase64(redactedImage) |
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.
possible optimization for the future, this can be done async but requires changing a few things and adjusting timestamps, if performance is an issue, this is a place to look at.
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've started doing this optimization but led me to do other things that also required to be in the main thread so the changes didn't make much effect, most likely we'll need to pay the memory footprint price instead of processing the images right away, so we can batch the process in background threads but pay the price of holding a copy of the images in memory which can lead to OOM quite quickly as well.
private let swiftUIImageTypes = ["_TtCOCV7SwiftUI11DisplayList11ViewUpdater8Platform13CGDrawingView", | ||
"_TtC7SwiftUIP33_A34643117F00277B93DEBAB70EC0697122_UIShapeHitTestingView", | ||
"SwiftUI._UIGraphicsView", "SwiftUI.ImageLayer"].compactMap { NSClassFromString($0) } |
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 wonder if this changes for every new release or something, some of them are auto-generated but that's the best I found so far.
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 suppose we won't know until we release but is there a chance that there are more auto-generated types in a customers app?
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.
Since the types are auto-generated, we cannot just do view as? SwiftUI.Text
similarly to UIKit.
So yeah I believe this is a moving thing that we'll discover more over time or new ones will come up within the next few SwiftUI versions, but those are the "root" auto-generated types that work well with the basic widgets at least.
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.
Some of them are mapped to the UIKit though, for example:
TextField -> UITextField
.
navigationTitle -> UILabel
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.
Looks great! Could certainly be a blog post or X thread. It's a cool technical solution that's pretty well contained in a single PR and easy to follow with a relative understanding of Swift
private let swiftUIImageTypes = ["_TtCOCV7SwiftUI11DisplayList11ViewUpdater8Platform13CGDrawingView", | ||
"_TtC7SwiftUIP33_A34643117F00277B93DEBAB70EC0697122_UIShapeHitTestingView", | ||
"SwiftUI._UIGraphicsView", "SwiftUI.ImageLayer"].compactMap { NSClassFromString($0) } |
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 suppose we won't know until we release but is there a chance that there are more auto-generated types in a customers app?
💡 Motivation and Context
💚 How did you test it?
Tests running with masking enabled and disabled, with SwiftUI and UIKit
📝 Checklist