Skip to content
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

fix: Masking for fast animations #4574

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Session replay touch tracking race condition (#4548)
- Session replay transformed view masking (#4529)
- Load integration from same binary (#4541)
- Masking for fast animations #4574


### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,39 @@ class SRRedactSampleViewController: UIViewController {

@IBOutlet var label: UILabel!

private let animatedLabel: UILabel = {
let label = UILabel()
label.text = "Animated"
label.sizeToFit()
return label
}()

private var continueAnimating = true

override func viewDidLoad() {
super.viewDidLoad()

notRedactedView.backgroundColor = .green
notRedactedView.transform = CGAffineTransform(rotationAngle: 45 * .pi / 180.0)
SentrySDK.replay.unmaskView(notRedactedLabel)
}

animatedLabel.frame = CGRect(origin: .zero, size: animatedLabel.frame.size)
view.addSubview(animatedLabel)
animate()

}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
continueAnimating = false
}

private func animate() {
UIView.animate(withDuration: 0.3, delay: 0, options: [.repeat, .autoreverse], animations: { [weak self] in
guard let self = self else { return }
self.animatedLabel.frame = CGRect(
origin: CGPoint(x: 0, y: self.view.frame.height),
size: self.animatedLabel.frame.size)
})
}
}
2 changes: 1 addition & 1 deletion Sources/Swift/Tools/SentryViewPhotographer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class SentryViewPhotographer: NSObject, SentryViewScreenshotProvider {
}

func image(view: UIView, options: SentryRedactOptions, onComplete: @escaping ScreenshotCallback ) {
let redact = redactBuilder.redactRegionsFor(view: view)
let image = renderer.render(view: view)

let redact = redactBuilder.redactRegionsFor(view: view)
let imageSize = view.bounds.size
dispatchQueue.dispatchAsync {
let screenshot = UIGraphicsImageRenderer(size: imageSize, format: .init(for: .init(displayScale: 1))).image { context in
Expand Down
12 changes: 5 additions & 7 deletions Sources/Swift/Tools/UIRedactBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class UIRedactBuilder {
func redactRegionsFor(view: UIView) -> [RedactRegion] {
var redactingRegions = [RedactRegion]()

self.mapRedactRegion(fromView: view,
self.mapRedactRegion(fromLayer: view.layer.presentation() ?? view.layer,
relativeTo: nil,
redacting: &redactingRegions,
rootFrame: view.frame,
Expand Down Expand Up @@ -238,10 +238,8 @@ class UIRedactBuilder {
return image.imageAsset?.value(forKey: "_containingBundle") == nil
}

private func mapRedactRegion(fromView view: UIView, relativeTo parentLayer: CALayer?, redacting: inout [RedactRegion], rootFrame: CGRect, transform: CGAffineTransform, forceRedact: Bool = false) {
guard !redactClassesIdentifiers.isEmpty && !view.isHidden && view.alpha != 0 else { return }
let layer = view.layer.presentation() ?? view.layer
guard !redactClassesIdentifiers.isEmpty && !layer.isHidden && layer.opacity != 0 else { return }
private func mapRedactRegion(fromLayer layer: CALayer, relativeTo parentLayer: CALayer?, redacting: inout [RedactRegion], rootFrame: CGRect, transform: CGAffineTransform, forceRedact: Bool = false) {
guard !redactClassesIdentifiers.isEmpty && !layer.isHidden && layer.opacity != 0, let view = layer.delegate as? UIView else { return }

let newTransform = concatenateTranform(transform, from: layer, withParent: parentLayer)

Expand Down Expand Up @@ -272,8 +270,8 @@ class UIRedactBuilder {
/// The beginning will be added after all the subviews have been mapped.
redacting.append(RedactRegion(size: layer.bounds.size, transform: newTransform, type: .clipEnd))
}
for subview in view.subviews.sorted(by: { $0.layer.zPosition < $1.layer.zPosition }) {
mapRedactRegion(fromView: subview, relativeTo: layer, redacting: &redacting, rootFrame: rootFrame, transform: newTransform, forceRedact: enforceRedact)
for subLayer in (layer.sublayers ?? []).sorted(by: { $0.zPosition < $1.zPosition }) {
mapRedactRegion(fromLayer: subLayer, relativeTo: layer, redacting: &redacting, rootFrame: rootFrame, transform: newTransform, forceRedact: enforceRedact)
}
brustolin marked this conversation as resolved.
Show resolved Hide resolved
if view.clipsToBounds {
redacting.append(RedactRegion(size: layer.bounds.size, transform: newTransform, type: .clipBegin))
Expand Down
Loading