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: don't mask SwiftUI gradient views #275

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix: don't mask SwiftUI gradient views
ioannisj committed Dec 18, 2024
commit b13d38e5e8f3fda3f4da467754726fb967048012
11 changes: 10 additions & 1 deletion PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
@@ -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))

@@ -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
@@ -438,6 +443,10 @@
private func isTextFieldSensitive(_ view: UITextField) -> Bool {
(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 {