Skip to content

Commit

Permalink
fix: don't mask SwiftUI gradient views (#275)
Browse files Browse the repository at this point in the history
* fix: don't mask SwiftUI gradient views

* chore: update CHANGELOG

* fix: lint
  • Loading branch information
ioannisj authored Dec 18, 2024
1 parent c60e177 commit 917815c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- fix: avoid masking SwiftUI Gradient views ([#275](https://github.com/PostHog/posthog-ios/pull/275))

## 3.17.0 - 2024-12-10

- feat: ability to add a custom label to autocapture elements ([#271](https://github.com/PostHog/posthog-ios/pull/271))
Expand Down
11 changes: 10 additions & 1 deletion PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
// These are usually views that don't belong to the current process and are most likely sensitive
private let systemSandboxedView: AnyClass? = NSClassFromString("_UIRemoteView")

// These layer types should be safe to ignore while masking
private let swiftUISafeLayerTypes: [AnyClass] = [
"SwiftUI.GradientLayer", // Views like LinearGradient, RadialGradient, or AngularGradient
].compactMap(NSClassFromString)

static let dispatchQueue = DispatchQueue(label: "com.posthog.PostHogReplayIntegration",
target: .global(qos: .utility))

Expand Down Expand Up @@ -331,7 +336,7 @@
}

// this can be anything, so better to be conservative
if swiftUIGenericTypes.contains(where: { view.isKind(of: $0) }) {
if swiftUIGenericTypes.contains(where: { view.isKind(of: $0) }), !isSwiftUILayerSafe(view.layer) {
if isTextInputSensitive(view), !hasSubViews {
maskableWidgets.append(view.toAbsoluteRect(window))
return
Expand Down Expand Up @@ -439,6 +444,10 @@
(isTextInputSensitive(view) || view.isSensitiveText()) && (hasText(view.text) || hasText(view.placeholder))
}

private func isSwiftUILayerSafe(_ layer: CALayer) -> Bool {
swiftUISafeLayerTypes.contains(where: { layer.isKind(of: $0) })
}

private func hasText(_ text: String?) -> Bool {
if let text = text, !text.isEmpty {
return true
Expand Down

0 comments on commit 917815c

Please sign in to comment.