From 622ed76557357a5f393bb9dbaa745cec80dc2d86 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 19 Dec 2024 15:09:41 +0100 Subject: [PATCH 1/3] WIP --- Sources/Swift/Tools/SentryViewPhotographer.swift | 1 - Sources/Swift/Tools/UIRedactBuilder.swift | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/Swift/Tools/SentryViewPhotographer.swift b/Sources/Swift/Tools/SentryViewPhotographer.swift index 80e94a925f4..5bb943a6a92 100644 --- a/Sources/Swift/Tools/SentryViewPhotographer.swift +++ b/Sources/Swift/Tools/SentryViewPhotographer.swift @@ -66,7 +66,6 @@ class SentryViewPhotographer: NSObject, SentryViewScreenshotProvider { let imageRect = CGRect(origin: .zero, size: size) context.cgContext.addRect(CGRect(origin: CGPoint.zero, size: size)) context.cgContext.clip(using: .evenOdd) - UIColor.blue.setStroke() context.cgContext.interpolationQuality = .none image.draw(at: .zero) diff --git a/Sources/Swift/Tools/UIRedactBuilder.swift b/Sources/Swift/Tools/UIRedactBuilder.swift index 23d23c51a1a..1908c006c0f 100644 --- a/Sources/Swift/Tools/UIRedactBuilder.swift +++ b/Sources/Swift/Tools/UIRedactBuilder.swift @@ -264,8 +264,8 @@ class UIRedactBuilder { } guard let subLayers = layer.sublayers, subLayers.count > 0 else { return } - - if view.clipsToBounds { + let clipToBounds = view.clipsToBounds + if clipToBounds { /// Because the order in which we process the redacted regions is reversed, we add the end of the clip region first. /// The beginning will be added after all the subviews have been mapped. redacting.append(RedactRegion(size: layer.bounds.size, transform: newTransform, type: .clipEnd)) @@ -273,7 +273,7 @@ class UIRedactBuilder { for subLayer in subLayers.sorted(by: { $0.zPosition < $1.zPosition }) { mapRedactRegion(fromLayer: subLayer, relativeTo: layer, redacting: &redacting, rootFrame: rootFrame, transform: newTransform, forceRedact: enforceRedact) } - if view.clipsToBounds { + if clipToBounds { redacting.append(RedactRegion(size: layer.bounds.size, transform: newTransform, type: .clipBegin)) } } From ac423dadbab00ca968c55b4749dea8f2ed6e7d19 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 19 Dec 2024 16:55:09 +0100 Subject: [PATCH 2/3] fix: Session Redact wrong clipping order --- CHANGELOG.md | 1 + .../Swift/Tools/SentryViewPhotographer.swift | 3 +-- .../SentryViewPhotographerTests.swift | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3293c1d1644..7b2479d1360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - `SentrySdkInfo.packages` should be an array (#4626) - Use the same SdkInfo for envelope header and event (#4629) - Fixes Session replay screenshot provider crash (#4649) +- Session Redact wrong clipping order () ### Internal diff --git a/Sources/Swift/Tools/SentryViewPhotographer.swift b/Sources/Swift/Tools/SentryViewPhotographer.swift index 5bb943a6a92..7a756c345c3 100644 --- a/Sources/Swift/Tools/SentryViewPhotographer.swift +++ b/Sources/Swift/Tools/SentryViewPhotographer.swift @@ -78,10 +78,9 @@ class SentryViewPhotographer: NSObject, SentryViewScreenshotProvider { defer { latestRegion = region } - guard latestRegion?.canReplace(as: region) != true && imageRect.intersects(path.boundingBoxOfPath) else { continue } - switch region.type { case .redact, .redactSwiftUI: + guard latestRegion?.canReplace(as: region) != true && imageRect.intersects(path.boundingBoxOfPath) else { continue } (region.color ?? UIImageHelper.averageColor(of: context.currentImage, at: rect.applying(region.transform))).setFill() context.cgContext.addPath(path) context.cgContext.fillPath() diff --git a/Tests/SentryTests/SentryViewPhotographerTests.swift b/Tests/SentryTests/SentryViewPhotographerTests.swift index 1b4360bfd4c..b21ab6e5835 100644 --- a/Tests/SentryTests/SentryViewPhotographerTests.swift +++ b/Tests/SentryTests/SentryViewPhotographerTests.swift @@ -268,6 +268,32 @@ class SentryViewPhotographerTests: XCTestCase { ]) } + func testLabelRedactedStackedHierarchy() throws { + let label = UILabel(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) + label.text = "Test" + + let bottomView = UIView(frame: CGRect(x: 5, y: 5, width: 40, height: 40)) + bottomView.clipsToBounds = true + bottomView.backgroundColor = .white + + let middleView = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) + middleView.clipsToBounds = true + middleView.backgroundColor = .white + + let topView = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40)) + topView.clipsToBounds = true + topView.backgroundColor = .white + + bottomView.addSubview(middleView) + middleView.addSubview(topView) + topView.addSubview(label) + + let image = try XCTUnwrap(prepare(views: [bottomView])) + let pixel = color(at: CGPoint(x: 10, y: 10), in: image) + + assertColor(pixel, .black) + } + private func assertColor(_ color: UIColor, in image: UIImage, at points: [CGPoint]) { points.forEach { let pixel = self.color(at: $0, in: image) From d4db9aa9718a974caec6205c7b91baf774aae071 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Thu, 19 Dec 2024 16:57:59 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b2479d1360..7826045e63a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ - `SentrySdkInfo.packages` should be an array (#4626) - Use the same SdkInfo for envelope header and event (#4629) - Fixes Session replay screenshot provider crash (#4649) -- Session Redact wrong clipping order () +- Session Redact wrong clipping order (#4651) ### Internal