Skip to content

Commit

Permalink
feat: add isParentSensitive parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj committed Nov 14, 2024
1 parent 93e6bab commit 504a529
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
38 changes: 17 additions & 21 deletions PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,19 @@
return (config.sessionReplayConfig.maskAllImages && !isAsset) || view.isNoCapture()
}

private func toWireframe(_ view: UIView) -> RRWireframe? {
private func toWireframe(_ view: UIView, isParentSensitive: Bool = false) -> RRWireframe? {
if !view.isVisible() {
return nil
}

let wireframe = createBasicWireframe(view)
let style = RRStyle()
var skipChildren = false
var isSensitive = false

if let textView = view as? UITextView {
isSensitive = isTextViewSensitive(textView)
wireframe.type = "text"
wireframe.text = isTextViewSensitive(textView) ? textView.text.mask() : textView.text
wireframe.text = isSensitive || isParentSensitive ? textView.text.mask() : textView.text
wireframe.disabled = !textView.isEditable
style.color = textView.textColor?.toRGBString()
style.fontFamily = textView.font?.familyName
Expand All @@ -402,14 +403,14 @@
}

if let textField = view as? UITextField {
isSensitive = isTextFieldSensitive(textField)
wireframe.type = "input"
wireframe.inputType = "text_area"
let isSensitive = isTextFieldSensitive(textField)
if let text = textField.text {
wireframe.value = isSensitive ? text.mask() : text
wireframe.value = isSensitive || isParentSensitive ? text.mask() : text
} else {
if let text = textField.placeholder {
wireframe.value = isSensitive ? text.mask() : text
wireframe.value = isSensitive || isParentSensitive ? text.mask() : text
}
}
wireframe.disabled = !textField.isEnabled
Expand All @@ -428,45 +429,40 @@
}

if let theSwitch = view as? UISwitch {
isSensitive = isSwitchSensitive(theSwitch)
wireframe.type = "input"
wireframe.inputType = "toggle"
wireframe.checked = theSwitch.isOn
if #available(iOS 14.0, *) {
if let text = theSwitch.title {
wireframe.label = isSwitchSensitive(theSwitch) ? text.mask() : text
wireframe.label = isSensitive || isParentSensitive ? text.mask() : text
}
}
}

if let imageView = view as? UIImageView {
isSensitive = isImageViewSensitive(imageView)
wireframe.type = "image"
if let image = imageView.image {
if !isImageViewSensitive(imageView) {
if !isSensitive, !isParentSensitive {
wireframe.image = image
}
}
}

if let button = view as? UIButton {
isSensitive = isButtonSensitive(button)
wireframe.type = "input"
wireframe.inputType = "button"
wireframe.disabled = !button.isEnabled

// UIButton has a UILabel subview that displays the button's text
// We want to skip visiting children if button is sensitive
// Otherwise, we capture the button's title through its child UILabel
if let text = button.titleLabel?.text {
if isButtonSensitive(button) {
skipChildren = true
wireframe.value = text.mask()
}
}
// we don't need a wireframe.value here. Text will be captured by child UILabel
}

if let label = view as? UILabel {
isSensitive = isLabelSensitive(label)
wireframe.type = "text"
if let text = label.text {
wireframe.text = isLabelSensitive(label) ? text.mask() : text
wireframe.text = isSensitive || isParentSensitive ? text.mask() : text
}
wireframe.disabled = !label.isEnabled
style.color = label.textColor?.toRGBString()
Expand Down Expand Up @@ -507,10 +503,10 @@

wireframe.style = style

if !view.subviews.isEmpty, !skipChildren {
if !view.subviews.isEmpty {
var childWireframes: [RRWireframe] = []
for subview in view.subviews {
if let child = toWireframe(subview) {
if let child = toWireframe(subview, isParentSensitive: isSensitive) {
childWireframes.append(child)
}
}
Expand Down
1 change: 1 addition & 0 deletions PostHog/Utils/UIApplication+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
} else {
// check scene.windows.isKeyWindow
for window in scene.windows {
// swiftlint:disable:next for_where
if window.isKeyWindow {
return window
}
Expand Down

0 comments on commit 504a529

Please sign in to comment.